@param object               $qb
@param SorterInterface      $sorter
@param QueryObjectInterface $queryObject

@throws \InvalidArgumentException
553821
public function applySorter($qb, SorterInterface $sorter, QueryObjectInterface $queryObject)
    {
        if ($queryObject instanceof SortableQueryObjectInterface) {
            // default sorting if no sorter rules exists
            if (0 === $sorter->count() && 0 < \count($queryObject->getDefaultSort())) {
                $sorter->setSorterRules($queryObject->getDefaultSort());
            }

            $this->getBuilderFor($qb)->applySorter($qb, $sorter, $queryObject->getSorterMap());
        }
    }
856965
protected function createPager(QueryBuilder $qb, Request $request)
    {
        $m = __METHOD__.' is deprecated, consider using the '.PagerGeneratorInterface::class.' instead';
        @trigger_error($m, E_USER_DEPRECATED);

        return $this->pagerGenerator->createPager($qb, $request);
    }
364292
public static function assert(
        JsonApiSerializer $serializer,
        Fields $fields,
        Included $included,
        Sorting $sort,
        ErrorBag $errorBag,
        $className
    ) {
        self::validateQueryParamsTypes($serializer, $fields, 'Fields', $errorBag);
        self::validateIncludeParams($serializer, $included, 'include', $errorBag);

        if (!empty($className) && false === $sort->isEmpty()) {
            self::validateSortParams($serializer, $className, $sort, $errorBag);
        }

        if ($errorBag->count() > 0) {
            throw new QueryException();
        }
    }
195601
public function sort(?callable $comparator = null): MapInterface
    {
        $comparator ?
            $this->items->sort($comparator) :
            $this->items->sort();

        return $this;
    }
1236633
public function setSelect(QueryBuilder $qb)
    {
        $columns = array();
        $partials = array();

        // Make sure all related joins are added as needed columns. A column many entities deep may rely on a
        // column not specifically requested in the mData
        foreach (array_keys($this->assignedJoins) as $joinName) {
            $columns[$joinName] = array();
        }

        // Combine all columns to pull
        foreach ($this->associations as $column) {
            $parts = explode('.', $column['fullName']);
            $columns[$parts[0]][] = $parts[1];
        }

        // Partial column results on entities require that we include the identifier as part of the selection
        foreach ($this->identifiers as $joinName => $identifiers) {
            if (!in_array($identifiers[0], $columns[$joinName])) {
                array_unshift($columns[$joinName], $identifiers[0]);
            }
        }

        // Make sure to include the identifier for the main entity
        if (!in_array($this->rootEntityIdentifier, $columns[$this->tableName])) {
            array_unshift($columns[$this->tableName], $this->rootEntityIdentifier);
        }

        foreach ($columns as $columnName => $fields) {
            $partials[] = 'partial ' . $columnName . '.{' . implode(',', $fields) . '}';
        }

        $qb->select(implode(',', $partials));
        $qb->from($this->metadata->getName(), $this->tableName);
    }
1283805
private function filterByUnavailability(QueryBuilder $qb)
    {
        $alias = $qb->getAllAliases()[0];
        $qb->andWhere($alias . '.reservationMovement IS NOT NULL');

        return $qb;
    }
733668
private function handleIndexedFields($qb, $criteria)
    {
        $criteria = (is_array($criteria)) ? $criteria : array();
        /* join indexation */
        if (empty($criteria)) {
            return;
        }
        foreach ($criteria as $criterion) {
            //ajouter test
            if (count($criterion) !== 3) {
                continue;
            }
            $criterion = (object) $criterion;
            $alias = uniqid('i'.rand());
            $qb->leftJoin('cc._indexation', $alias)
                    ->andWhere($alias.'._field = :field'.$alias)
                    ->andWhere($alias.'._value '.$criterion->op.' :value'.$alias)
                    ->setParameter('field'.$alias, $criterion->field)
                    ->setParameter('value'.$alias, $criterion->value);
        }
    }
27063
public function buildQuery(QueryBuilder $qb, array $parameters)
    {
        if (!is_array($parameters['category'])) {
            $parameters['category'] = [$parameters['category']];
        }
        $childrenArray = [];
        //clean the parameters from the blank value
        foreach ($parameters['category'] as $index => $parameter) {
            //the blank value is removed
            if ($parameter === '') {
                unset($parameters['category'][$index]);
            } else {
                $parentCategory = $this->getEntityManager()->getRepository('VictoireBlogBundle:BlogCategory')->findOneById($parameter);
                $childrenArray = array_merge($childrenArray, $this->getCategoryChildrens($parentCategory, []));
            }
        }

        if (count($childrenArray) > 0) {
            if (array_key_exists('strict', $parameters)) {
                $repository = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article');
                foreach ($childrenArray as $index => $category) {
                    $parameter = ':category'.$index;
                    $subquery = $repository->createQueryBuilder('article_'.$index)
                        ->join('article_'.$index.'.category', 'category_'.$index)
                        ->where('category_'.$index.' = '.$parameter);
                    $qb->andWhere($qb->expr()->in('main_item', $subquery->getDql()))
                        ->setParameter($parameter, $category);
                }
            } else {
                $qb = $qb
                    ->join('main_item.category', 'c')
                    ->andWhere('c.id IN (:category)')
                    ->setParameter('category', $childrenArray);
            }
        }

        return $qb;
    }
1277103
public function buildQuery(QueryBuilder $qb, array $parameters)
    {
        $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        if (isset($parameters['year'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND YEAR(main_item.publishedAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND YEAR(main_item.createdAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND YEAR(main_item.publishedAt) = :year')
                ->setParameter('year', $parameters['year'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['month'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND MONTH(main_item.publishedAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND MONTH(main_item.createdAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND MONTH(main_item.publishedAt) = :month')
                ->setParameter('month', $parameters['month'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['day'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND DAY(main_item.publishedAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND DAY(main_item.createdAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND DAY(main_item.publishedAt) = :day')
                ->setParameter('day', $parameters['day'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }

        return $qb;
    }
1063337
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        if (null !== $this->dqlAlias) {
            $dqlAlias = $this->dqlAlias;
        }

        $field = ArgumentToOperandConverter::toField($this->field);
        $value = ArgumentToOperandConverter::toValue($this->value);

        return (string) new DoctrineComparison(
            $field->transform($qb, $dqlAlias),
            $this->operator,
            $value->transform($qb, $dqlAlias)
        );
    }
812256
protected function getQueryTotal(QueryBuilder $qb): int
    {
        $countQuery = clone $qb;

        if (\count($qb->getParameters()) > 0) {
            $countQuery->setParameters($qb->getParameters());
        }

        if ($countQuery->getDQLPart('orderBy')) {
            $countQuery->resetDQLPart('orderBy');
        }

        $countQuery->setMaxResults(null);
        $countQuery->setFirstResult(0);

        $queryAlias = $qb->getAllAliases()[0];
        $countQuery->select(sprintf('count(DISTINCT %s.%s) as total', $queryAlias, 'id'));

        return $countQuery->getQuery()->getSingleScalarResult();
    }
1300752
protected function _paginate(QueryBuilder $qb, int $offset, int $limit)
    {
        return $qb
            ->setFirstResult($offset)
            ->setMaxResults($limit);
    }
1018126
public function evaluate(
        QueryBuilder $queryBuilder,
        CreatePaginator $annotation
    ) {
        foreach ($annotation->getOrderBy() as $orderBy) {
            if (is_array($orderBy)) {
                $field = $this
                    ->providerCollector
                    ->provide(trim($orderBy[1]));

                $direction = $this
                    ->providerCollector
                    ->provide(
                        trim($orderBy[2]),
                        isset($orderBy[3]) && is_array($orderBy[3])
                            ? $orderBy[3]
                            : []
                    );

                $queryBuilder->addOrderBy(
                    trim($orderBy[0]) . '.' . $field,
                    $direction
                );
            }
        }
    }
1197336
public function sort(callable $sorter = null)
    {
        if (!$sorter) {
            $sorter = function ($a, $b) {
                if ($a == $b) {
                    return 0;
                }

                return ($a < $b) ? -1 : 1;
            };
        }

        usort($this->source, $sorter);

        return $this;
    }
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);
        }
    }
925392
protected function _query(QueryBuilder $qb, array $columns)
    {
        return $this->inquire($qb, $columns, $this->getClassMetadata(), 'e', $this->getEntityManager());
    }
1326103
private function addOrderBy(QueryBuilder $qb, array $orderBy = [])
    {
        if (count($orderBy)) {
            $alias = $qb->getAllAliases()[0];
            foreach ($orderBy as $sortCol => $order) {
                $qb->orderBy($alias . '.' . $sortCol, $order);
            }
        }

        return $qb;
    }