Skip to content
Snippets Groups Projects
Commit 4072fc73 authored by jaapjansma's avatar jaapjansma
Browse files

fixed a few errors

parent 14452a35
Branches
Tags
No related merge requests found
......@@ -48,14 +48,15 @@ abstract class CRM_Civirules_TriggerData_TriggerData {
* @return int
*/
public function getContactId() {
if ($this->contact_id) {
if (!empty($this->contact_id)) {
return $this->contact_id;
}
foreach($this->entity_data as $data) {
foreach($this->entity_data as $entity => $data) {
if (!empty($data['contact_id'])) {
return $data['contact_id'];
}
}
return null;
}
/**
......
......@@ -29,19 +29,19 @@ class CRM_CivirulesPostTrigger_Case extends CRM_Civirules_Trigger_Post {
* @param $objectRef
*/
public function triggerTrigger($op, $objectName, $objectId, $objectRef) {
$triggerData = $this->getTriggerDataFromPost($op, $objectName, $objectId, $objectRef);
$t = $this->getTriggerDataFromPost($op, $objectName, $objectId, $objectRef);
//trigger for each client
$clients = CRM_Case_BAO_Case::getCaseClients($objectId);
foreach($clients as $client) {
$triggerData = clone $t;
$roleData = array();
$roleData['contact_id'] = $client;
$roleData['is_client'] = true;
$triggerData->setEntityData('CaseRole', $roleData);
$triggerData->setEntityData('Relationship', null);
CRM_Civirules_Engine::triggerRule($this, clone $triggerData);
CRM_Civirules_Engine::triggerRule($this, $triggerData);
}
//trigger for each case role
......@@ -78,4 +78,49 @@ class CRM_CivirulesPostTrigger_Case extends CRM_Civirules_Trigger_Post {
return $entities;
}
/**
* Get trigger data belonging to this specific post event
*
* Sub classes could override this method. E.g. a post on GroupContact doesn't give on object of GroupContact
* it rather gives an array with contact Id's
*
* @param $op
* @param $objectName
* @param $objectId
* @param $objectRef
* @return CRM_Civirules_TriggerData_Edit|CRM_Civirules_TriggerData_Post
*/
protected function getTriggerDataFromPost($op, $objectName, $objectId, $objectRef) {
$entity = CRM_Civirules_Utils_ObjectName::convertToEntity($objectName);
//set data
$data = array();
if (is_object($objectRef)) {
CRM_Core_DAO::storeValues($objectRef, $data);
} elseif (is_array($objectRef)) {
$data = $objectRef;
}
//retrieve extra data from the database because the objectRef does not contain all
//data from the case
$case_data = civicrm_api3('Case', 'getsingle', array('id' => $objectId));
foreach($case_data as $key => $value) {
if (!isset($data[$key])) {
$data[$key] = $value;
}
}
//unset contact_id
unset($data['contact_id']);
if ($op == 'edit') {
//set also original data with an edit event
$oldData = CRM_Civirules_Utils_PreData::getPreData($entity, $objectId);
$triggerData = new CRM_Civirules_TriggerData_Edit($entity, $objectId, $data, $oldData);
} else {
$triggerData = new CRM_Civirules_TriggerData_Post($entity, $objectId, $data);
}
return $triggerData;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment