/**
  * 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 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->event = new CRM_Civirules_BAO_Event();
     $this->assign('event_edit_params', false);
     $this->eventClass = false;
     if (!empty($this->ruleId)) {
         $this->rule->id = $this->ruleId;
         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::getEventObjectByEventId($this->event->id, TRUE);
         $this->eventClass->setEventId($this->event->id);
         $this->eventClass->setRuleId($this->rule->id);
         $this->eventClass->setEventParams($this->rule->event_params);
         $this->assign('event_edit_params', $this->eventClass->getExtraDataInputUrl($this->ruleId));
     }
     $this->assign('eventClass', $this->eventClass);
     $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 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;
     $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);
 }
 protected function getFields()
 {
     $return = array();
     foreach ($this->eventClass->getProvidedEntities() as $entityDef) {
         if (!empty($entityDef->daoClass) && class_exists($entityDef->daoClass)) {
             $key = $entityDef->entity . '_';
             $className = $entityDef->daoClass;
             if (!is_callable(array($className, 'fields'))) {
                 continue;
             }
             $fields = call_user_func(array($className, 'fields'));
             foreach ($fields as $field) {
                 $fieldKey = $key . $field['name'];
                 $label = $field['title'];
                 if (empty($label)) {
                     $label = $field['name'];
                 }
                 $return[$fieldKey] = $label;
             }
         }
     }
     return $return;
 }