/** * @param string $alias * @param ListRequestInterface $request * * @return \Doctrine\ORM\QueryBuilder */ public function createQueryBuilderWithLimitAndOrder(string $alias, ListRequestInterface $request) { return $this->createQueryBuilder($alias)->setFirstResult(($request->getPage() - 1) * $request->getLimit())->setMaxResults($request->getLimit())->addOrderBy($alias . '.' . $request->getSort(), $request->getOrder()); }
/** * @param array $criteria * @param ListRequestInterface $request * * @return array total and items */ public function getEntitiesByWithListRequestAndTotal(array $criteria, ListRequestInterface $request) { $items = $this->getEntitiesBy($criteria, [$request->getSort() => $request->getOrder()], $request->getLimit(), ($request->getPage() - 1) * $request->getLimit()); return ['total' => $this->repository->countByCriteria($criteria), 'items' => $items]; }