Exemplo n.º 1
0
 /**
  * Convert given query condition value which is supposed to contain types
  * identifiers to integer identifiers
  *
  * This function will take care of awaited query format
  */
 public function convertQueryCondition($value)
 {
     // First fetch the type
     if (null === $value) {
         return 0;
     }
     if (!is_array($value)) {
         $value = [$value];
     }
     $hasOperator = false;
     // FIXME Sorry for this
     if (!Misc::isIndexed($value)) {
         // We have an operator.
         $operator = array_keys($value)[0];
         $values = $value[$operator][0];
         $hasOperator = true;
     } else {
         $values = $value;
     }
     foreach ($values as $key => $type) {
         if (null === $type) {
             $values[$key] = 0;
         } else {
             if ($typeId = $this->getTypeId($type, false)) {
                 $values[$key] = $typeId;
             } else {
                 unset($values[$key]);
             }
         }
     }
     if (empty($values)) {
         // It should not have been empty, this is an impossible
         // condition
         $values = [-1];
     }
     if ($hasOperator) {
         return [$operator => $values];
     } else {
         return $values;
     }
 }
 /**
  * Apply the operator onto the query
  *
  * @param \SelectQueryInterface $query
  * @param string $statement
  * @param string $value
  */
 protected final function applyOperator(\SelectQueryInterface $query, $statement, $value)
 {
     // Check if $value contains an operator (i.e. if is associative array)
     if (is_array($value) && !Misc::isIndexed($value)) {
         // First key will be the operator
         $keys = array_keys($value);
         $operator = $keys[0];
         $value = $value[$operator];
         switch ($operator) {
             case '<>':
                 if (is_array($value)) {
                     $query->condition($statement, $value, 'NOT IN');
                 } else {
                     $query->condition($statement, $value, '<>');
                 }
                 break;
             case 'exists':
                 $query->exists($value);
                 break;
             case 'in':
                 $query->condition($statement, $value, 'IN');
                 break;
             default:
                 $query->condition($statement, $value, $operator);
                 break;
         }
     } else {
         if (null === $value) {
             $query->isNull($statement);
         } else {
             $query->condition($statement, $value);
         }
     }
 }