Exemple #1
0
 /**
  * Process a criteria of a rule
  *
  * @param &$criteria  criteria to check
  * @param &$input     the input data used to check criterias
  **/
 function checkCriteria(&$criteria, &$input)
 {
     $partial_regex_result = array();
     // Undefine criteria field : set to blank
     if (!isset($input[$criteria->fields["criteria"]])) {
         $input[$criteria->fields["criteria"]] = '';
     }
     //If the value is not an array
     if (!is_array($input[$criteria->fields["criteria"]])) {
         $value = $this->getCriteriaValue($criteria->fields["criteria"], $criteria->fields["condition"], $input[$criteria->fields["criteria"]]);
         $res = RuleCriteria::match($criteria, $value, $this->criterias_results, $partial_regex_result);
     } else {
         //If the value is, in fact, an array of values
         // Negative condition : Need to match all condition (never be)
         if (in_array($criteria->fields["condition"], array(self::PATTERN_IS_NOT, self::PATTERN_NOT_CONTAIN, self::REGEX_NOT_MATCH, self::PATTERN_DOES_NOT_EXISTS))) {
             $res = true;
             foreach ($input[$criteria->fields["criteria"]] as $tmp) {
                 $value = $this->getCriteriaValue($criteria->fields["criteria"], $criteria->fields["condition"], $tmp);
                 $res &= RuleCriteria::match($criteria, $value, $this->criterias_results, $partial_regex_result);
                 if (!$res) {
                     break;
                 }
             }
             // Positive condition : Need to match one
         } else {
             $res = false;
             foreach ($input[$criteria->fields["criteria"]] as $crit) {
                 $value = $this->getCriteriaValue($criteria->fields["criteria"], $criteria->fields["condition"], $crit);
                 $res |= RuleCriteria::match($criteria, $value, $this->criterias_results, $partial_regex_result);
             }
         }
     }
     // Found regex on this criteria
     if (count($partial_regex_result)) {
         // No regex existing : put found
         if (!count($this->regex_results)) {
             $this->regex_results = $partial_regex_result;
         } else {
             // Already existing regex : append found values
             $temp_result = array();
             foreach ($partial_regex_result as $new) {
                 foreach ($this->regex_results as $old) {
                     $temp_result[] = array_merge($old, $new);
                 }
             }
             $this->regex_results = $temp_result;
         }
     }
     return $res;
 }