Ejemplo n.º 1
0
 /**
  * @return PaginationInterface
  */
 public function findAll()
 {
     $page = func_get_arg(0);
     $limit = func_get_arg(1);
     $qb = $this->createQueryBuilder('u');
     return $this->paginator->paginate($qb->getQuery(), $page, $limit);
 }
Ejemplo n.º 2
0
 public function search(SearchFilter $filter, $page = 1, $limit = 10)
 {
     // get workshop and lessons filtered separately
     $workshops = $this->workshopRepository->findForCriteria($filter);
     $lessons = $this->lessonsRepository->findForCriteria($filter);
     // get all lessons for found workshops
     if (count($workshops) > 0) {
         $lessonsFromWorkshops = $this->lessonsRepository->findByWorkshopIds(array_unique(array_column($workshops, "id")));
         $lessons = array_unique(array_merge($lessons, $lessonsFromWorkshops), SORT_REGULAR);
     }
     // get all workshops for found lessons
     if (count($lessons) > 0) {
         $workshopsFromLessons = $this->workshopRepository->findByIds(array_unique(array_column($lessons, "workshop_id")));
         $workshops = array_unique(array_merge($workshops, $workshopsFromLessons), SORT_REGULAR);
     }
     // join of the lessons and workshops
     $result = array_map(function ($workshopArray) use($lessons) {
         $workshopArray["lessons"] = array_values(array_filter($lessons, function ($lessonArray) use($workshopArray) {
             return $lessonArray["workshop_id"] == $workshopArray["id"];
         }));
         return $workshopArray;
     }, $workshops);
     $this->pagination = $this->paginator->paginate($result, $page, $limit);
     $this->results = $result;
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * @param array $filter
  * @return PaginationInterface
  */
 public function findAll(array $filter = [])
 {
     $page = func_get_arg(1);
     $limit = func_get_arg(2);
     $qb = $this->getQueryBuilder();
     $this->applyFilter($qb, $filter);
     return $this->paginator->paginate($qb->getQuery(), $page, $limit);
 }
Ejemplo n.º 4
0
 /**
  * @return array
  */
 public function getReviewList()
 {
     $currentUser = $this->getUser();
     $thank = $this->em->getRepository('NFQReviewsBundle:Thanks')->findOneByUser($currentUser);
     if (!$thank) {
         $result = ['number' => 0, 'reviews' => []];
     } else {
         $result = ['number' => $thank->getNumber(), 'reviews' => $currentUser->getGReviews()->toArray()];
     }
     $page = $this->requestStack->getCurrentRequest()->query->get('my_reviews_page', 1);
     $pagination = $this->paginator->paginate($result['reviews'], $page, 5, ['pageParameterName' => 'my_reviews_page']);
     $result['reviews'] = $pagination;
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * @return array
  */
 public function getRequestsForMe()
 {
     $response = [];
     try {
         $repo = $this->em->getRepository('NFQAssistanceBundle:AssistanceRequest');
         //get all my tags
         $tagsRepo = $this->em->getRepository('NFQAssistanceBundle:Tags');
         $myTags = $tagsRepo->getMyRootTags($this->getUser());
         $tagAr = [];
         foreach ($myTags as $tag) {
             $tagAr[] = $tag['id'];
         }
         if (empty($tagAr)) {
             throw new \Exception('you have not defined any tags');
         }
         $results = $repo->getRequestsForMe($this->getUser(), $tagAr);
         $page = $this->requestStack->getCurrentRequest()->query->get('requests_for_me_page', 1);
         $pagination = $this->paginator->paginate($results, $page, 10, ['pageParameterName' => 'requests_for_me_page']);
         $response['status'] = 'success';
         $response['data'] = $pagination;
     } catch (\Exception $e) {
         $response['status'] = 'failed';
         $response['data'] = $e->getMessage();
     }
     return $response;
 }
Ejemplo n.º 6
0
 /**
  * Creates pagination object
  */
 protected function createPagination()
 {
     $paginatorOptions = ['sortFieldWhitelist' => $this->getOption('sortFieldWhitelist')];
     if (null !== $this->getOption('defaultSortFieldName')) {
         $paginatorOptions['defaultSortFieldName'] = $this->getOption('defaultSortFieldName');
     }
     $this->pagination = $this->paginator->paginate($this->queryBuilder->getQuery(), $this->page, $this->getOption('limit'), $paginatorOptions);
 }
 /**
  * @inheritDoc
  */
 public function getResults()
 {
     return $this->paginator->paginate($this->getQueryBuilder(), $this->page, $this->limit, $this->options);
 }