Beispiel #1
0
 /**
  *
  * @param array $filterOptions format example array(
  * array(
  *  "field" => "issueStatus", 
  *  "method" => "CONTAINS", 
  *  "value" => "OPEN")
  * )
  * @param string $prefix the prefix used as alias in the query.
  * @param array $extraPrefix array of arrays each element must have a 
  * key and the value is an other array with 'prefix' and 'field' values
  * Example (array(
  *  "issueStatus" => array ("prefix" => "is", "field" = "issueStatusId")))
  * @return string 
  */
 function processQueryFilter($filterOptions, $prefix, $extraPrefix = array())
 {
     $result = '';
     $defaultMethod = "CONTIENE";
     $logicalOperator = "AND";
     if (!is_array($filterOptions)) {
         return "";
     }
     foreach ($filterOptions as $filter) {
         if (key_exists("field", $filter) && key_exists("value", $filter)) {
             $method = $defaultMethod;
             if (key_exists("method", $filter)) {
                 $method = strtoupper($filter["method"]);
             }
             if (key_exists($method, $this->_queryMethods)) {
                 if (key_exists($filter['field'], $extraPrefix)) {
                     $field = $extraPrefix[$filter['field']]['prefix'] . '.' . $extraPrefix[$filter['field']]['field'];
                 } else {
                     $field = $prefix . "." . $filter['field'];
                 }
                 if ($filter['value'] != "") {
                     $value = $this->db->escape($filter['value']) . " ";
                     if ($method == "CONTIENE") {
                         $value = "'%" . $filter['value'] . "%' ";
                     }
                     if (key_exists("operator", $filter)) {
                         $logicalOperator = $filter['operator'];
                     }
                     if ($result) {
                         $result .= $logicalOperator . " " . $field . $this->_queryMethods[$method] . $value;
                     } else {
                         $result .= $field . $this->_queryMethods[$method] . $value;
                     }
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Replaces first found question mark with given value using given database active record class.
  * 
  * @param string $where where clausule to be altered.
  * @param mixed $value value, to be replacet against first question mark from left.
  * @param CI_DB_active_record $db database active record object.
  * @return string altered where clausule.
  */
 private function replaceFirstQuestionMark($where, $value, CI_DB_active_record $db)
 {
     $escaped_value = $db->escape($value);
     $index = strpos($where, '?', 0);
     if ($index !== FALSE) {
         return substr($where, 0, $index) . $escaped_value . substr($where, $index + 1);
     }
     return $where;
 }