/** * Trigger a rule for this trigger * * @param $op * @param $objectName * @param $objectId * @param $objectRef */ public function triggerTrigger($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; $triggerData->setEntityData('Relationship', null); $triggerData->setContactId($client); CRM_Civirules_Engine::triggerRule($this, $triggerData); } //trigger for each case role $relatedContacts = CRM_Case_BAO_Case::getRelatedContacts($objectId); foreach ($relatedContacts as $contact) { $triggerData = clone $t; $relationshipData = null; $relationship = new CRM_Contact_BAO_Relationship(); $relationship->contact_id_b = $contact['contact_id']; $relationship->case_id = $objectId; if ($relationship->find(true)) { CRM_Core_DAO::storeValues($relationship, $relationshipData); } $triggerData->setEntityData('Relationship', $relationshipData); $triggerData->setContactId($contact['contact_id']); CRM_Civirules_Engine::triggerRule($this, $triggerData); } }
/** * @return int */ public function process() { $count = 0; $isValidCount = 0; while ($eventData = $this->getNextEntityEventData()) { $isValid = CRM_Civirules_Engine::triggerRule($this, $eventData); if ($isValid) { $isValidCount++; } $count++; } return array('count' => $count, 'is_valid_count' => $isValidCount); }
/** * Trigger a rule for this event * * @param $op * @param $objectName * @param $objectId * @param $objectRef */ public function triggerEvent($op, $objectName, $objectId, $objectRef) { $eventData = $this->getEventDataFromPost($op, $objectName, $objectId, $objectRef); //trigger for activity event for every source_contact_id, target_contact_id and assignee_contact_id $activityContact = new CRM_Activity_BAO_ActivityContact(); $activityContact->activity_id = $objectId; $activityContact->find(); while ($activityContact->fetch()) { $data = array(); CRM_Core_DAO::storeValues($activityContact, $data); $eventData->setEntityData('ActivityContact', $data); CRM_Civirules_Engine::triggerRule($this, clone $eventData); } }
/** * Trigger a rule for this event * * @param $op * @param $objectName * @param $objectId * @param $objectRef */ public function triggerEvent($op, $objectName, $objectId, $objectRef) { //in case of GroupContact $objectRef consist of an array of contactIds //so convert this array to group contact objects //we do this by a query on the group_contact table to retrieve the latest records for this group and contact $sql = "SELECT MAX(`id`), `group_id`, `contact_id`, `status`, `location_id`, `email_id`\n FROM `civicrm_group_contact`\n WHERE `group_id` = %1 AND `contact_id` IN (" . implode(", ", $objectRef) . ")\n GROUP BY `contact_id`"; $params[1] = array($objectId, 'Integer'); $dao = CRM_Core_DAO::executeQuery($sql, $params, true, 'CRM_Contact_DAO_GroupContact'); while ($dao->fetch()) { $data = array(); CRM_Core_DAO::storeValues($dao, $data); $eventData = $this->getEventDataFromPost($op, $objectName, $objectId, $data); CRM_Civirules_Engine::triggerRule($this, clone $eventData); } }
/** * Trigger a rule for this trigger * * @param $op * @param $objectName * @param $objectId * @param $objectRef */ public function triggerTrigger($op, $objectName, $objectId, $objectRef) { $entity = CRM_Civirules_Utils_ObjectName::convertToEntity($objectName); //only execute entity tag for setting or removing tags from contacts //beceuase we need to know the contact id for the trigger engine //and we only know this when the tag is on contact level if (!isset($objectRef['1']) || $objectRef['1'] != 'civicrm_contact') { return; } foreach ($objectRef['0'] as $cid) { $data = array('tag_id' => $objectId, 'entity_id' => $cid, 'entity_table' => $objectRef['1'], 'contact_id' => $cid); $triggerData = new CRM_Civirules_TriggerData_Post($entity, $objectId, $data); CRM_Civirules_Engine::triggerRule($this, $triggerData); } }
/** * CiviRuleAction.process API * * Process delayed actions * * @param array $params * @return array API result descriptor * @see civicrm_api3_create_success * @see civicrm_api3_create_error * @throws API_Exception */ function civicrm_api3_civi_rule_action_process($params) { $returnValues = CRM_Civirules_Engine::processDelayedActions(60); // Spec: civicrm_api3_create_success($values = 1, $params = array(), $entity = NULL, $action = NULL) return civicrm_api3_create_success($returnValues, $params, 'CiviRuleAction', 'Process'); }
/** * Trigger a rule for this trigger * * @param $op * @param $objectName * @param $objectId * @param $objectRef */ public function triggerTrigger($op, $objectName, $objectId, $objectRef) { $triggerData = $this->getTriggerDataFromPost($op, $objectName, $objectId, $objectRef); CRM_Civirules_Engine::triggerRule($this, clone $triggerData); }