public function setEventId($eventId) { parent::setEventId($eventId); $event = new CRM_Civirules_BAO_Event(); $event->id = $this->eventId; if (!$event->find(true)) { throw new Exception('Civirules: could not find event with ID: ' . $this->eventId); } $this->objectName = $event->object_name; $this->op = $event->op; }
/** * Overridden parent method to perform processing before form is build * * @access public */ public function preProcess() { $this->ruleConditionId = CRM_Utils_Request::retrieve('rule_condition_id', 'Integer'); $this->ruleCondition = new CRM_Civirules_BAO_RuleCondition(); $this->ruleCondition->id = $this->ruleConditionId; $this->condition = new CRM_Civirules_BAO_Condition(); $this->rule = new CRM_Civirules_BAO_Rule(); $this->event = new CRM_Civirules_BAO_Event(); if (!$this->ruleCondition->find(true)) { throw new Exception('Civirules could not find ruleCondition'); } $this->condition->id = $this->ruleCondition->condition_id; if (!$this->condition->find(true)) { throw new Exception('Civirules could not find condition'); } $this->rule->id = $this->ruleCondition->rule_id; if (!$this->rule->find(true)) { throw new Exception('Civirules could not find rule'); } $this->event->id = $this->rule->event_id; if (!$this->event->find(true)) { throw new Exception('Civirules could not find event'); } $this->eventClass = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($this->event->class_name, true); $this->eventClass->setEventId($this->event->id); parent::preProcess(); }
/** * Overridden parent method to perform processing before form is build * * @access public */ public function preProcess() { $this->ruleActionId = CRM_Utils_Request::retrieve('rule_action_id', 'Integer'); $this->ruleAction = new CRM_Civirules_BAO_RuleAction(); $this->ruleAction->id = $this->ruleActionId; $this->action = new CRM_Civirules_BAO_Action(); $this->rule = new CRM_Civirules_BAO_Rule(); $this->event = new CRM_Civirules_BAO_Event(); if (!$this->ruleAction->find(true)) { throw new Exception('Civirules could not find ruleAction'); } $this->action->id = $this->ruleAction->action_id; if (!$this->action->find(true)) { throw new Exception('Civirules could not find action'); } $this->rule->id = $this->ruleAction->rule_id; if (!$this->rule->find(true)) { throw new Exception('Civirules could not find rule'); } $this->event->id = $this->rule->event_id; if (!$this->event->find(true)) { throw new Exception('Civirules could not find event'); } $this->eventClass = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($this->event->class_name, true); $this->eventClass->setEventId($this->event->id); //set user context $session = CRM_Core_Session::singleton(); $editUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->rule->id, TRUE); $session->pushUserContext($editUrl); parent::preProcess(); $this->setFormTitle(); }
/** * Function to validate parameters * * @param array $params * @return string $errorMessage */ function _validateParams($params) { $errorMessage = ''; if (!isset($params['id']) && empty($params['label'])) { return ts('Label can not be empty when adding a new CiviRule Event'); } if (_checkClassNameObjectNameOperation($params) == FALSE) { return ts('Either class_name or a combination of object_name and op is mandatory'); } if (isset($params['cron']) && $params['cron'] == 1) { $params['object_name'] = null; $params['op'] = null; if (!isset($params['class_name']) || empty($params['class_name'])) { return ts('For a cron type event the class_name is mandatory'); } } if (isset($params['object_name']) && !empty($params['object_name'])) { $extensionConfig = CRM_Civirules_Config::singleton(); if (!in_array($params['object_name'], $extensionConfig->getValidEventObjectNames())) { return ts('ObjectName passed in parameters (' . $params['object_name'] . ')is not a valid object for a CiviRule Event'); } } if (isset($params['op']) && !empty($params['op'])) { $extensionConfig = CRM_Civirules_Config::singleton(); if (!in_array($params['op'], $extensionConfig->getValidEventOperations())) { return ts('Operation passed in parameters (' . $params['op'] . ')is not a valid operation for a CiviRule Event'); } } if (CRM_Civirules_BAO_Event::eventExists($params) == TRUE) { return ts('There is already an event for this class_name or combination of object_name and op'); } return $errorMessage; }
/** * Function to build the event list * * @return array $eventList * @access public * @static */ public static function buildEventList() { $eventList = array(); $events = CRM_Civirules_BAO_Event::getValues(array()); foreach ($events as $eventId => $event) { $eventList[$eventId] = $event['label']; } return $eventList; }
/** * Function to get the data * * @return array $rules * @access protected */ protected function getRules() { $rules = CRM_Civirules_BAO_Rule::getValues(array()); foreach ($rules as $ruleId => $rule) { $rules[$ruleId]['actions'] = $this->setRowActions($rule); if (isset($rule['event_id']) && !empty($rule['event_id'])) { $rules[$ruleId]['event_label'] = CRM_Civirules_BAO_Event::getEventLabelWithId($rule['event_id']); } $rules[$ruleId]['created_contact_name'] = CRM_Civirules_Utils::getContactName($rule['created_user_id']); $rules[$ruleId]['is_active'] = CRM_Civirules_Utils::formatIsActive($rule['is_active']); } return $rules; }
/** * Overridden parent method to perform processing before form is build * * @access public */ public function preProcess() { $this->ruleConditionId = CRM_Utils_Request::retrieve('rule_condition_id', 'Integer'); $this->ruleCondition = new CRM_Civirules_BAO_RuleCondition(); $this->ruleCondition->id = $this->ruleConditionId; $ruleConditionData = array(); CRM_Core_DAO::storeValues($this->ruleCondition, $ruleConditionData); $this->condition = new CRM_Civirules_BAO_Condition(); $this->rule = new CRM_Civirules_BAO_Rule(); $this->event = new CRM_Civirules_BAO_Event(); if (!$this->ruleCondition->find(true)) { throw new Exception('Civirules could not find ruleCondition'); } $this->condition->id = $this->ruleCondition->condition_id; if (!$this->condition->find(true)) { throw new Exception('Civirules could not find condition'); } $this->rule->id = $this->ruleCondition->rule_id; if (!$this->rule->find(true)) { throw new Exception('Civirules could not find rule'); } $this->event->id = $this->rule->event_id; if (!$this->event->find(true)) { throw new Exception('Civirules could not find event'); } $this->conditionClass = CRM_Civirules_BAO_Condition::getConditionObjectById($this->condition->id, false); if ($this->conditionClass) { $this->conditionClass->setRuleConditionData($ruleConditionData); } $this->eventClass = CRM_Civirules_BAO_Event::getEventObjectByEventId($this->event->id, true); $this->eventClass->setEventId($this->event->id); $this->eventClass->setEventParams($this->rule->event_params); parent::preProcess(); $this->setFormTitle(); //set user context $session = CRM_Core_Session::singleton(); $editUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->rule->id, TRUE); $session->pushUserContext($editUrl); }
/** * CiviRuleEvent.Get API * * @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_event_get($params) { $returnValues = CRM_Civirules_BAO_Event::getValues($params); return civicrm_api3_create_success($returnValues, $params, 'CiviRuleEvent', 'Get'); }
/** * Returns the url for redirect * * @param $event_id * @return bool|string url */ protected function getEventRedirect($event_id) { $event = CRM_Civirules_BAO_Event::getEventObjectByEventId($event_id, true); $redirectUrl = $event->getExtraDataInputUrl($this->ruleId); if (!empty($redirectUrl)) { return $redirectUrl; } return false; }
/** * @param $fields */ static function validateConditionEntities($fields) { $conditionClass = CRM_Civirules_BAO_Condition::getConditionObjectById($fields['rule_condition_select'], false); if (!$conditionClass) { $errors['rule_condition_select'] = ts('Not a valid condition, condition class is missing'); return $errors; } $requiredEntities = $conditionClass->requiredEntities(); $rule = new CRM_Civirules_BAO_Rule(); $rule->id = $fields['rule_id']; $rule->find(true); $event = new CRM_Civirules_BAO_Event(); $event->id = $rule->event_id; $event->find(true); $eventObject = CRM_Civirules_BAO_Event::getPostEventObjectByClassName($event->class_name, true); $eventObject->setEventId($event->id); $availableEntities = array(); foreach ($eventObject->getProvidedEntities() as $entityDef) { $availableEntities[] = strtolower($entityDef->entity); } foreach ($requiredEntities as $entity) { if (!in_array(strtolower($entity), $availableEntities)) { $errors['rule_condition_select'] = ts('This condition is not available with event %1', array(1 => $event->label)); return $errors; } } return true; }
/** * Function to retrieve the label of an event with eventId * * @param int $eventId * @return string $event->label * @access public * @static */ public static function getEventLabelWithId($eventId) { if (empty($eventId)) { return ''; } $event = new CRM_Civirules_BAO_Event(); $event->id = $eventId; $event->find(true); return $event->label; }
/** * Returns an array with cron events which should be triggered in the cron * * @return array */ public static function findRulesForCron() { $cronEvents = array(); $sql = "SELECT r.id AS rule_id, e.id AS event_id, e.class_name, r.event_params\n FROM `civirule_rule` r\n INNER JOIN `civirule_event` e ON r.event_id = e.id AND e.is_active = 1\n WHERE r.`is_active` = 1 AND e.cron = 1"; $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $cronEventObject = CRM_Civirules_BAO_Event::getEventObjectByClassName($dao->class_name, false); if ($cronEventObject !== false) { $cronEventObject->setEventId($dao->event_id); $cronEventObject->setRuleId($dao->rule_id); $cronEventObject->setEventParams($dao->event_params); $cronEvents[] = $cronEventObject; } } return $cronEvents; }