/** * @param QueryBuilder $qb * @param int $selectedPage * @throws LessThan1MaxPerPageException * @throws NotIntegerMaxPerPageException * @throws LessThan1CurrentPageException * @throws NotIntegerCurrentPageException * @throws OutOfRangeCurrentPageException */ protected function applyPager(QueryBuilder $qb, $selectedPage = null) { if ($selectedPage) { $this->sortConfig->setPage($selectedPage); } $this->pager = new Pagerfanta(new DoctrineORMAdapter($qb)); $this->pager->setMaxPerPage($this->resultsPerPage); $this->pager->setCurrentPage($this->sortConfig->getPage()); }
/** * @param Query $query * @param SortConfig $sortConfig */ protected function applyESSort(Query $query, SortConfig $sortConfig) { $column = $sortConfig->getColumn(); if ($column) { $direction = $sortConfig->getDirection() ? 'desc' : 'asc'; // null or false both default to ASC $query->addSort([$column => ['order' => $direction]]); } }
/** * @param QueryBuilder $qb * @param SortConfig $sortConfig */ protected function applySort(QueryBuilder $qb, SortConfig $sortConfig) { $column = $sortConfig->getColumn(); if (!$column || !$this->family->hasAttribute($column)) { parent::applySort($qb, $sortConfig); return; } $attribute = $this->family->getAttribute($column); $uid = uniqid('join'); $fullColumnReference = $uid . '.' . $attribute->getType()->getDatabaseType(); $qb->leftJoin($this->alias . '.values', $uid, Join::WITH, "({$uid}.data = {$this->alias}.id AND ({$uid}.attributeCode = '{$attribute->getCode()}' OR {$uid}.id IS NULL))"); $direction = $sortConfig->getDirection() ? 'DESC' : 'ASC'; // null or false both default to ASC $qb->addOrderBy($fullColumnReference, $direction); }