Add conditions according to given filters.

@param TransUnitQuery    $query
@param array             $locales
@param array             $filters
764137
protected function addTranslationFilter(TransUnitQuery $query, array $locales = null, array $filters = null)
    {
        if (null !== $locales) {
            $q = TransUnitQuery::create()
                ->select('Id')
                ->distinct()
                ->join('Translation', Criteria::LEFT_JOIN)
                ->useTranslationQuery()
                    ->filterByLocale($locales, Criteria::IN)
            ;

            foreach ($locales as $locale) {
                if (!empty($filters[$locale])) {
                    $q
                        ->filterByContent(sprintf('%%%s%%', $filters[$locale]), Criteria::LIKE)
                        ->filterByLocale(sprintf('%s', $locale))
                    ;
                }
            }

            $ids = $q
                ->endUse()
                ->find($this->getConnection())
            ;

            if (count($ids) > 0) {
                $query->filterById($ids, Criteria::IN);
            }
        }
    }
542860
public function handle(
        CriteriaConverter $converter,
        SelectQuery $query,
        Criterion $criterion,
        array $languageSettings
    )
    {
        /** @var \eZ\Publish\API\Repository\Values\Content\Query\Criterion $filter */
        $filter = $criterion->value;
        $subSelect = $query->subSelect();
        $condition = $this->locationCriteriaConverter->convertCriteria($subSelect, $filter, []);

        $subSelect
            ->select('ezcontentobject_tree.contentobject_id')
            ->from($this->dbHandler->quoteTable('ezcontentobject_tree'))
            ->innerJoin(
                $this->dbHandler->quoteTable('ezcontentobject'),
                $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_tree'),
                $this->dbHandler->quoteColumn('id', 'ezcontentobject')
            )
            ->innerJoin(
                $this->dbHandler->quoteTable('ezcontentobject_version'),
                $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
                $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')
            )
            ->where(
                $condition,
                //ContentInfo::STATUS_PUBLISHED
                $subSelect->expr->eq(
                    'ezcontentobject.status',
                    $subSelect->bindValue(1, null, PDO::PARAM_INT)
                ),
                //VersionInfo::STATUS_PUBLISHED
                $subSelect->expr->eq(
                    'ezcontentobject_version.status',
                    $subSelect->bindValue(1, null, PDO::PARAM_INT)
                )
            );

        return $query->expr->in(
            $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
            $subSelect
        );
    }
159682
public function logQuery($query, $bindings, $time = null)
    {
        if ($this->loggingQueries) {
            $this->queryLog[] = compact('query', 'bindings', 'time');
        }
    }
100997
protected function buildConditions(array $filters)
    {
        $conditions = $this->engine->newQuery();

        foreach ($filters as $key=>$value) {
            $conditions = $this->buildCondition($conditions, $key, $value);
        }

        return $conditions;
    }
799549
public function scopeWhereSlug($query, $slug, $locale = null)
    {
        return $query->whereHas('translations', function ($query) use ($slug, $locale) {
            return $query->whereSlug($slug, $locale, true);
        });
    }
516261
public function count(array $locales = null,  array $filters = null)
    {
        $builder = $this->createQueryBuilder();

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        $count = $builder->count()
            ->getQuery()
            ->execute();

        return $count;
    }
128526
public function setFilter(array $allowed = array(), $query = null)
    {
        if (!isset($query)) {
            $query = $this->getFilterQuery();
        }

        $this->setFilterData($allowed, $query);
        $this->query_filter = array_filter($query, 'is_string');
    }
972324
public function setFilters($filters, QueryBuilder &$query, QueryBuilder &$countQuery, &$selects)
    {
        //then we set the filters
        if ($filters && is_array($filters)) {
            foreach ($filters as $filter) {
                //get the field object
                $fieldObject = $this->fieldFactory->findFilter($filter['field_name']);

                //set the filter on the object
                $fieldObject->setFilter($filter);

                //filter the query objects, only pass in the selects the first time so they aren't added twice
                $fieldObject->filterQuery($query, $selects);
                $fieldObject->filterQuery($countQuery);
            }
        }
    }
435311
public function setAllowFilters(array $filters = []): void
    {
        $this->allowFilters = [];
        foreach ($filters as $column) {
            $this->addAllowFilter($column);
        }
    }
1042739
protected function addSelectsToQuery(Builder $query, array $selects)
    {
        if (!empty($selects)) {
            $query->selectRaw('max(' . implode(' + ', $selects) . ') as relevance', $this->searchBindings);
        }
    }
1203307
private function addRuleCondition(QueryBuilder $query, EntityDefinition $definition, Context $context): void
    {
        if ($definition->isBlacklistAware() && $context->getRuleIds()) {
            $wheres = [];

            $accessor = $this->getFieldAccessor('blacklistIds', $definition, $definition->getEntityName(), $context);

            foreach ($context->getRuleIds() as $ruleId) {
                if (!Uuid::isValid($ruleId)) {
                    throw new InvalidUuidException($ruleId);
                }
                $wheres[] = sprintf(
                    'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                    'contextRule' . $ruleId
                );
                $query->setParameter('contextRule' . $ruleId, $ruleId);
            }

            $query->andWhere(implode(' + ', $wheres) . ' = 0');
        }

        if (!$definition->isWhitelistAware()) {
            return;
        }

        $accessor = $this->getFieldAccessor('whitelistIds', $definition, $definition->getEntityName(), $context);

        $wheres = [];
        foreach ($context->getRuleIds() as $id) {
            if (!Uuid::isValid($id)) {
                throw new InvalidUuidException($id);
            }
            $wheres[] = sprintf(
                'JSON_CONTAINS(IFNULL(' . $accessor . ', JSON_ARRAY()), JSON_ARRAY(:%s))',
                'contextRule' . $id
            );
            $query->setParameter('contextRule' . $id, $id);
        }

        $conditions = [
            '(JSON_DEPTH(' . $accessor . ') is null)',
            '(JSON_DEPTH(' . $accessor . ') = 1)',
        ];

        if (!empty($wheres)) {
            $conditions[] = implode(' + ', $wheres) . ' >= 1';
        }

        $query->andWhere('(' . implode(' OR ', $conditions) . ')');
    }
1029647
public function addQueries(array $queries = array()) {
	    foreach($queries as $queryInfo) {
	        $batchAction = (isset($queryInfo[1])) ? $queryInfo[1] : null;
	        $this->addQuery($queryInfo[0], $batchAction);
	    }
	}
701887
protected function addTranslationFilter(Builder $builder, array $locales = null,  array $filters = null)
    {
        if (null !== $locales) {
            $qb = $this->createQueryBuilder()
                ->hydrate(false)
                ->distinct('id')
                ->field('translations.locale')->in($locales);

            foreach ($locales as $locale) {
                if (!empty($filters[$locale])) {
                    $builder->addAnd(
                        $builder->expr()
                            ->field('translations.content')->equals(new \MongoRegex(sprintf('/%s/i', $filters[$locale])))
                            ->field('translations.locale')->equals($locale)
                    );
                }
            }

            $ids = $qb->getQuery()->execute();
            $ids = iterator_to_array($ids);

            if (count($ids) > 0) {
                $builder->field('id')->in($ids);
            }
        }
    }
1365915
public static function queryFilter(ActiveQuery &$query, array $get)
    {
        if(!empty($get['text'])){
            $query->andFilterWhere(['LIKE', 'title', $get['text']]);
        }else{
            if(!empty($get['category_id'])){
                $query->andFilterWhere(['parent_id' => $get['category_id']]);
            }else {
                $query->andFilterWhere(['parent_id' => 0]);
            }
        }
    }
908896
protected function addExtendedAdvancedSearchWhereClause($qb, $filters)
    {
        $parseFilters = [];
        if (isset($filters->root[0])) {
            // Function is determined by the second clause type
            $type         = (isset($filters->root[1])) ? $filters->root[1]->type : $filters->root[0]->type;
            $parseFilters = &$filters->root;
        } elseif (isset($filters->children[0])) {
            $type         = (isset($filters->children[1])) ? $filters->children[1]->type : $filters->children[0]->type;
            $parseFilters = &$filters->children;
        } elseif (is_array($filters)) {
            $type         = (isset($filters[1])) ? $filters[1]->type : $filters[0]->type;
            $parseFilters = &$filters;
        }

        if (empty($type)) {
            $type = 'and';
        }

        $parameters  = [];
        $expressions = $qb->expr()->{"{$type}X"}();

        if ($parseFilters) {
            $this->parseExtendedSearchFilters($parseFilters, $qb, $expressions, $parameters);
        }

        return [$expressions, $parameters];
    }
90799
public function addWhereAny($filters)
    {
        // Parse and split predicates along with any parameters
        $filters = $this->normalisePredicates(func_get_args());
        $this->splitQueryParameters($filters, $predicates, $parameters);

        $clause = "(" . implode(") OR (", $predicates) . ")";
        return $this->addWhere(array($clause => $parameters));
    }
761069
public function getTransUnitList(array $locales = null, $rows = 20, $page = 1, array $filters = null)
    {
        $sortColumn = isset($filters['sidx']) ? $filters['sidx'] : 'id';
        $order = isset($filters['sord']) ? $filters['sord'] : 'ASC';

        $builder = $this->createQueryBuilder()
            ->hydrate(false)
            ->select('id');

        $this->addTransUnitFilters($builder, $filters);
        $this->addTranslationFilter($builder, $locales, $filters);

        $results = $builder->sort($sortColumn, $order)
            ->skip($rows * ($page - 1))
            ->limit($rows)
            ->getQuery()
            ->execute();

        $ids = array();
        foreach ($results as $result) {
            $ids[] = $result['_id'];
        }

        $transUnits = array();

        if (count($ids) < 1) {
            return $transUnits;
        }

        $results = $this->createQueryBuilder()
            ->hydrate(false)
            ->field('id')->in($ids)
            ->field('translations.locale')->in($locales)
            ->sort(array($sortColumn => $order, 'translations.locale' => 'asc'))
            ->getQuery()
            ->execute();

        foreach ($results as $item) {
            $end = count($item['translations']);
            for ($i = 0; $i < $end; $i++) {
                if (!in_array($item['translations'][$i]['locale'], $locales)) {
                    unset($item['translations'][$i]);
                }
            }
            sort($item['translations']);
            $transUnits[] = $item;
        }

        return $transUnits;
    }