/**
  * Method to execute the actions
  *
  * @param object CRM_Civirules_TriggerData_TriggerData $triggerData
  * @access protected
  * @static
  */
 protected static function executeActions(CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     $actionParams = array('rule_id' => $triggerData->getTrigger()->getRuleId());
     $ruleActions = CRM_Civirules_BAO_RuleAction::getValues($actionParams);
     foreach ($ruleActions as $ruleAction) {
         self::executeAction($triggerData, $ruleAction);
     }
 }
 /**
  * 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;
 }
 /**
  * Function to perform post save processing (extends parent function)
  *
  * @access public
  */
 function postProcess()
 {
     $saveParams = array('rule_id' => $this->_submitValues['rule_id'], 'action_id' => $this->_submitValues['rule_action_select'], 'delay' => 'null');
     if ($this->ruleActionId) {
         $saveParams['id'] = $this->ruleActionId;
     }
     if (!empty($this->_submitValues['delay_select'])) {
         $delayClass = CRM_Civirules_Delay_Factory::getDelayClassByName($this->_submitValues['delay_select']);
         $delayClass->setValues($this->_submitValues);
         $saveParams['delay'] = serialize($delayClass);
     }
     $ruleAction = CRM_Civirules_BAO_RuleAction::add($saveParams);
     $session = CRM_Core_Session::singleton();
     $session->setStatus('Action added to CiviRule ' . CRM_Civirules_BAO_Rule::getRuleLabelWithId($this->_submitValues['rule_id']), 'Action added', 'success');
     $action = CRM_Civirules_BAO_Action::getActionObjectById($ruleAction['action_id'], true);
     $redirectUrl = $action->getExtraDataInputUrl($ruleAction['id']);
     if (empty($redirectUrl) || $this->ruleActionId) {
         $redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->_submitValues['rule_id'], TRUE);
     } elseif (!$this->ruleActionId) {
         $redirectUrl .= '&action=add';
     }
     CRM_Utils_System::redirect($redirectUrl);
 }
 /**
  * Function to get the rule actions for the rule
  *
  * @return array $ruleActions
  * @access protected
  */
 protected function getRuleActions()
 {
     $actionParams = array('is_active' => 1, 'rule_id' => $this->ruleId);
     $ruleActions = CRM_Civirules_BAO_RuleAction::getValues($actionParams);
     foreach ($ruleActions as $ruleActionId => $ruleAction) {
         $actionClass = CRM_Civirules_BAO_Action::getActionObjectById($ruleAction['action_id']);
         $actionClass->setRuleActionData($ruleAction);
         $ruleActions[$ruleActionId]['label'] = CRM_Civirules_BAO_Action::getActionLabelWithId($ruleAction['action_id']);
         $ruleActions[$ruleActionId]['actions'] = $this->setRuleActionActions($ruleActionId, $actionClass);
         $ruleActions[$ruleActionId]['formattedConditionParams'] = $actionClass->userFriendlyConditionParams();
         $ruleActions[$ruleActionId]['formattedDelay'] = '';
         if (!empty($ruleAction['delay'])) {
             $delayClass = unserialize($ruleAction['delay']);
             $ruleActions[$ruleActionId]['formattedDelay'] = $delayClass->getDelayExplanation();
         }
     }
     return $ruleActions;
 }
 /**
  * Function to delete all rule actions with rule id
  *
  * @param int $ruleId
  * @access public
  * @static
  */
 public static function deleteWithRuleId($ruleId)
 {
     $ruleAction = new CRM_Civirules_BAO_RuleAction();
     $ruleAction->rule_id = $ruleId;
     $ruleAction->find(false);
     while ($ruleAction->fetch()) {
         $ruleAction->delete();
     }
 }
 /**
  * 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;
 }
 function cancelAction()
 {
     if (isset($this->_submitValues['rule_action_id']) && $this->_action == CRM_Core_Action::ADD) {
         CRM_Civirules_BAO_RuleAction::deleteWithId($this->_submitValues['rule_action_id']);
     }
 }