public function search($page = 0, $pageSize = 25, $purchasedOnly = true, $includeVoid = false) { $errors = array(); $total = 0; $items = null; try { $query = array(); foreach (array(QurbaniRepository::CNT, QurbaniRepository::RST) as $index) { $query[$index] = $this->qurbaniRepo->repository->createQueryBuilder("q")->where("q.qurbanimonth = :pQurbanimonth")->setParameter("pQurbanimonth", $this->details->qurbanimonth); if ($purchasedOnly) { $query[$index] = $query[$index]->andWhere("q.donationid IS NOT NULL"); } if (!$includeVoid) { $query[$index] = $query[$index]->andWhere("q.isvoid = 0"); } $query[$index] = $query[$index]->orderBy("q.createddate", "DESC"); if ($index == QurbaniRepository::CNT) { $query[$index] = $query[$index]->select("COUNT(q.qurbanikey)"); } } $total = $query[QurbaniRepository::CNT]->getQuery()->getSingleScalarResult(); $items = $query[QurbaniRepository::RST]->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult(); } catch (\Exception $ex) { array_push($errors, $ex->getMessage()); } return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize, $errors); }
public function search($page = 0, $pageSize = 10, array $orderBy = null) { if ($page < 0 || $pageSize < 1) { throw new \Exception("Invalid page or pageSize: page must be >= 0 and pageSize must be > 0"); } else { $metadata = $this->em->getClassMetadata($this->repository->getClassName()); $identifiers = $metadata->getIdentifierFieldNames(); $id = $identifiers[0]; $total = $this->repository->createQueryBuilder("q")->select("COUNT(q.{$id})")->getQuery()->getSingleScalarResult(); $query = $this->repository->createQueryBuilder("q"); if ($orderBy != null) { foreach ($orderBy as $field => $direction) { $query->orderBy(new Expr\OrderBy("q.{$field}", $direction)); } } $items = $query->setFirstResult($page * $pageSize)->setMaxResults($pageSize)->getQuery()->getResult(); return ResponseUtils::createSearchResponse($total, $items, $page, $pageSize); } }