Builds where clause

@param string $field
@param string $searchOper
@param string $term
@param QueryBuilder $qb
@return Expr | \Doctrine\ORM\Query\Func
@throws \InvalidArgumentException
972937
protected function getFieldQuery ($field, $searchOper, $term, QueryBuilder $qb)
    {
        if(is_array($this->searchableProperties) && !in_array($field, $this->searchableProperties)){
            throw new \Exception(sprintf('Field %s is not searchable', $field));
        }

        switch ($searchOper) {
            case 'eq':
                return $qb->expr()->eq($field, $qb->expr()->literal($term));
                 
            case 'ne':
                return $qb->expr()->neq($field, $qb->expr()->literal($term));
                 
            case 'lt':
                return $qb->expr()->lt($field, $qb->expr()->literal($term));
                 
            case 'le':
                return $qb->expr()->lte($field, $qb->expr()->literal($term));
                 
            case 'gt':
                return $qb->expr()->gt($field, $qb->expr()->literal($term));
                 
            case 'ge':
                return $qb->expr()->gte($field, $qb->expr()->literal($term));
                 
            case 'bw':
                return $qb->expr()->like($field, $qb->expr()->literal($term . '%'));
    
            case 'bn':
                return $qb->expr()->not($qb->expr()->like($field, $qb->expr()->literal($term . '%')));
                 
            case 'ew':
                return $qb->expr()->like($field, $qb->expr()->literal('%' . $term));
    
            case 'en':
                return $qb->expr()->not($qb->expr()->like($field, $qb->expr()->literal('%' . $term)));
    
            case 'cn':
                return $qb->expr()->like($field, $qb->expr()->literal('%' . $term . '%'));
    
            case 'nc':
                return $qb->expr()->not($qb->expr()->like($field, $qb->expr()->literal('%' . $term . '%')));
    
            default:
                throw new \InvalidArgumentException(sprintf('Search operator %s is not valid', $searchOper));
        }
    }
716491
public function configureQueryBuilder(QueryBuilder $qb, array $searches, array $sortBy = null, array $options = ['count' => false, 'page' => 0, 'limit' => -1])
    {
        $qb->leftJoin('obj.resourceType', 'ort');
        $userJoin = false;
        foreach ($searches as $filterName => $filterValue) {
            switch ($filterName) {
                case 'resourceType':
                    if (is_array($filterValue)) {
                        $qb->andWhere("ort.name IN (:{$filterName})");
                    } else {
                        $qb->andWhere("ort.name LIKE :{$filterName}");
                    }
                    $qb->setParameter($filterName, $filterValue);
                    break;
                case 'doer':
                    if (!$userJoin) {
                        $userJoin = true;
                        $qb->join('obj.doer', 'doer');
                    }
                    $qb->andWhere("doer.uuid = :{$filterName}");
                    $qb->setParameter($filterName, $filterValue);
                    break;
                case 'doer.name':
                    if (!$userJoin) {
                        $userJoin = true;
                        $qb->join('obj.doer', 'doer');
                    }
                    $qb->andWhere($qb->expr()->orX(
                        $qb->expr()->like('UPPER(doer.firstName)', ':doer'),
                        $qb->expr()->like('UPPER(doer.lastName)', ':doer'),
                        $qb->expr()->like('UPPER(doer.username)', ':doer'),
                        $qb->expr()->like('UPPER(doer.email)', ':doer'),
                        $qb->expr()->like(
                            "CONCAT(CONCAT(UPPER(doer.firstName), ' '), UPPER(doer.lastName))",
                            ':doer'
                        ),
                        $qb->expr()->like(
                            "CONCAT(CONCAT(UPPER(doer.lastName), ' '), UPPER(doer.firstName))",
                            ':doer'
                        )
                    ));
                    $qb->setParameter('doer', '%'.strtoupper($filterValue).'%');
                    break;
                case 'dateLog':
                    $qb->andWhere('obj.dateLog >= :dateFrom')
                        ->setParameter('dateFrom', $filterValue);
                    break;
                case 'dateFromStrict':
                    $qb->andWhere('obj.dateLog > :dateFromStrict')
                        ->setParameter('dateFromStrict', $filterValue);
                    break;
                case 'dateTo':
                    $qb->andWhere('obj.dateLog <= :dateTo')
                        ->setParameter('dateTo', $filterValue);
                    break;
                case 'dateToStrict':
                    $qb->andWhere('obj.dateLog < :dateToStrict')
                        ->setParameter('dateToStrict', $filterValue);
                    break;
                case 'action':
                    $this->filterAction($filterValue, $qb);
                    break;
                case 'organization':
                    if (!$userJoin) {
                        $userJoin = true;
                        $qb->join('obj.doer', 'doer');
                    }
                    $qb->join('doer.userOrganizationReferences', 'orgaRef')
                        ->andWhere('orgaRef.organization IN (:organizations)')
                        ->setParameter('organizations', $filterValue);
                    break;
                case 'unique':
                case 'type':
                    break;
                default:
                    $this->setDefaults($qb, $filterName, $filterValue);
                    break;
            }
        }

        if (!empty($sortBy) && ('doer.name' === $sortBy['property'] || 'actions' === $sortBy['property'])) {
            $direction = 1 === $sortBy['direction'] ? 'ASC' : 'DESC';
            switch ($sortBy['property']) {
                case 'doer.name':
                    if (!$userJoin) {
                        $qb->join('obj.doer', 'doer');
                    }
                    $qb->addOrderBy('doer.lastName', $direction);
                    $qb->addOrderBy('doer.firstName', $direction);
                    $qb->addOrderBy('doer.id', $direction);
                    break;
                case 'actions':
                    $qb->addOrderBy('actions', $direction);
            }
        }

        return $qb;
    }
662409
private function filterByAvailability(QueryBuilder $qb)
    {
        $alias = $qb->getAllAliases()[0];
        $qb->andWhere($alias . '.reservationMovement IS NULL');

        return $qb;
    }
85380
private function getBoolQuery($field, array $values, $operator)
    {
        $type = ('or' === strtolower($operator) ? BoolQuery::SHOULD : BoolQuery::MUST);

        $query = new BoolQuery();
        foreach ($values as $value) {
            $query->add(new TermQuery($field, $value), $type);
        }

        return $query;
    }
573380
public function where(string $field, $value)
    {
        $matches = [];
        // We check whether there is a specific operator in the field name,
        // and if so we validate it against a whitelist
        if (\preg_match('/(.+)\[([a-zA-Z]+)\]/', $field, $matches)) {
            $operator = \mb_strtolower($matches[2]);

            if (!\in_array($operator, self::$validOperators, true)) {
                throw new \InvalidArgumentException(\sprintf(
                    'Unknown operator "%s" given. Expected "%s" or no operator.',
                    $operator,
                    \implode(', ', self::$validOperators)
                ));
            }
        }

        if ($value instanceof \DateTimeInterface) {
            $value = $value->format(self::DATE_FORMAT);
        }
        if ($value instanceof Location) {
            $value = $value->queryStringFormatted();
        }
        if (\is_array($value)) {
            $value = \implode(',', $value);
        }

        $this->whereConditions[$field] = $value;

        return $this;
    }
1312191
protected function filterQueryBuilder(QueryBuilder $queryBuilder, string $field, ListFilter $listFilter)
    {
        $value = $this->filterEasyadminAutocompleteValue($listFilter->getValue());
        // Empty string and numeric keys is considered as "not applied filter"
        if (null === $value || '' === $value || \is_int($field)) {
            return;
        }

        // Add root entity alias if none provided
        $queryField = $listFilter->getProperty();
        if (false === \strpos($queryField, '.')) {
            $queryField = $queryBuilder->getRootAlias().'.'.$queryField;
        }

        // Checks if filter is directly appliable on queryBuilder
        if (!$this->isFilterAppliable($queryBuilder, $queryField)) {
            return;
        }

        $operator = $listFilter->getOperator();
        // Sanitize parameter name
        $parameter = 'form_filter_'.\str_replace('.', '_', $field);

        switch ($operator) {
            case ListFilter::OPERATOR_EQUALS:
                if ('_NULL' === $value) {
                    $queryBuilder->andWhere(\sprintf('%s IS NULL', $queryField));
                } elseif ('_NOT_NULL' === $value) {
                    $queryBuilder->andWhere(\sprintf('%s IS NOT NULL', $queryField));
                } else {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s :%s', $queryField, '=', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_NOT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '!=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_IN:
                // Checks that $value is not an empty Traversable
                if (0 < \count($value)) {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s (:%s)', $queryField, 'IN', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_NOTIN:
                // Checks that $value is not an empty Traversable
                if (0 < \count($value)) {
                    $queryBuilder
                        ->andWhere(\sprintf('%s %s (:%s)', $queryField, 'NOT IN', $parameter))
                        ->setParameter($parameter, $value)
                    ;
                }
                break;
            case ListFilter::OPERATOR_GT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '>', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_GTE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '>=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LT:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '<', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LTE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, '<=', $parameter))
                    ->setParameter($parameter, $value)
                ;
                break;
            case ListFilter::OPERATOR_LIKE:
                $queryBuilder
                    ->andWhere(\sprintf('%s %s :%s', $queryField, 'LIKE', $parameter))
                    ->setParameter($parameter, '%'.$value.'%')
                ;
                break;
            default:
                throw new \RuntimeException(\sprintf('Operator "%s" is not supported !', $operator));
        }
    }
1179727
public function where(string $key, string $operator, $value): QueryBuilder
    {
        $this->addWhere($key, $operator, $value, 'AND');
        return $this;
    }
203627
public function applyFilters(QueryBuilder $qb)
    {
        foreach ($this->getFilters() as $filter) {

            $type = null;
            $placeholder = $filter['valuePlaceholder'];
            if (is_array($filter['value'])) {
                $type = Connection::PARAM_STR_ARRAY;
                $filter['valuePlaceholder'] = '(' . $placeholder . ')';
            }

            $qb->andWhere($filter['column'] .' '. $filter['operator'] .' '. $filter['valuePlaceholder'])
                ->setParameter($placeholder, $filter['value'], $type);
        }

        return $qb;
    }
795557
public function where($field, $value)
    {
        $this->reloadQueryAdapter();
        $this->activeQuery->where($field, $value);
        return $this;
    }
401319
public function where($field, $op = null, $condition = null)
    {
        $param = func_get_args();
        array_shift($param);
        $this->parseWhereExp('and', $field, $op, $condition, $param);
        return $this;
    }
529643
private function buildBaseQuery(
        Connection $connection,
        TableMetadata $tableMetadata,
        string $searchTerm
    ): QueryBuilder {

        // Build query except WHERE clause
        $queryBuilder = $connection
            ->createQueryBuilder()
            ->select('COUNT(*) AS count')
            ->from('`' . $tableMetadata->getDatabaseName() . '`.`' . $tableMetadata->getTableName() . '`')
            ->setParameter('search_term', '%' . $searchTerm . '%');

        foreach ($this->getSearchableColumnNames($tableMetadata) as $index => $columnName) {
            $clause = '`' . $columnName . '` LIKE :search_term';
            if (0 === $index) {
                $queryBuilder->where($clause);
            } else {
                $queryBuilder->orWhere($clause);
            }
        }

        return $queryBuilder;
    }
907424
public function where($field, $condition = false, $operator = '=')
    {
        if (func_num_args() >= 2) {
            $this->where->addCondition($field, $condition, $operator);
        } else {
            $this->where->addCondition($field);
        }

        return $this;
    }
113249
protected function where_clause_list($field, array $values) {
        if (empty($values)) {
            return array("1 = 2", array()); // Fake condition, won't return rows ever. MDL-17645
        }

        // Note: Do not use get_in_or_equal() because it can not deal with bools and nulls.

        $params = array();
        $select = "";
        $values = (array)$values;
        foreach ($values as $value) {
            if (is_bool($value)) {
                $value = (int)$value;
            }
            if (is_null($value)) {
                $select = "$field IS NULL";
            } else {
                $params[] = $value;
            }
        }
        if ($params) {
            if ($select !== "") {
                $select = "$select OR ";
            }
            $count = count($params);
            if ($count == 1) {
                $select = $select."$field = ?";
            } else {
                $qs = str_repeat(',?', $count);
                $qs = ltrim($qs, ',');
                $select = $select."$field IN ($qs)";
            }
        }
        return array($select, $params);
    }
402850
public function orWhere($field)
    {
        if ($field instanceof Criteria) {
            return $this->root->inject(Node::OPERATOR_OR, $field->root)->getMostRecentCriteria();
        }

        return $this->root->append(Node::OPERATOR_OR, new Criteria($field, $this->root))->getMostRecentCriteria();
    }
447444
protected function search(QueryBuilder $qb, string $search): void
    {
        $query = $this->queryDefinition;
        $node = $this->objectDefinition;

        $em = $this->getManager();
        $metadata = $em->getClassMetadata($this->entity);

        $node->getFields();
        $columns = [];
        $searchFields = FieldOptionsHelper::normalize($query->getMeta('pagination')['search_fields'] ?? ['*']);
        foreach ($node->getFields() as $field) {
            if (!FieldOptionsHelper::isEnabled($searchFields, $field->getName())) {
                continue;
            }

            $config = FieldOptionsHelper::getConfig($searchFields, $field->getName(), null);
            $searchColumn = null;
            if ($metadata->hasField($field->getName())) {
                $searchColumn = $field->getName();
            }

            if ($metadata->hasField($field->getOriginName())) {
                $searchColumn = $field->getOriginName();
            }

            if ($searchColumn) {
                switch ($metadata->getFieldMapping($searchColumn)['type']) {
                    case Type::STRING:
                    case Type::TEXT:
                        $columns[$searchColumn] = $config ?? 'partial';
                        break;
                    case Type::INTEGER:
                    case Type::BIGINT:
                    case Type::FLOAT:
                    case Type::DECIMAL:
                    case Type::SMALLINT:
                        $columns[$searchColumn] = $config ?? 'exact';
                        break;
                }
            }
        }

        foreach ($searchFields as $field => $mode) {
            if (\is_int($field)) {
                $field = $mode;
                $mode = 'exact';
            }

            if ('*' === $field) {
                continue;
            }
            $columns[$field] = $mode;
        }


        if (\count($columns) > 0) {
            $joins = [];
            $orx = new Orx();
            foreach ($columns as $column => $mode) {
                $alias = $qb->getRootAliases()[0];
                if (strpos($column, '.') !== false) {
                    [$child, $column] = explode('.', $column);
                    $parentAlias = $alias;
                    $alias = 'searchJoin'.ucfirst($child);
                    if (!\in_array($alias, $joins, true)) {
                        $qb->leftJoin("{$parentAlias}.{$child}", $alias);
                        $joins[] = $alias;
                    }
                }

                if ('partial' === $mode) {
                    //search each word separate
                    $searchArray = explode(' ', $search);

                    $partialAnd = new Andx();
                    foreach ($searchArray as $q) {
                        $q = trim($q);
                        $partialAnd->add("$alias.$column LIKE '%$q%'");
                    }
                    $orx->add($partialAnd);
                } else {
                    $q = trim($search);
                    $orx->add("$alias.$column LIKE '$q'");
                }
            }

            $qb->andWhere($orx);
        }
    }
1207646
protected function where($where)
    {
        foreach($where as $field => $value) {
            $this->queryBuilder->where($field, $value);
        }
    }
1242334
public function where($field, $operator = null, $value = null, $boolean = 'and', $raw = false)
    {
        if (is_array($field)) {
            // If the column is an array, we will assume it is an array of
            // key-value pairs and can add them each as a where clause.
            return $this->addArrayOfWheres($field, $boolean, $raw);
        }

        // We'll bypass the 'has' and 'notHas' operator since they
        // only require two arguments inside the where method.
        $bypass = [Operator::$has, Operator::$notHas];

        // Here we will make some assumptions about the operator. If only
        // 2 values are passed to the method, we will assume that
        // the operator is 'equals' and keep going.
        if (func_num_args() === 2 && in_array($operator, $bypass) === false) {
            list($value, $operator) = [$operator, '='];
        }

        if (! in_array($operator, Operator::all())) {
            throw new InvalidArgumentException("Invalid where operator: {$operator}");
        }

        // We'll escape the value if raw isn't requested.
        $value = $raw ? $value : $this->escape($value);

        $field = $this->escape($field, $ignore = null, 3);

        $this->addFilter($boolean, compact('field', 'operator', 'value'));

        return $this;
    }