Ejemplo n.º 1
0
 protected function createWhereFromFilters(TokenSequencerInterface $query, array $filters, $prefixFieldsWithCollection = false, $startWithWhere = true)
 {
     if (empty($filters)) {
         return;
     }
     if ($startWithWhere) {
         $query->where();
     }
     // normalise filters
     $normalisedFilters = [];
     foreach ($filters as $field => $conditions) {
         if (!is_array($conditions)) {
             $normalisedFilters[] = ["field" => $field, "op" => "=", "value" => $conditions];
         } else {
             if (isset($conditions["op"], $conditions["value"])) {
                 $conditions = [$conditions];
             }
             // condition should now be an array of operators and values
             foreach ($conditions as $singleCondition) {
                 if (!is_array($singleCondition) || !isset($singleCondition["op"], $singleCondition["value"])) {
                     throw new \InvalidArgumentException("The filter condition for the field '{$field}' is malformed");
                 }
                 $singleCondition["field"] = $field;
                 $normalisedFilters[] = $singleCondition;
             }
         }
     }
     // add filters
     $addLogicOperator = false;
     foreach ($normalisedFilters as $condition) {
         $this->addConditionToQuery($query, $condition, $prefixFieldsWithCollection, $addLogicOperator);
         $addLogicOperator = true;
     }
 }