/** * @param array $conditions * @param PagingProperties $pagingProperties * @param ApiUser $user * @return \Doctrine\Common\Collections\Collection|static * @throws \Exception */ public function filter(array &$conditions, PagingProperties $pagingProperties, $user = null) { $qb = $this->_em->createQueryBuilder(); $orderByField = sprintf('%s.%s', self::SELECT_ALIAS, $pagingProperties->getSort()); $offset = ($pagingProperties->getPage() - 1) * $pagingProperties->getLimit(); $qb->select(self::SELECT_ALIAS)->from($this->_entityName, self::SELECT_ALIAS); foreach ($conditions as $condition) { $whereExpression = $this->buildWhereExpression($qb, $condition); $qb->orWhere($whereExpression); } if (!$this->userState->isOroUser()) { $publicComments = sprintf('%s.private = false', self::SELECT_ALIAS); $qb->andWhere($publicComments); } $qb->addOrderBy($orderByField, $pagingProperties->getOrder()); $qb->setFirstResult($offset); $qb->setMaxResults($pagingProperties->getLimit()); $query = $qb->getQuery(); try { $result = $query->getResult(Query::HYDRATE_OBJECT); } catch (\Exception $e) { $result = null; } return $result; }
/** * @param PagingContext $context * @param PagingProperties $pagingConfiguration * @return array */ private function reconstructQueryParams(PagingContext $context, PagingProperties $pagingConfiguration) { $originalQueryParams = $context->getQuery(); $reconstructedParams = array(); foreach ($pagingConfiguration->toArray() as $key => $value) { if (array_key_exists($key, $originalQueryParams)) { $reconstructedParams[$key] = sprintf('%s=%s', $key, $value); } } if (!array_key_exists('limit', $reconstructedParams)) { $reconstructedParams['limit'] = sprintf('limit=%s', $pagingConfiguration->getLimit()); } return $reconstructedParams; }
/** * @param array $conditions * @param PagingProperties $pagingProperties * @return \Doctrine\ORM\QueryBuilder */ protected function orderByTicketKey(array $conditions, PagingProperties $pagingProperties) { $qb = $this->_em->createQueryBuilder(); $offset = ($pagingProperties->getPage() - 1) * $pagingProperties->getLimit(); $qb->select(self::SELECT_ALIAS)->addSelect('CONCAT(b.key, \'-\', ' . self::SELECT_ALIAS . '.sequenceNumber) AS HIDDEN ticketKey')->from('DiamanteDeskBundle:Ticket', self::SELECT_ALIAS)->join(self::SELECT_ALIAS . '.branch', 'b'); foreach ($conditions as $condition) { $whereExpression = $this->buildWhereExpression($qb, $condition); $qb->andWhere($whereExpression); } $qb->addOrderBy('ticketKey', $pagingProperties->getOrder()); $qb->setFirstResult($offset); $qb->setMaxResults($pagingProperties->getLimit()); return $qb; }
/** * @param array $conditions * @param PagingProperties $pagingProperties * @return \Doctrine\ORM\QueryBuilder */ protected function createFilterQuery(array $conditions, PagingProperties $pagingProperties) { $qb = $this->_em->createQueryBuilder(); $orderByField = sprintf('%s.%s', self::SELECT_ALIAS, $pagingProperties->getSort()); $offset = ($pagingProperties->getPage() - 1) * $pagingProperties->getLimit(); $qb->select(self::SELECT_ALIAS)->from($this->_entityName, self::SELECT_ALIAS); foreach ($conditions as $condition) { $whereExpression = $this->buildWhereExpression($qb, $condition); $qb->andWhere($whereExpression); } $qb->addOrderBy($orderByField, $pagingProperties->getOrder()); $qb->setFirstResult($offset); $qb->setMaxResults($pagingProperties->getLimit()); return $qb; }