示例#1
0
/**
 * Civirules.Cron 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_civirules_cron($params)
{
    $returnValues = array();
    $rules = CRM_Civirules_BAO_Rule::findRulesForCron();
    foreach ($rules as $rule) {
        $return = $rule->process();
        $triggeredEntities = $return['count'];
        $triggeredActions = $return['is_valid_count'];
        $returnValues[$rule->getRuleId()] = array('rule' => CRM_Civirules_BAO_Rule::getRuleLabelWithId($rule->getRuleId()), 'triggered_entities' => $triggeredEntities, 'triggered_actions' => $triggeredActions);
    }
    return civicrm_api3_create_success($returnValues, $params, 'Civirules', 'cron');
}
 /**
  * Function to validate if rule label already exists
  *
  * @param array $fields
  * @return array|bool
  * @access static
  */
 static function validateRuleLabelExists($fields)
 {
     /*
      * if id not empty, edit mode. Check if changed before check if exists
      */
     if (!empty($fields['id']) && $fields['id'] != 'RuleId') {
         /*
          * check if values have changed against database label
          */
         $currentLabel = CRM_Civirules_BAO_Rule::getRuleLabelWithId($fields['id']);
         if ($fields['rule_label'] != $currentLabel && CRM_Civirules_BAO_Rule::labelExists($fields['rule_label']) == TRUE) {
             $errors['rule_label'] = ts('There is already a rule with this name');
             return $errors;
         }
     } else {
         if (CRM_Civirules_BAO_Rule::labelExists($fields['rule_label']) == TRUE) {
             $errors['rule_label'] = ts('There is already a rule with this name');
             return $errors;
         }
     }
     return TRUE;
 }
 /**
  * Overridden parent method to process form data after submission
  *
  * @throws Exception when rule condition not found
  * @access public
  */
 public function postProcess()
 {
     $data = unserialize($this->ruleCondition->condition_params);
     $data['original_operator'] = $this->_submitValues['original_operator'];
     $data['original_value'] = $this->_submitValues['original_value'];
     if (isset($this->_submitValues['original_multi_value'])) {
         $data['original_multi_value'] = explode("\r\n", $this->_submitValues['original_multi_value']);
     }
     $data['operator'] = $this->_submitValues['operator'];
     $data['value'] = $this->_submitValues['value'];
     if (isset($this->_submitValues['multi_value'])) {
         $data['multi_value'] = explode("\r\n", $this->_submitValues['multi_value']);
     }
     $this->ruleCondition->condition_params = serialize($data);
     $this->ruleCondition->save();
     $session = CRM_Core_Session::singleton();
     $session->setStatus('Condition ' . $this->condition->label . ' parameters updated to CiviRule ' . CRM_Civirules_BAO_Rule::getRuleLabelWithId($this->ruleCondition->rule_id), 'Condition parameters updated', 'success');
     $redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->ruleCondition->rule_id, TRUE);
     CRM_Utils_System::redirect($redirectUrl);
 }
 /**
  * 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 set the form title based on action and data coming in
  *
  * @access protected
  */
 protected function setFormTitle()
 {
     $title = 'CiviRules Add Condition';
     $this->assign('ruleConditionHeader', 'Add Condition to CiviRule ' . CRM_Civirules_BAO_Rule::getRuleLabelWithId($this->ruleId));
     CRM_Utils_System::setTitle($title);
 }