Append mapping for url to given query-builder.

@param QueryBuilder $queryBuilder
@param string[] $locales
15163
private function appendUrlMapping(QueryBuilder $queryBuilder, $locales)
    {
        $structures = $this->structureManager->getStructures(Structure::TYPE_PAGE);
        $urlNames = [];

        foreach ($structures as $structure) {
            if (!$structure->hasTag('sulu.rlp')) {
                continue;
            }

            $propertyName = $structure->getPropertyByTagName('sulu.rlp')->getName();

            if (!in_array($propertyName, $urlNames)) {
                $this->appendSingleMapping($queryBuilder, $propertyName, $locales);
                $urlNames[] = $propertyName;
            }
        }
    }
828280
public function addQueryParams(array $queryParams)
    {
        $this->data['query'] = array_merge(Helper::getValue($this->data['query'], []), $queryParams);
        $this->data['query'] = array_filter($this->data['query']);
        return $this;
    }
178225
public function getQuery(QueryBuilder $queryBuilder)
    {
        $action = $this->getRule()->getAction();
        $foundType = preg_match('/\[\[(.*)\]\]/', $action, $matches);

        if ($foundType) {
            $type = $matches[1];
            $parts = explode(']]', $action);
            $action = ($foundType) ? $parts[1] : $action;

            return $queryBuilder
                ->join('l.resourceType', 'rt')
                ->andWhere('l.action = :action')
                ->andWhere('rt.name = :type')
                ->setParameter('action', $action)
                ->setParameter('type', $type);
        } else {
            return $queryBuilder
                ->andWhere('l.action = :action')
                ->setParameter('action', $action);
        }
    }
1144871
public function addContextFilterToQueryBuilder($queryBuilder, $context_relation_name = 'context', $context_name = 'default')
    {
        $context = $this->findContext($context_name);

        $queryBuilder->andWhere(
            $queryBuilder->getRootAliases()[0] . '.' . $context_relation_name
            . '=' .
            $this->addNamedParameter($context_relation_name, $context->getId(), $queryBuilder, null)
        );

        return $queryBuilder;
    }
856680
protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = null)
    {
        if (null === $criteria) {
            return;
        }

        foreach ($criteria as $property => $value) {
            if (null === $value) {
                $queryBuilder
                    ->andWhere($queryBuilder->expr()->isNull($this->getPropertyName($property)));
            } elseif (!is_array($value)) {
                $queryBuilder
                    ->andWhere($queryBuilder->expr()->eq($this->getPropertyName($property), ':' . $property))
                    ->setParameter($property, $value);
            } else {
                $queryBuilder->andWhere($queryBuilder->expr()->in($this->getPropertyName($property), $value));
            }
        }
    }
559534
public static function createQueryBuilder($queryBuilder)
    {
        if ($queryBuilder instanceof ORMBuilder) {
            return new ORMQueryBuilder($queryBuilder);
        }
        if ($queryBuilder instanceof DBALBuilder) {
            return new DBALQueryBuilder($queryBuilder);
        }

        throw new QueryBuilderException(
            sprintf('Invalid parameter "queryBuilder". Use %s or %s', ORMBuilder::class, DBALBuilder::class)
        );
    }
56077
public function createQuery($params, $queryBuilder)
    {
        if (!empty($params['q'])) {
            $queryBuilder->text($params['q']);
        }

        $sort = $this->filterSort($params['sort']);
        $queryBuilder->sort($sort);

        return $queryBuilder;
    }
115399
private function createQueryBuilderWithLocaleCode(string $localeCode): QueryBuilder
    {
        $queryBuilder = $this->createQueryBuilder('o');
        $queryBuilder
            ->addSelect('translation')
            ->leftJoin('o.translations', 'translation')
            ->andWhere('translation.locale = :localeCode')
            ->setParameter('localeCode', $localeCode)
        ;

        return $queryBuilder;
    }
877616
private function executeQuery(string $url, string $locale = null): string
    {
        if (null !== $locale) {
            $url = sprintf('%s&accept-language=%s', $url, $locale);
        }

        return $this->getUrlContents($url);
    }
1096119
protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, $alias, $field, $operator, $value)
    {
        $valueParameter = $queryNameGenerator->generateParameterName($field);

        switch ($operator) {
            case self::PARAMETER_BETWEEN:
                $rangeValue = explode('..', $value);

                $rangeValue = $this->normalizeBetweenValues($rangeValue);
                if (null === $rangeValue) {
                    return;
                }

                $queryBuilder
                    ->andWhere(sprintf('%1$s.%2$s BETWEEN :%3$s_1 AND :%3$s_2', $alias, $field, $valueParameter))
                    ->setParameter(sprintf('%s_1', $valueParameter), $rangeValue[0])
                    ->setParameter(sprintf('%s_2', $valueParameter), $rangeValue[1]);

                break;
            case self::PARAMETER_GREATER_THAN:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $queryBuilder
                    ->andWhere(sprintf('%s.%s > :%s', $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);

                break;
            case self::PARAMETER_GREATER_THAN_OR_EQUAL:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $queryBuilder
                    ->andWhere(sprintf('%s.%s >= :%s', $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);

                break;
            case self::PARAMETER_LESS_THAN:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $queryBuilder
                    ->andWhere(sprintf('%s.%s < :%s', $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);

                break;
            case self::PARAMETER_LESS_THAN_OR_EQUAL:
                $value = $this->normalizeValue($value, $operator);
                if (null === $value) {
                    return;
                }

                $queryBuilder
                    ->andWhere(sprintf('%s.%s <= :%s', $alias, $field, $valueParameter))
                    ->setParameter($valueParameter, $value);

                break;
        }
    }
1023212
private function addUserFilterToQueryBuilder(QueryBuilder $queryBuilder, $userSearch)
    {
        if ($userSearch !== null && $userSearch !== '') {
            $upperUserSearch = strtoupper($userSearch);
            $upperUserSearch = trim($upperUserSearch);
            $upperUserSearch = preg_replace('/\s+/', ' ', $upperUserSearch);

            $queryBuilder->leftJoin('log.doer', 'doer');
            $queryBuilder->andWhere(
                $queryBuilder->expr()->orx(
                    $queryBuilder->expr()->like('UPPER(doer.lastName)', ':userSearch'),
                    $queryBuilder->expr()->like('UPPER(doer.firstName)', ':userSearch'),
                    $queryBuilder->expr()->like('UPPER(doer.username)', ':userSearch'),
                    $queryBuilder->expr()->like(
                        "CONCAT(CONCAT(UPPER(doer.firstName), ' '), UPPER(doer.lastName))",
                        ':userSearch'
                    ),
                    $queryBuilder->expr()->like(
                        "CONCAT(CONCAT(UPPER(doer.lastName), ' '), UPPER(doer.firstName))",
                        ':userSearch'
                    )
                )
            );

            $queryBuilder->setParameter('userSearch', '%' . $upperUserSearch . '%');
        }

        return $queryBuilder;
    }
754100
public function findForLocalesAndDomains(array $locales, array $domains)
    {
        $builder = $this->createQueryBuilder('f');

        if (count($locales) > 0) {
            $builder->andWhere($builder->expr()->in('f.locale', $locales));
        }

        if (count($domains) > 0) {
            $builder->andWhere($builder->expr()->in('f.domain', $domains));
        }

        return $builder->getQuery()->getResult();
    }
919149
protected function joinTranslations(QueryBuilder $qb, $locale = null, $addSelect = true)
    {
        $qb->innerJoin('o.translations', 'translations');

        if (!empty($locale)) {
            $qb->andWhere('translations.locale = :locale')->setParameter('locale', $locale);
        }
        if ($addSelect) {
            $qb->addSelect('translations');
        }

        return $this;
    }
365020
public function getByLocale(
        \Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery $queryBuilder,
        $alias,
        $field,
        $value
    ) {
        if (!$locale = $value['value']) {
            $locale = $this->getDefaultLocale();
        }
        $queryBuilder->where(sprintf('%s.locale = :locale', $alias));
        $queryBuilder->andWhere($queryBuilder->expr()->isNotNull(sprintf('%s.parent', $alias)));
        $queryBuilder->setParameter(':locale', $locale);

        return true;
    }
24191
public function scopeTranslatedIn(Builder $query, $locale = null)
    {
        $locale = $locale ?: $this->locale();

        return $query->whereHas('translations', function (Builder $q) use ($locale) {
            $q->where($this->getLocaleKey(), '=', $locale);
        });
    }
1076380
protected function getTranslatedQuery(QueryBuilder $qb, $locale = null)
    {
        $query = $this->setTranslationHints($qb->getQuery(), $locale);

        return $query;
    }
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);
            }
        }
    }