コード例 #1
0
 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;
 }
コード例 #2
0
/**
 * 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 Trigger');
    }
    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 trigger 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->getValidTriggerObjectNames())) {
            return ts('ObjectName passed in parameters (' . $params['object_name'] . ')is not a valid object for a CiviRule Trigger');
        }
    }
    if (isset($params['op']) && !empty($params['op'])) {
        $extensionConfig = CRM_Civirules_Config::singleton();
        if (!in_array($params['op'], $extensionConfig->getValidTriggerOperations())) {
            return ts('Operation passed in parameters (' . $params['op'] . ')is not a valid operation for a CiviRule Trigger');
        }
    }
    if (CRM_Civirules_BAO_Trigger::triggerExists($params) == TRUE) {
        return ts('There is already a trigger for this class_name or combination of object_name and op');
    }
    return $errorMessage;
}
コード例 #3
0
 /**
  * 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();
 }
コード例 #4
0
 /**
  * Function to build the trigger list
  *
  * @return array $triggerList
  * @access public
  * @static
  */
 public static function buildTriggerList()
 {
     $triggerList = array();
     $triggers = CRM_Civirules_BAO_Trigger::getValues(array());
     foreach ($triggers as $triggerId => $trigger) {
         $triggerList[$triggerId] = $trigger['label'];
     }
     return $triggerList;
 }
コード例 #5
0
 /**
  * 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);
 }
コード例 #6
0
 /**
  * Returns the url for redirect
  *
  * @param $triggerId
  * @return bool|string url
  */
 protected function getTriggerRedirect($triggerId)
 {
     $trigger = CRM_Civirules_BAO_Trigger::getTriggerObjectByTriggerId($triggerId, true);
     $redirectUrl = $trigger->getExtraDataInputUrl($this->ruleId);
     if (!empty($redirectUrl)) {
         return $redirectUrl;
     }
     return false;
 }
コード例 #7
0
/**
 * CiviRuleTrigger.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_trigger_get($params)
{
    $returnValues = CRM_Civirules_BAO_Trigger::getValues($params);
    return civicrm_api3_create_success($returnValues, $params, 'CiviRuleTrigger', 'Get');
}
コード例 #8
0
 /**
  * Returns an array with cron triggers which should be triggered in the cron
  *
  * @return array
  */
 public static function findRulesForCron()
 {
     $cronTriggers = array();
     $sql = "SELECT r.id AS rule_id, t.id AS trigger_id, t.class_name, r.trigger_params\n            FROM `civirule_rule` r\n            INNER JOIN `civirule_trigger` t ON r.trigger_id = t.id AND t.is_active = 1\n            WHERE r.`is_active` = 1 AND t.cron = 1";
     $dao = CRM_Core_DAO::executeQuery($sql);
     while ($dao->fetch()) {
         $cronTriggerObject = CRM_Civirules_BAO_Trigger::getTriggerObjectByClassName($dao->class_name, false);
         if ($cronTriggerObject !== false) {
             $cronTriggerObject->setTriggerId($dao->trigger_id);
             $cronTriggerObject->setRuleId($dao->rule_id);
             $cronTriggerObject->setTriggerParams($dao->trigger_params);
             $cronTriggers[] = $cronTriggerObject;
         }
     }
     return $cronTriggers;
 }
コード例 #9
0
 /**
  * @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);
     $trigger = new CRM_Civirules_BAO_Trigger();
     $trigger->id = $rule->trigger_id;
     $trigger->find(true);
     $triggerObject = CRM_Civirules_BAO_Trigger::getPostTriggerObjectByClassName($trigger->class_name, true);
     $triggerObject->setTriggerId($trigger->id);
     $availableEntities = array();
     foreach ($triggerObject->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 trigger %1', array(1 => $trigger->label));
             return $errors;
         }
     }
     return true;
 }
コード例 #10
0
 /**
  * Function to retrieve the label of an eva triggerent with triggerId
  * 
  * @param int $triggerId
  * @return string $trigger->label
  * @access public
  * @static
  */
 public static function getTriggerLabelWithId($triggerId)
 {
     if (empty($triggerId)) {
         return '';
     }
     $trigger = new CRM_Civirules_BAO_Trigger();
     $trigger->id = $triggerId;
     $trigger->find(true);
     return $trigger->label;
 }