2

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

在下一步中,例程使用 SOAP 环回 Sugar 并创建一个 Note(连同作为附件的 PDF)。

我的问题是我可以避免这个 SOAP 调用并使用其他一些内部机制/类来做同样的事情吗?类似的东西

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

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

4

2 回答 2

4

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

编辑:例如:你可以试试这个代码,看看代码<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();

就附件而言,它有点棘手。Sugar 期望附件是一个 upload_file 对象。看看<sugar_root>/modules/Notes/controller.php函数中的代码action_save()<sugar_root>/include/upload_file.php

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

$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

高温高压

PS:未经测试的代码

于 2010-10-28T07:58:24.177 回答
0

在 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);                       

    }

}
于 2021-08-15T22:29:46.780 回答