/** * Function to delete a rule with id * * @param int $ruleId * @throws Exception when ruleId is empty * @access public * @static */ public static function deleteWithId($ruleId) { if (empty($ruleId)) { throw new Exception('rule id can not be empty when attempting to delete a civirule rule'); } CRM_Civirules_BAO_RuleAction::deleteWithRuleId($ruleId); CRM_Civirules_BAO_RuleCondition::deleteWithRuleId($ruleId); $rule = new CRM_Civirules_BAO_Rule(); $rule->id = $ruleId; $rule->delete(); return; }
/** * Method to set the form title * * @access protected */ protected function setFormTitle() { $conditionLabel = ''; $ruleCondition = new CRM_Civirules_BAO_RuleCondition(); $ruleCondition->id = $this->ruleConditionId; if ($ruleCondition->find(true)) { $condition = new CRM_Civirules_BAO_Condition(); $condition->id = $ruleCondition->condition_id; if ($condition->find(true)) { $conditionLabel = $condition->label; } } $title = 'CiviRules Edit Condition parameters'; $this->assign('ruleConditionHeader', 'Edit Condition ' . $conditionLabel . ' of CiviRule ' . CRM_Civirules_BAO_Rule::getRuleLabelWithId($ruleCondition->rule_id)); CRM_Utils_System::setTitle($title); }
/** * Function to perform post save processing (extends parent function) * * @access public */ function postProcess() { $session = CRM_Core_Session::singleton(); $saveParams = array('rule_id' => $this->_submitValues['rule_id'], 'condition_id' => $this->_submitValues['rule_condition_select']); if (isset($this->_submitValues['rule_condition_link_select'])) { $saveParams['condition_link'] = $this->_submitValues['rule_condition_link_select']; } $ruleCondition = CRM_Civirules_BAO_RuleCondition::add($saveParams); $condition = CRM_Civirules_BAO_Condition::getConditionObjectById($ruleCondition['condition_id'], true); $redirectUrl = $condition->getExtraDataInputUrl($ruleCondition['id']); if (empty($redirectUrl)) { $redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->_submitValues['rule_id'], TRUE); } else { $redirectUrl .= '&action=add'; } $session->setStatus('Condition added to CiviRule ' . CRM_Civirules_BAO_Rule::getRuleLabelWithId($this->_submitValues['rule_id']), 'Condition added', 'success'); CRM_Utils_System::redirect($redirectUrl); }
/** * Function to get the rule conditions for the rule * * @return array $ruleConditions * @access protected */ protected function getRuleConditions() { $conditionParams = array('is_active' => 1, 'rule_id' => $this->ruleId); $ruleConditions = CRM_Civirules_BAO_RuleCondition::getValues($conditionParams); foreach ($ruleConditions as $ruleConditionId => $ruleCondition) { $conditionClass = CRM_Civirules_BAO_Condition::getConditionObjectById($ruleCondition['condition_id']); $conditionClass->setRuleConditionData($ruleCondition); $ruleConditions[$ruleConditionId]['name'] = CRM_Civirules_BAO_Condition::getConditionLabelWithId($ruleCondition['condition_id']); $ruleConditions[$ruleConditionId]['actions'] = $this->setRuleConditionActions($ruleConditionId, $conditionClass); $ruleConditions[$ruleConditionId]['formattedConditionParams'] = $conditionClass->userFriendlyConditionParams(); } return $ruleConditions; }
/** * Overridden parent method to set default values * * @return array $defaultValues * @access public */ public function setDefaultValues() { $data = array(); $defaultValues = array(); $defaultValues['rule_condition_id'] = $this->ruleConditionId; $ruleCondition = new CRM_Civirules_BAO_RuleCondition(); $ruleCondition->id = $this->ruleConditionId; if ($ruleCondition->find(true)) { $data = unserialize($ruleCondition->condition_params); } if (!empty($data['operator'])) { $defaultValues['operator'] = $data['operator']; } if (!empty($data['value'])) { $defaultValues['value'] = $data['value']; } if (!empty($data['multi_value'])) { $defaultValues['multi_value'] = implode("\r\n", $data['multi_value']); } if (!empty($data['original_operator'])) { $defaultValues['original_operator'] = $data['original_operator']; } if (!empty($data['original_value'])) { $defaultValues['original_value'] = $data['original_value']; } if (!empty($data['original_multi_value'])) { $defaultValues['original_multi_value'] = implode("\r\n", $data['original_multi_value']); } return $defaultValues; }
/** * Function to count the number of conditions for a rule * * @param int $ruleId * @return int * @access public * @static */ public static function countConditionsForRule($ruleId) { $ruleCondition = new CRM_Civirules_BAO_RuleCondition(); $ruleCondition->rule_id = $ruleId; return $ruleCondition->count(); }
/** * Method to check if all conditions are valid * * @param object CRM_Civirules_TriggerData_TriggerData $triggerData * @return bool * @access protected * @static */ protected static function areConditionsValid(CRM_Civirules_TriggerData_TriggerData $triggerData) { $isValid = true; $firstCondition = true; $conditionParams = array('rule_id' => $triggerData->getTrigger()->getRuleId()); $ruleConditions = CRM_Civirules_BAO_RuleCondition::getValues($conditionParams); foreach ($ruleConditions as $ruleConditionId => $ruleCondition) { $isConditionValid = self::checkCondition($ruleCondition, $triggerData); if ($firstCondition) { $isValid = $isConditionValid ? true : false; $firstCondition = false; } elseif ($ruleCondition['condition_link'] == 'AND') { if ($isConditionValid && $isValid) { $isValid = true; } else { $isValid = false; } } elseif ($ruleCondition['condition_link'] == 'OR') { if ($isConditionValid || $isValid) { $isValid = true; } else { $isValid = false; } } else { $isValid = false; //we should never reach this statement } } return $isValid; }
function cancelAction() { if (isset($this->_submitValues['rule_condition_id']) && $this->_action == CRM_Core_Action::ADD) { CRM_Civirules_BAO_RuleCondition::deleteWithId($this->_submitValues['rule_condition_id']); } }
/** * Function to delete a rule with id * * @param int $ruleId * @throws Exception when ruleId is empty * @access public * @static */ public static function deleteWithId($ruleId) { if (empty($ruleId)) { throw new Exception('rule id can not be empty when attempting to delete a civirule rule'); } CRM_Utils_Hook::pre('delete', 'CiviRuleRule', $ruleId, CRM_Core_DAO::$_nullArray); CRM_Civirules_BAO_RuleAction::deleteWithRuleId($ruleId); CRM_Civirules_BAO_RuleCondition::deleteWithRuleId($ruleId); $rule = new CRM_Civirules_BAO_Rule(); $rule->id = $ruleId; $rule->delete(); CRM_Utils_Hook::post('delete', 'CiviRuleRule', $ruleId, CRM_Core_DAO::$_nullArray); return; }