/**
  * 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 = CRM_CivirulesConditions_Utils_Period::getConditionParams($this->_submitValues, $data);
     $this->ruleCondition->condition_params = serialize($data);
     $this->ruleCondition->save();
     parent::postProcess();
 }
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $userFriendlyConditionParams = parent::userFriendlyConditionParams();
     $periods = CRM_CivirulesConditions_Utils_Period::Options();
     if (isset($periods[$this->conditionParams['period']])) {
         $period = $periods[$this->conditionParams['period']];
     } else {
         $period = ts('all time');
     }
     return ts('Total amount') . ' ' . $period . ' ' . $userFriendlyConditionParams;
 }
 /**
  * Overridden parent method to build form
  *
  * @access public
  */
 public function buildQuickForm()
 {
     $operatorList[0] = 'equals (=)';
     $operatorList[1] = 'is not equal (!=)';
     $operatorList[2] = 'is more than (>)';
     $operatorList[3] = 'is more than or equal (>=)';
     $operatorList[4] = 'is less than (<)';
     $operatorList[5] = 'is less than or equal (<=)';
     $this->add('hidden', 'rule_condition_id');
     $this->add('select', 'operator', ts('Operator'), $operatorList, true);
     $this->add('text', 'no_of_days', ts('Number of Days'), array(), true);
     $this->addRule('no_of_days', 'Number of Days must be a whole number', 'numeric');
     $this->addRule('no_of_days', 'Number of Days must be a whole number', 'nopunctuation');
     $this->add('select', 'period', ts('Period'), array('' => ts('All time')) + CRM_CivirulesConditions_Utils_Period::Options());
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $userFriendlyConditionParams = parent::userFriendlyConditionParams();
     $period = CRM_CivirulesConditions_Utils_Period::userFriendlyConditionParams($this->conditionParams);
     return ts('Total amount') . ' ' . $period . ' ' . $userFriendlyConditionParams;
 }
 /**
  * Add fields to the form for period selection
  *
  * @param $form
  */
 public static function buildQuickForm(&$form)
 {
     $form->add('select', 'period', ts('Period'), array('' => ts('All time')) + CRM_CivirulesConditions_Utils_Period::Options());
     $replacements = self::getReplacementOptions();
     foreach ($replacements as $replacement_key => $replacement_periods) {
         $form->add('text', $replacement_key, ts($replacement_key));
     }
     $form->assign('period_replacements', $replacements);
     $form->assign('period_replacements_by_period', json_encode(self::getReplacementOptionsByPeriod()));
 }
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $operator = null;
     switch ($this->conditionParams['operator']) {
         case 1:
             $operator = 'is not equal to';
             break;
         case 2:
             $operator = 'bigger than';
             break;
         case 3:
             $operator = 'bigger than or equal to';
             break;
         case 4:
             $operator = 'less than';
             break;
         case 5:
             $operator = 'less than or equal to';
             break;
         default:
             $operator = 'is equal to';
             break;
     }
     $period = CRM_CivirulesConditions_Utils_Period::userFriendlyConditionParams($this->conditionParams);
     return 'Distinct number of contributing days ' . $operator . ' ' . $this->conditionParams['no_of_days'] . ' ' . $period;
 }
 /**
  * Overridden parent method to build form
  *
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->add('select', 'period', ts('Period'), array('' => ts('All time')) + CRM_CivirulesConditions_Utils_Period::Options());
 }
 /**
  * Returns a user friendly text explaining the condition params
  * e.g. 'Older than 65'
  *
  * @return string
  * @access public
  */
 public function userFriendlyConditionParams()
 {
     $operator = null;
     switch ($this->conditionParams['operator']) {
         case 1:
             $operator = 'is not equal to';
             break;
         case 2:
             $operator = 'bigger than';
             break;
         case 3:
             $operator = 'bigger than or equal to';
             break;
         case 4:
             $operator = 'less than';
             break;
         case 5:
             $operator = 'less than or equal to';
             break;
         default:
             $operator = 'is equal to';
             break;
     }
     $periods = CRM_CivirulesConditions_Utils_Period::Options();
     if (isset($periods[$this->conditionParams['period']])) {
         $period = ts('in the ') . $periods[$this->conditionParams['period']];
     } else {
         $period = ts('all time');
     }
     return 'Distinct number of contributing days ' . $operator . ' ' . $this->conditionParams['no_of_days'] . ' ' . $period;
 }