2016-07-07 59 views
2

這是我第一次嘗試編碼sugarCRM/suiteCRM。嘗試在創建或更新任務時向suiteCRM添加邏輯掛鉤

我應該說我已經爲Wordpress編寫了將近10年的版本,但現在我已經完全失去了開始挖掘suiteCRM。

我讀過,你可以添加一個邏輯鉤將其保存到數據庫後修改的數據,但我不知道從哪裏開始...

想象我創建任務的今天, 7月7日,與我每2個月訪問一次的客戶有關,因此在賬戶中有一個名爲「訪問頻率」的字段。我希望在任務的「未來訪問日期」字段中添加未來日期(7月7日+60天= 9月7日aprox),以便我可以通過工作流程使用它創建特定的未來任務。

我想要做的是計算任務中的字段(未來訪問日期),相當於添加到任務自己的日期字段的賬戶模塊字段(訪問頻率)的天數。

我已經能夠使它工作,使用以下佈局:

\custom\modules\Tasks\logic_hooks.php

<?php 

$hook_version = 1; 
$hook_array['before_save'] = Array(); 

$hook_array['before_save'][] = Array(
    1, //Processing index. For sorting the array. 
    'future_task_date_on_task_creation', //Label. A string value to identify the hook. 
    'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located. 
    'before_save_class', //The class the method is in. 
    'future_visit_date' //The method to call. 
); 

?> 

裏面\定製\模塊\任務\ future_visit_date.php

<?php 

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 

class before_save_class { 

    function future_visit_date($bean, $event, $arguments) { 
     $bean->rhun_fecha_sig_c = date("Y-m-d H:i:s", $date); 
    } 

} 

?> 

通過此設置,未來訪問日期將被填充計算日期。

我也讀了是不建議此設置,而且我應該使用擴展框架,並把第一個文件的路徑:

/custom/Extension/modules/Tasks/Ext/LogicHooks/<file>.php 

但我不能使它發揮作用。

如果不在那裏,我是否必須創建LogicHooks文件夾? 我應該爲這個文件分配哪個文件名? 我是否必須更改代碼內的其他內容?

回答

2

是的,創建LogicHooks目錄(如果它不存在)。 PHP文件可以被稱爲任何你喜歡的。

/custom/Extension/modules/Tasks/Ext/LogicHooks/MyLogicHookFile.php

如之前定義在這個文件中你的邏輯鉤。

<?php 

$hook_version = 1; 
$hook_array['before_save'] = Array(); 

$hook_array['before_save'][] = Array(
    1, //Processing index. For sorting the array. 
    'future_task_date_on_task_creation', //Label. A string value to identify the hook. 
    'custom/modules/Tasks/future_visit_date.php', //The PHP file where your class is located. 
    'before_save_class', //The class the method is in. 
    'future_visit_date' //The method to call. 
); 

然後從管理面板運行修復和重建。

使用Extension框架的主要優點是它允許多個開發人員將組件添加到Sugar實例,而不用擔心覆蓋現有的代碼。
更多的信息可以發現它在Developer Guide

+0

謝謝,現在我做它的工作! –