SugarCRM:在没有 SOAP 的情况下创建带附件的注释?

发布于 2024-09-30 02:14:31 字数 304 浏览 3 评论 0原文

我在 Lead Editview 上有一个自定义按钮,单击该按钮会生成(通过 AJAX)发票编号和具有相同编号的 PDF。

在下一步中,例程使用 SOAP 环回 Sugar 并创建一个注释(以及作为附件的 PDF)。

我的问题是我可以避免这个 SOAP 调用并使用其他一些内部机制/类来执行相同的操作吗?类似于

$invoice = new Note();
$invoice->create(....);
...

这可能吗?我在任何地方都找不到任何文档...所有道路似乎都指向 SOAP。

I've got this custom button on Lead Editview that when clicked on generates (via AJAX) an invoice number and a PDF bearing the same number.

In the next step, the routine uses SOAP to loopback to Sugar and creates a Note (along with the PDF as attachment).

My question is can I avoid this SOAP call and use some other internal mechanism / classes to do the same? Something along the lines of

$invoice = new Note();
$invoice->create(....);
...

Is this possible? I couldn't find any documentation anywhere... all roads seem to point to SOAP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2024-10-07 02:14:31

如果您的 Ajax 调用正在执行数据库更新/保存操作,那么您可以考虑使用 after_save 逻辑挂钩。

编辑:例如:您可以尝试此代码,看看 /modules/Notes/Note.php 中的代码

$note = new Note();
$note->modified_user_id = $current_user->id;
$note->created_by = $current_user->id;
$note->name = 'New';
$note->parent_type = "Accounts";
$note->parent_id = $bean->parent_id;
$note->description = $bean->description;
$note->save();

至附件为止,有点棘手。 Sugar 期望附件是 upload_file 对象。查看 /modules/Notes/controller.php 函数 action_save()/include/upload_file 中的代码.php

HACK:这不是正确的方法,但它有效。通过对上面的代码稍作修改并巧妙地使用 move 函数,您就可以使附件正常工作。 Sugar 将附件与创建的笔记 ID 一起存储在 cache/upload 文件夹中。

$note->filename = "Yourfilename.txt" //your file name goes here
$note->file_mime_type = "text/plain"  // your file's mime type goes here
$new_note_id = $note->save();

move(your_file_location, cache/upload/$new_note_id)
//don't add a extension to cache/upload/$new_note_id

HTH

PS:未经测试的代码

If your Ajax call is performing a db update/save operation, then you could look into using a after_save logic hook.

EDIT: for eg: you could try out this code, have a look at the code in <sugar_root>/modules/Notes/Note.php

$note = new Note();
$note->modified_user_id = $current_user->id;
$note->created_by = $current_user->id;
$note->name = 'New';
$note->parent_type = "Accounts";
$note->parent_id = $bean->parent_id;
$note->description = $bean->description;
$note->save();

As far as attachment goes, it's a bit tricky. Sugar expects the attachment to be a upload_file object. Have a look at the code in <sugar_root>/modules/Notes/controller.php the function action_save() and <sugar_root>/include/upload_file.php

HACK: this is not the correct way but it works. With a slight modification to the code above and cunning use of the move function , you could make the attachment work. Sugar stores the attachments in cache/upload folder with the ID of the note created.

$note->filename = "Yourfilename.txt" //your file name goes here
$note->file_mime_type = "text/plain"  // your file's mime type goes here
$new_note_id = $note->save();

move(your_file_location, cache/upload/$new_note_id)
//don't add a extension to cache/upload/$new_note_id

HTH

P.S: untested code

能否归途做我良人 2024-10-07 02:14:31

在controller.php上执行此操作

 foreach ( $_FILES as $file ) {
        for ( $i = 0 ; $i < count( $file[ 'name' ] ) ; $i++ ) {
            $fileData = file_get_contents( $file[ 'tmp_name' ][ $i ] );   
            $fileTmpLocation = $file[ 'tmp_name' ][ $i ];     
            $fileMimeType = mime_content_type( $file[$i] );        
            $fileInfo = array( 'name' => $file[ 'name' ][ $i ], 'data' => $fileData, 'tmpLocation' =>$fileTmpLocation, 'mimeType' => $fileMimeType );
            
            array_push( $files, $fileInfo );
        }
    }

    $this->guardarNotas($this->bean->id,$files);
}

,这是保存带有附件的注释的功能:

 private function guardarNotas($case_id,$files){

    foreach($files as $file){
        $noteBean = BeanFactory::newBean('Notes');
        $noteBean->name = $file['name'];
        $noteBean->parent_type = "Cases";
        $noteBean->parent_id = $case_id;

        $noteBean->filename = $file["name"]; 
        $noteBean->file_mime_type = $file["mimeType"];
        

        $noteBean->save();

        move_uploaded_file($file["tmpLocation"], "upload/".$noteBean->id);                       

    }

}

Do this on controller.php

 foreach ( $_FILES as $file ) {
        for ( $i = 0 ; $i < count( $file[ 'name' ] ) ; $i++ ) {
            $fileData = file_get_contents( $file[ 'tmp_name' ][ $i ] );   
            $fileTmpLocation = $file[ 'tmp_name' ][ $i ];     
            $fileMimeType = mime_content_type( $file[$i] );        
            $fileInfo = array( 'name' => $file[ 'name' ][ $i ], 'data' => $fileData, 'tmpLocation' =>$fileTmpLocation, 'mimeType' => $fileMimeType );
            
            array_push( $files, $fileInfo );
        }
    }

    $this->guardarNotas($this->bean->id,$files);
}

And this is the function to save Notes with attachment:

 private function guardarNotas($case_id,$files){

    foreach($files as $file){
        $noteBean = BeanFactory::newBean('Notes');
        $noteBean->name = $file['name'];
        $noteBean->parent_type = "Cases";
        $noteBean->parent_id = $case_id;

        $noteBean->filename = $file["name"]; 
        $noteBean->file_mime_type = $file["mimeType"];
        

        $noteBean->save();

        move_uploaded_file($file["tmpLocation"], "upload/".$noteBean->id);                       

    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文