Ejemplo n.º 1
0
 private function attachCriterionToCriteria($criteria, $criterion, $add_or_to_criterion, $operator_str, $value, $colname)
 {
     //echo ( " operator_str " . $operator_str );
     list($criteria_operator, $value_to_set, $query_append_method) = $criteria_operator = baseObjectFilter::getCriteriaOperatorFromStr($operator_str, $value, $colname);
     //				echo ( "<br>Adding to criteria [" . $colname . "] = [" . $value . "] , " . $criteria_operator . "<br>");
     // TODO - is this huristics OK ? can we really say for sure that fields that end with _date are time objects ?
     if (kString::endsWith($colname, "_date")) {
         $value_to_set = strtotime($value);
     }
     // special case where match can be used
     if ($criteria_operator == self::MATCH_AND) {
         self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true);
     } elseif ($criteria_operator == self::MATCH_OR) {
         self::addMatchToCriteria($criteria, null, $value_to_set, $colname, $criteria_operator, true);
     } elseif ($criteria_operator == Criteria::IN || $criteria_operator == Criteria::NOT_IN || !is_array($value_to_set)) {
         if ($add_or_to_criterion) {
             $new_crit = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator);
             if ($criterion == null) {
                 // need to create a new criterion for the colname
                 $criterion = $new_crit;
             } else {
                 $criterion->addOr($new_crit);
             }
         } else {
             // add or null
             if (in_array($operator_str, array(self::LT_OR_NULL, self::GT_OR_NULL, self::LTE_OR_NULL, self::GTE_OR_NULL))) {
                 $accumulated_criterion = $criteria->getNewCriterion($colname, $value_to_set, $criteria_operator);
                 $or_null_criterion = $criteria->getNewCriterion($colname, null);
                 $accumulated_criterion->addOr($or_null_criterion);
                 $criteria->addAnd($accumulated_criterion);
             } else {
                 // simply addAnd to the criteria
                 $criteria->addAnd($colname, $value_to_set, $criteria_operator);
             }
         }
     } else {
         $accumulated_criterion = null;
         foreach ($value_to_set as $single_value) {
             // here use the $criteria object
             $single_crit = $criteria->getNewCriterion($colname, $single_value, $criteria_operator);
             if ($accumulated_criterion == NULL) {
                 $accumulated_criterion = $single_crit;
             } else {
                 if ($query_append_method == self::QUERY_OR) {
                     $accumulated_criterion->addOr($single_crit);
                 } else {
                     $accumulated_criterion->addAnd($single_crit);
                 }
             }
         }
         if ($add_or_to_criterion) {
             if ($criterion == null) {
                 // need to create a new criterion for the colname - use the one just created
                 $criterion = $accumulated_criterion;
             } else {
                 $criterion->addOr($accumulated_criterion);
             }
         } else {
             // simply addAnd to the criteria
             $criteria->addAnd($accumulated_criterion);
         }
     }
     return $criterion;
 }