Could really do with a link/unlink event...
When a record has a related record added or removed there is currently no specific event for this.
It would be helpful to include this so we can trigger Event Handlers when these actions are performed.
The yetiforce guys suggested a solution to me sometime ago which I now find myself using quite frequently...
This is in include/utils/utils.php
/**
* Function to related two records of different entity types
*/
function relateEntities($focus, $sourceModule, $sourceRecordId, $destinationModule, $destinationRecordIds) {
// Modifications suggested by Yetiforce
global $adb, $log;
$log->debug("Entering relateEntities method ($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordIds)");
require_once("include/events/include.inc");
$em = new VTEventsManager($adb);
$em->initTriggerCache();
// End mods
if(!is_array($destinationRecordIds)) $destinationRecordIds = Array($destinationRecordIds);
foreach($destinationRecordIds as $destinationRecordId) {
// Modifications suggested by Yetiforce
$data = array();
$data['focus'] = $focus;
$data['sourceModule'] = $sourceModule;
$data['sourceRecordId'] = $sourceRecordId;
$data['destinationModule'] = $destinationModule;
$data['destinationRecordId'] = $destinationRecordId;
$em->triggerEvent('vtiger.entity.link.before', $data);
// End
$focus->save_related_module($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
$focus->trackLinkedInfo($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
// Modifications suggested by Yetiforce
$em->triggerEvent('vtiger.entity.link.after', $data);
// End
$log->debug("Exiting relateEntities method");
}
}
Edited by Alan Lord