2

Lead Editviewにこのカスタムボタンがあり、クリックすると(AJAXを介して)請求書番号と同じ番号のPDFが生成されます。

次のステップでは、ルーチンはSOAPを使用してSugarにループバックし、メモを作成します(PDFを添付ファイルとして)。

私の質問は、このSOAP呼び出しを回避し、他の内部メカニズム/クラスを使用して同じことを行うことができるかどうかです。の線に沿った何か

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

これは可能ですか?ドキュメントがどこにも見つかりませんでした...すべての道路がSOAPを指しているようです。

4

2 に答える 2

4

Ajax呼び出しがdbupdate/ save操作を実行している場合は、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

ハック:これは正しい方法ではありませんが、機能します。上記のコードを少し変更し、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

HTH

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 に答える