/**
  * 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->trigger = new CRM_Civirules_BAO_Trigger();
     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->trigger->id = $this->rule->trigger_id;
     if (!$this->trigger->find(true)) {
         throw new Exception('Civirules could not find trigger');
     }
     $this->triggerClass = CRM_Civirules_BAO_Trigger::getPostTriggerObjectByClassName($this->trigger->class_name, true);
     $this->triggerClass->setTriggerId($this->trigger->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 perform processing before displaying form (overrides parent function)
  * 
  * @access public
  */
 function preProcess()
 {
     $this->ruleId = CRM_Utils_Request::retrieve('id', 'Integer');
     $this->rule = new CRM_Civirules_BAO_Rule();
     $this->trigger = new CRM_Civirules_BAO_Trigger();
     $this->assign('trigger_edit_params', false);
     $this->triggerClass = false;
     if (!empty($this->ruleId)) {
         $this->rule->id = $this->ruleId;
         if (!$this->rule->find(TRUE)) {
             throw new Exception('Civirules could not find rule');
         }
         $this->trigger->id = $this->rule->trigger_id;
         if (!$this->trigger->find(TRUE)) {
             throw new Exception('Civirules could not find trigger');
         }
         $this->triggerClass = CRM_Civirules_BAO_Trigger::getTriggerObjectByTriggerId($this->trigger->id, TRUE);
         $this->triggerClass->setTriggerId($this->trigger->id);
         $this->triggerClass->setRuleId($this->rule->id);
         $this->triggerClass->setTriggerParams($this->rule->trigger_params);
         $this->assign('trigger_edit_params', $this->triggerClass->getExtraDataInputUrl($this->ruleId));
     }
     $this->assign('triggerClass', $this->triggerClass);
     $ruleConditionAddUrl = CRM_Utils_System::url('civicrm/civirule/form/rule_condition', 'reset=1&action=add&rid=' . $this->ruleId, TRUE);
     $ruleActionAddUrl = CRM_Utils_System::url('civicrm/civirule/form/rule_action', 'reset=1&action=add&rid=' . $this->ruleId, TRUE);
     $this->assign('ruleConditionAddUrl', $ruleConditionAddUrl);
     $this->assign('ruleActionAddUrl', $ruleActionAddUrl);
     $this->assign('action', $this->_action);
     $this->assign('rule', $this->rule);
     $session = CRM_Core_Session::singleton();
     switch ($this->_action) {
         case CRM_Core_Action::DISABLE:
             CRM_Civirules_BAO_Rule::disable($this->ruleId);
             $session->setStatus('CiviRule disabled', 'Disable', 'success');
             CRM_Utils_System::redirect($session->readUserContext());
             break;
         case CRM_Core_Action::ENABLE:
             CRM_Civirules_BAO_Rule::enable($this->ruleId);
             $session->setStatus('CiviRule enabled', 'Enable', 'success');
             CRM_Utils_System::redirect($session->readUserContext());
             break;
     }
 }
 public function setTriggerId($triggerId)
 {
     parent::setTriggerId($triggerId);
     $trigger = new CRM_Civirules_BAO_Trigger();
     $trigger->id = $this->triggerId;
     if (!$trigger->find(true)) {
         throw new Exception('Civirules: could not find trigger with ID: ' . $this->triggerId);
     }
     $this->objectName = $trigger->object_name;
     $this->op = $trigger->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;
     $ruleConditionData = array();
     CRM_Core_DAO::storeValues($this->ruleCondition, $ruleConditionData);
     $this->condition = new CRM_Civirules_BAO_Condition();
     $this->rule = new CRM_Civirules_BAO_Rule();
     $this->trigger = new CRM_Civirules_BAO_Trigger();
     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->trigger->id = $this->rule->trigger_id;
     if (!$this->trigger->find(true)) {
         throw new Exception('Civirules could not find trigger');
     }
     $this->conditionClass = CRM_Civirules_BAO_Condition::getConditionObjectById($this->condition->id, false);
     if ($this->conditionClass) {
         $this->conditionClass->setRuleConditionData($ruleConditionData);
     }
     $this->triggerClass = CRM_Civirules_BAO_Trigger::getTriggerObjectByTriggerId($this->trigger->id, true);
     $this->triggerClass->setTriggerId($this->trigger->id);
     $this->triggerClass->setTriggerParams($this->rule->trigger_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);
 }