コード例 #1
1
ファイル: ExploreController.php プロジェクト: hasantayyar/ojs
 public function indexAction(Request $request, $page = 1)
 {
     $getTypes = $request->query->get('type_filters');
     $getSubjects = $request->query->get('subject_filters');
     $getPublishers = $request->query->get('publisher_filters');
     $typeFilters = !empty($getTypes) ? explode(',', $getTypes) : [];
     $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
     $publisherFilters = !empty($getPublishers) ? explode(',', $getPublishers) : [];
     $journalSearcher = $this->get('fos_elastica.index.search.journal');
     $boolQuery = new Query\Bool();
     $match = new Query\Match();
     $match->setField('status', 1);
     $boolQuery->addMust($match);
     $match = new Query\Match();
     $match->setField('published', true);
     $boolQuery->addMust($match);
     if (!empty($typeFilters) || !empty($subjectFilters) || !empty($publisherFilters)) {
         foreach ($typeFilters as $type) {
             $match = new Query\Match();
             $match->setField('publisher.publisher_type.name', $type);
             $boolQuery->addMust($match);
         }
         foreach ($subjectFilters as $subject) {
             $match = new Query\Match();
             $match->setField('subjects.subject', $subject);
             $boolQuery->addMust($match);
         }
         foreach ($publisherFilters as $publisher) {
             $match = new Query\Match();
             $match->setField('publisher.name', $publisher);
             $boolQuery->addMust($match);
         }
     }
     $journalQuery = new Query($boolQuery);
     $typeAgg = new Aggregation\Terms('types');
     $typeAgg->setField('publisher.publisher_type.name');
     $typeAgg->setOrder('_term', 'asc');
     $typeAgg->setSize(0);
     $journalQuery->addAggregation($typeAgg);
     $subjectAgg = new Aggregation\Terms('subjects');
     $subjectAgg->setField('subjects.subject');
     $subjectAgg->setOrder('_term', 'asc');
     $subjectAgg->setSize(0);
     $journalQuery->addAggregation($subjectAgg);
     $publisherAgg = new Aggregation\Terms('publishers');
     $publisherAgg->setField('publisher.name');
     $publisherAgg->setOrder('_term', 'asc');
     $publisherAgg->setSize(0);
     $journalQuery->addAggregation($publisherAgg);
     $adapter = new ElasticaAdapter($journalSearcher, $journalQuery);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(21);
     $pagerfanta->setCurrentPage($page);
     $journals = $pagerfanta->getCurrentPageResults();
     $types = $adapter->getResultSet()->getAggregation('types')['buckets'];
     $subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets'];
     $publishers = $adapter->getResultSet()->getAggregation('publishers')['buckets'];
     $data = ['types' => $types, 'subjects' => $subjects, 'publishers' => $publishers, 'type_filters' => $typeFilters, 'subject_filters' => $subjectFilters, 'publisher_filters' => $publisherFilters, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'page' => 'explore'];
     return $this->render('OjsSiteBundle:Explore:index.html.twig', $data);
 }
コード例 #2
1
 public function __construct(Pagerfanta $paginator, Request $request, $base_url)
 {
     $this->data = $paginator->getCurrentPageResults();
     $this->total_count = $paginator->getNbResults();
     $this->count = count($this->data);
     $query = array('q' => $request->get('q'), 'limit' => $request->get('limit'), 'page' => $request->get('page'));
     $this->query = $query;
     $this->urls['current'] = $base_url . '?' . http_build_query($query);
     if ($paginator->hasPreviousPage()) {
         $query['page'] = $paginator->getPreviousPage();
         $this->urls['previous'] = $base_url . '?' . http_build_query($query);
         if ($paginator->getCurrentPage() > 2) {
             $query['page'] = 1;
             $this->urls['start'] = $base_url . '?' . http_build_query($query);
         }
     }
     if ($paginator->hasNextPage()) {
         $query['page'] = $paginator->getNextPage();
         $this->urls['next'] = $base_url . '?' . http_build_query($query);
         if ($paginator->getCurrentPage() < $paginator->getNbPages() - 1) {
             $query['page'] = $paginator->getNbPages();
             $this->urls['end'] = $base_url . '?' . http_build_query($query);
         }
     }
 }
コード例 #3
1
 public function searchAction(Request $request)
 {
     $format = $request->getRequestFormat();
     $query = trim($request->query->get('q'));
     if (empty($query)) {
         if ('json' === $format) {
             return new JsonResponse(array('status' => 'error', 'message' => 'Missing or too short search query, example: ?q=example'), 400);
         }
         return $this->render('KnpBundlesBundle:Bundle:search.html.twig');
     }
     // Skip search if query matches exactly one bundle name, and such was found in database
     if (!$request->isXmlHttpRequest() && preg_match('/^[a-z0-9-]+\\/[a-z0-9-]+$/i', $query)) {
         list($ownerName, $name) = explode('/', $query);
         $bundle = $this->getRepository('Bundle')->findOneBy(array('ownerName' => $ownerName, 'name' => $name));
         if ($bundle) {
             return $this->redirect($this->generateUrl('bundle_show', array('ownerName' => $ownerName, 'name' => $name, '_format' => $format)));
         }
     }
     /** @var $solarium \Solarium_Client */
     $solarium = $this->get('solarium.client');
     $select = $solarium->createSelect();
     $escapedQuery = $select->getHelper()->escapeTerm($query);
     $dismax = $select->getDisMax();
     $dismax->setQueryFields(array('name^2', 'ownerName', 'fullName^1.5', 'description', 'keywords', 'text', 'text_ngram'));
     $dismax->setPhraseFields(array('description^30'));
     $dismax->setQueryParser('edismax');
     $select->setQuery($escapedQuery);
     try {
         $paginator = new Pagerfanta(new SolariumAdapter($solarium, $select));
         $paginator->setMaxPerPage($request->query->get('limit', 10))->setCurrentPage($request->query->get('page', 1), false, true);
         if (1 === $paginator->getNbResults() && !$request->isXmlHttpRequest()) {
             $first = $paginator->getCurrentPageResults()->getIterator()->current();
             if (strtolower($first['name']) == strtolower($query)) {
                 return $this->redirect($this->generateUrl('bundle_show', array('ownerName' => $first['ownerName'], 'name' => $first['name'], '_format' => $format)));
             }
         }
     } catch (\Solarium_Client_HttpException $e) {
         $msg = 'Seems that our search engine is currently offline. Please check later.';
         if ('json' === $format) {
             return new JsonResponse(array('status' => 'error', 'message' => $msg), 500);
         }
         throw new HttpException(500, $msg);
     }
     if ('json' === $format) {
         $result = array('results' => array(), 'total' => $paginator->getNbResults());
         foreach ($paginator as $bundle) {
             $result['results'][] = array('name' => $bundle->fullName, 'description' => null !== $bundle->description ? substr($bundle->description, 0, 110) . '...' : '', 'avatarUrl' => $bundle->avatarUrl ?: 'http://www.gravatar.com/avatar/?d=identicon&f=y&s=50', 'state' => $bundle->state, 'score' => $bundle->totalScore, 'url' => $this->generateUrl('bundle_show', array('ownerName' => $bundle->ownerName, 'name' => $bundle->name), true));
         }
         if (!$request->isXmlHttpRequest()) {
             if ($paginator->hasPreviousPage()) {
                 $result['prev'] = $this->generateUrl('search', array('q' => urldecode($query), 'page' => $paginator->getPreviousPage(), '_format' => 'json'), true);
             }
             if ($paginator->hasNextPage()) {
                 $result['next'] = $this->generateUrl('search', array('q' => urldecode($query), 'page' => $paginator->getNextPage(), '_format' => 'json'), true);
             }
         }
         return new JsonResponse($request->isXmlHttpRequest() ? $result['results'] : $result);
     }
     return $this->render('KnpBundlesBundle:Bundle:searchResults.html.twig', array('query' => urldecode($query), 'bundles' => $paginator));
 }
コード例 #4
0
 /**
  * @test
  */
 public function it_iterates_slice()
 {
     $pagerfanta = new Pagerfanta(new PorpaginasAdapter(new ArrayResult(array(1, 2, 3, 4))));
     $pagerfanta->setMaxPerPage(2);
     $pagerfanta->setCurrentPage(1);
     $this->assertEquals(array(1, 2), $pagerfanta->getCurrentPageResults());
     $pagerfanta->setCurrentPage(2);
     $this->assertEquals(array(3, 4), $pagerfanta->getCurrentPageResults());
 }
コード例 #5
0
 public function createRepresentationFromPagerfanta(Pagerfanta $pager)
 {
     $this->pager = empty($pager) ? $this->pager : $pager;
     if (empty($this->pager)) {
         return array();
     }
     $representation = array('hasToPaginate' => $this->pager->haveToPaginate(), 'hasNextPage' => $this->pager->hasNextPage(), 'hasPreviousPage' => $this->pager->hasPreviousPage(), 'totalItems' => $this->pager->getNbResults(), 'itemsPerPage' => $this->pager->getMaxPerPage(), 'currentPage' => $this->pager->getCurrentPage(), 'data' => $this->pager->getCurrentPageResults());
     return $representation;
 }
コード例 #6
0
ファイル: SearchController.php プロジェクト: kriswillis/sulu
 /**
  * Perform a search and return a JSON response.
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function searchAction(Request $request)
 {
     $queryString = $request->query->get('q');
     $category = $request->query->get('category', null);
     $locale = $request->query->get('locale', null);
     $page = $this->listRestHelper->getPage();
     $limit = $this->listRestHelper->getLimit();
     $aggregateHits = [];
     $startTime = microtime(true);
     $categories = $category ? [$category] : $this->searchManager->getCategoryNames();
     foreach ($categories as $category) {
         $query = $this->searchManager->createSearch($queryString);
         if ($locale) {
             $query->locale($locale);
         }
         if ($category) {
             $query->category($category);
         }
         foreach ($query->execute() as $hit) {
             $aggregateHits[] = $hit;
         }
     }
     $time = microtime(true) - $startTime;
     $adapter = new ArrayAdapter($aggregateHits);
     $pager = new Pagerfanta($adapter);
     $pager->setMaxPerPage($limit);
     $pager->setCurrentPage($page);
     $representation = new SearchResultRepresentation(new CollectionRepresentation($pager->getCurrentPageResults(), 'result'), 'sulu_search_search', ['locale' => $locale, 'query' => $query, 'category' => $category], (int) $page, (int) $limit, $pager->getNbPages(), 'page', 'limit', false, count($aggregateHits), $this->getCategoryTotals($aggregateHits), number_format($time, 8));
     $view = View::create($representation);
     $context = SerializationContext::create();
     $context->enableMaxDepthChecks();
     $context->setSerializeNull(true);
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
コード例 #7
0
ファイル: RestResponse.php プロジェクト: cvele/fondacija
 public function createResponseArray($data, $entity, Request $request)
 {
     $this->request = $request;
     $fractal = new Manager();
     $fractal->parseIncludes($request->query->get('include', []));
     $fractal->setSerializer(new ArraySerializer());
     $transformer = $this->transformerFactory->get($entity);
     if ($data instanceof Pagerfanta) {
         $pager = $data;
         $pager->setMaxPerPage($request->query->get('limit', 10));
         $pager->setCurrentPage($request->query->get('page', 1));
         $results = $pager->getCurrentPageResults();
         $resource = new Collection($results, $transformer);
         $resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
     } elseif ($data instanceof DoctrineQuery) {
         $ormAdapter = new DoctrineORMAdapter($data);
         $pager = new Pagerfanta($ormAdapter);
         $pager->setMaxPerPage($request->query->get('limit', 10));
         $pager->setCurrentPage($request->query->get('page', 1));
         $results = $pager->getCurrentPageResults();
         $resource = new Collection($results, $transformer);
         $resource->setPaginator(new PagerfantaPaginatorAdapter($pager, [$this, 'paginationRouter']));
     } elseif (is_array($data)) {
         $resource = new Collection($data, $transformer);
     } else {
         $resource = new Item($data, $transformer);
     }
     $data = $fractal->createData($resource)->toArray();
     return $data;
 }
コード例 #8
0
 public function createCollection(QueryBuilder $qb, Request $request, $route, array $routeParams = array())
 {
     $page = $request->query->get(self::PARAMETER_NAME_PAGE_NUMBER, 1);
     $count = $request->query->get(self::PARAMETER_NAME_PAGE_SIZE, self::PAGE_DEFAULT_COUNT);
     if ($count > self::MAX_PAGE_COUNT) {
         $count = self::MAX_PAGE_COUNT;
     }
     if ($count <= 0) {
         $count = self::PAGE_DEFAULT_COUNT;
     }
     $adapter = new DoctrineORMAdapter($qb);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage($count);
     $pagerfanta->setCurrentPage($page);
     $players = [];
     foreach ($pagerfanta->getCurrentPageResults() as $result) {
         $players[] = $result;
     }
     $paginatedCollection = new PaginatedCollection($players, $pagerfanta->getNbResults());
     // make sure query parameters are included in pagination links
     $routeParams = array_merge($routeParams, $request->query->all());
     $createLinkUrl = function ($targetPage) use($route, $routeParams) {
         return $this->router->generate($route, array_merge($routeParams, array(self::PARAMETER_NAME_PAGE_NUMBER => $targetPage)));
     };
     $paginatedCollection->addLink('self', $createLinkUrl($page));
     $paginatedCollection->addLink('first', $createLinkUrl(1));
     $paginatedCollection->addLink('last', $createLinkUrl($pagerfanta->getNbPages()));
     if ($pagerfanta->hasNextPage()) {
         $paginatedCollection->addLink('next', $createLinkUrl($pagerfanta->getNextPage()));
     }
     if ($pagerfanta->hasPreviousPage()) {
         $paginatedCollection->addLink('prev', $createLinkUrl($pagerfanta->getPreviousPage()));
     }
     return $paginatedCollection;
 }
コード例 #9
0
 /**
  * Lists all ArchivedClock entities within the requested week
  *
  * @param integer $year  Year in YYYY format
  * @param integer $month Month in MM format
  * @param integer $day   Day in DD format
  *
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function viewAction($year, $month, $day)
 {
     if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $week = new \DateTime();
     $week->setDate($year, $month, $day);
     $week->setTime(0, 0, 0);
     // Midnight
     $week = $this->container->get('dt_utils')->getFirstDayOfWeek($week);
     $archivedClocksQB = $em->createQueryBuilder()->select('ac')->from('OpenSkedgeBundle:ArchivedClock', 'ac')->where('ac.week = :week')->setParameter('week', $week);
     $page = $this->container->get('request')->query->get('page', 1);
     $limit = $this->container->get('request')->query->get('limit', 15);
     $adapter = new DoctrineORMAdapter($archivedClocksQB);
     $paginator = new Pagerfanta($adapter);
     try {
         $paginator->setMaxPerPage($limit);
         $paginator->setCurrentPage($page);
         $entities = $paginator->getCurrentPageResults();
     } catch (NotValidMaxPerPageException $e) {
         throw new HttpException(400, 'Not a valid limit', $e, array(), $e->getCode());
     } catch (NotValidCurrentPageException $e) {
         throw $this->createNotFoundException('Page does not exist.');
     }
     return $this->render('OpenSkedgeBundle:HoursReport:view.html.twig', array('week' => $week, 'entities' => $entities, 'paginator' => $paginator));
 }
コード例 #10
0
 public function indexAction(Request $request, $page)
 {
     $querystring = $request->query->get('query');
     $finder = $this->get('fos_elastica.finder.videocollection');
     $language = $this->get('bestophe_video_collection.movieManager')->getLanguage();
     $query = $this->getElasticaResults($querystring, $language);
     $results = $finder->find($query);
     $totalHits = count($results);
     $adapter = new ArrayAdapter($results);
     $pager = new Pagerfanta($adapter);
     $maxPerPage = $this->getPagerFantaMaxPerPage();
     $pager->setMaxPerPage($maxPerPage);
     $pager->setCurrentPage($page);
     //            if ($querystring != null && $querystring != '') {
     //                $query = new \Elastica\Query\Match();
     //                $query->setFieldQuery('title_fr', $querystring);
     //                //  $query->setFieldFuzziness('title_fr', 0.7);
     //                //  $query->setFieldMinimumShouldMatch('title_fr', '80%');
     //            //
     //        } else {
     //                $query = new \Elastica\Query\MatchAll();
     //            }
     //
     //            $results = $finder->find($query);
     //
     //            $totalHits = count($results);
     return $this->render('bestopheVideoCollectionBundle:MovieSection:SearchView.html.twig', array('listMovies' => $pager->getCurrentPageResults(), 'pager' => $pager, 'query' => $querystring, 'totalHits' => $totalHits));
 }
コード例 #11
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $repo Repo */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $repo = $this->getContainer()->get('knp_bundles.github_repository_api');
     $page = 1;
     $pager = new Pagerfanta(new DoctrineORMAdapter($em->getRepository('KnpBundlesBundle:Bundle')->queryAllSortedBy('updatedAt'), false));
     $pager->setMaxPerPage(100)->setCurrentPage($page, false, true);
     if (1 === $page) {
         $output->writeln(sprintf('[%s] Loaded <comment>%d</comment> bundles from the DB', date('d-m-y H:i:s'), $pager->getNbResults()));
     }
     do {
         /** @var $bundle Bundle */
         foreach ($pager->getCurrentPageResults() as $bundle) {
             // Check that API not failed
             if (!$repo->updateCommits($bundle)) {
                 // Sleep a while, and check again
                 sleep(60);
                 $repo->updateCommits($bundle);
             }
             $em->persist($bundle);
         }
         $output->writeln(sprintf('[%s] Migrated %d from %d  bundles', date('d-m-y H:i:s'), $page * 100, $pager->getNbResults()));
         $em->flush();
         ++$page;
     } while ($pager->hasNextPage() && $pager->setCurrentPage($page, false, true));
     return 0;
 }
コード例 #12
0
 /**
  * Lists all Test entities.
  *
  * @Route("/", name="test")
  * @Template()
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getEntityManager();
     $page = $request->query->get('page');
     if (!$page) {
         $page = 1;
     }
     $query = $em->createQueryBuilder();
     $query->add('select', 't')->add('from', 'ApplicationTestBundle:Test t')->add('orderBy', 't.featured DESC, t.position ASC, t.id DESC');
     $adapter = new DoctrineORMAdapter($query);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page) {
         $url = '?page=' . $page;
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator);
     //$twig = $this->container->get('twig');
     //$twig->addExtension(new \Twig_Extensions_Extension_Text);
     return array('pager' => $html, 'entities' => $entities);
 }
コード例 #13
0
 /**
  * @param Pagerfanta $pager  The pager
  * @param Route      $route  The collection's route
  * @param mixed      $inline Most of the time, a custom `CollectionRepresentation` instance
  *
  * @return PaginatedRepresentation
  */
 public function createRepresentation(Pagerfanta $pager, Route $route, $inline = null)
 {
     if (null === $inline) {
         $inline = new CollectionRepresentation($pager->getCurrentPageResults());
     }
     return new PaginatedRepresentation($inline, $route->getName(), $route->getParameters(), $pager->getCurrentPage(), $pager->getMaxPerPage(), $pager->getNbPages(), $this->getPageParameterName(), $this->getLimitParameterName(), $route->isAbsolute(), $pager->getNbResults());
 }
コード例 #14
0
 public function __construct(Pagerfanta $pagerfanta)
 {
     $photos = $pagerfanta->getCurrentPageResults();
     $this->photos = $photos instanceof \Traversable ? iterator_to_array($photos) : $photos;
     $this->page = $pagerfanta->getCurrentPage();
     $this->pagesCount = $pagerfanta->getNbPages();
     $this->totalCount = $pagerfanta->getNbResults();
 }
コード例 #15
0
 /**
  * @Route("/", name="landmarx_attribute_index")
  * @Template("LandmarxAttributeBundle:Attribute:index.html.twig")
  */
 public function indexAction()
 {
     $query = $this->get('doctrine_mongodb')->getRepository('LandmarxAttributeBundle:Attribute')->createQueryBuilder('a');
     $pager = new Pagerfanta(new DoctrineODMMongoDBAdapter($query));
     $pager->setMaxPerPage($this->getRequest()->get('pageMax', 10));
     $pager->setCurrentPage($this->getRequest()->get('page', 1));
     return array('attributes' => $pager->getCurrentPageResults(), 'pager' => $pager);
 }
コード例 #16
0
 /**
  * @Route("/", name="landmarx_category_index")
  * @Template("LandmarxLandmarkBundle:Category:index.html.twig")
  */
 public function indexAction()
 {
     $query = $this->get('doctrine_mongodb')->getRepository('LandmarxLandmarkBundle:Category')->createQueryBuilder('c')->OrderedBy('c.name', 'ASC');
     $pager = new Pagerfanta(new DoctrineODMMongoDBAdapter($query));
     $pager->setMaxPerPage($this->getRequest()->get('pageMax', 10));
     $pager->setCurrentPage($this->getRequest()->get('page', 1));
     return array('categories' => $pager->getCurrentPageResults(), 'pager' => $pager);
 }
コード例 #17
0
 public function testResultsPerOffset()
 {
     $pagerfanta = new Pagerfanta($this->adapter);
     $pagerfanta->setMaxPerPage(1);
     $currentPageResults = $pagerfanta->getCurrentPageResults();
     $expected = [['codigo' => "1", "tipo" => "01", "tipo2" => "01", "cvaluga" => "1", "bairro" => "4", "titulo" => "RUY PINHEIRO IMOVEIS", "texto" => "Boa Esperança - 03 Quartos, Sala, WC Social, Cozinha, Varanda, Área de Serviço, 04 Vagas de garagem, Vlr. R\$- 260.000,00, CRECI-J 0191, Fone:3623-6263, Site: ruypinheiroimoveis.com.br", "cod" => null]];
     $this->assertEquals($expected, $currentPageResults);
 }
コード例 #18
0
ファイル: RestController.php プロジェクト: ThreeDotsLabs/crm
 /**
  * @param Request          $request
  * @param AdapterInterface $adapter
  * @param string|null      $route
  *
  * @return PaginatedRepresentation
  */
 protected function paginate(Request $request, AdapterInterface $adapter, $route = null, $routeParameters = null)
 {
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage($request->query->get(self::LIMIT_PARAMETER, 5));
     $pagerfanta->setCurrentPage($request->query->get(self::PAGE_PARAMETER, 1));
     $collection = new CollectionRepresentation($pagerfanta->getCurrentPageResults());
     $paginated = new PaginatedRepresentation($collection, $route ?? $request->get('_route'), $routeParameters ?? $request->attributes->get('_route_params'), $pagerfanta->getCurrentPage(), $pagerfanta->getMaxPerPage(), $pagerfanta->getNbPages(), self::PAGE_PARAMETER, self::LIMIT_PARAMETER, false, $pagerfanta->count());
     return $paginated;
 }
コード例 #19
0
 /**
  * @param FilterInterface $filter
  * @param $searchParams
  * @param $page
  * @param $maxPerPage
  * @param Pagerfanta $pagerfanta
  * @return array
  */
 public function paginate($filter, $searchParams, $page, $maxPerPage, &$pagerfanta = null)
 {
     /** @var QueryBuilder $qb */
     $qb = $this->createQueryBuilder('x');
     $query = FilterBuilder::create()->setQueryBuilder($qb)->setFilter($filter)->buildQuery($searchParams)->getQuery();
     $adapter = new DoctrineORMAdapter($query, true, false);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setAllowOutOfRangePages(true)->setMaxPerPage($maxPerPage)->setCurrentPage($page);
     return iterator_to_array($pagerfanta->getCurrentPageResults());
 }
コード例 #20
0
ファイル: PeopleController.php プロジェクト: hasantayyar/ojs
 /**
  * @param  Request $request
  * @param  int $page
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function indexAction(Request $request, $page = 1)
 {
     $getRoles = $request->query->get('role_filters');
     $getSubjects = $request->query->get('subject_filters');
     $getJournals = $request->query->get('journal_filters');
     $roleFilters = !empty($getRoles) ? explode(',', $getRoles) : [];
     $subjectFilters = !empty($getSubjects) ? explode(',', $getSubjects) : [];
     $journalFilters = !empty($getJournals) ? explode(',', $getJournals) : [];
     $userSearcher = $this->get('fos_elastica.index.search.user');
     $userQuery = new Query('*');
     if (!empty($roleFilters) || !empty($subjectFilters) || !empty($journalFilters)) {
         $boolQuery = new Query\Bool();
         foreach ($roleFilters as $role) {
             $match = new Query\Match();
             $match->setField('journalUsers.roles', $role);
             $boolQuery->addMust($match);
         }
         foreach ($subjectFilters as $subject) {
             $match = new Query\Match();
             $match->setField('subjects', $subject);
             $boolQuery->addMust($match);
         }
         foreach ($journalFilters as $journal) {
             $match = new Query\Match();
             $match->setField('journalUsers.journal.title', $journal);
             $boolQuery->addMust($match);
         }
         $userQuery->setQuery($boolQuery);
     }
     $roleAgg = new Aggregation\Terms('roles');
     $roleAgg->setField('journalUsers.roles');
     $roleAgg->setOrder('_term', 'asc');
     $roleAgg->setSize(0);
     $userQuery->addAggregation($roleAgg);
     $subjectAgg = new Aggregation\Terms('subjects');
     $subjectAgg->setField('subjects');
     $subjectAgg->setOrder('_term', 'asc');
     $subjectAgg->setSize(0);
     $userQuery->addAggregation($subjectAgg);
     $journalAgg = new Aggregation\Terms('journals');
     $journalAgg->setField('journalUsers.journal.title');
     $journalAgg->setOrder('_term', 'asc');
     $journalAgg->setSize(0);
     $userQuery->addAggregation($journalAgg);
     $adapter = new ElasticaAdapter($userSearcher, $userQuery);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(20);
     $pagerfanta->setCurrentPage($page);
     $people = $pagerfanta->getCurrentPageResults();
     $roles = $adapter->getResultSet()->getAggregation('roles')['buckets'];
     $subjects = $adapter->getResultSet()->getAggregation('subjects')['buckets'];
     $journals = $adapter->getResultSet()->getAggregation('journals')['buckets'];
     $data = ['people' => $people, 'roles' => $roles, 'subjects' => $subjects, 'journals' => $journals, 'pagerfanta' => $pagerfanta, 'role_filters' => $roleFilters, 'subject_filters' => $subjectFilters, 'journal_filters' => $journalFilters, 'page' => 'ojs_site_people_index'];
     return $this->render('OjsSiteBundle:People:index.html.twig', $data);
 }
コード例 #21
0
 /**
  * @param Pagerfanta $object
  *
  * @return PaginatedRepresentation
  */
 protected function createPaginatedRepresentation($object)
 {
     if (!$object instanceof Pagerfanta) {
         return;
     }
     $items = $object->getCurrentPageResults();
     if ($items instanceof \ArrayIterator) {
         $items = $items->getArrayCopy();
     }
     return new PaginatedRepresentation($items, $object->getCurrentPage(), $object->getMaxPerPage(), $object->getNbPages(), $object->getNbResults());
 }
コード例 #22
0
ファイル: PagerfantaTest.php プロジェクト: 3lolo/lr_app
 private function assertResetCurrentPageResults($callback)
 {
     $this->setAdapterNbResultsAny(100);
     $this->pagerfanta->setMaxPerPage(10);
     $currentPageResults0 = new \ArrayObject();
     $currentPageResults1 = new \ArrayObject();
     $this->adapter->expects($this->at(0))->method('getSlice')->will($this->returnValue($currentPageResults0));
     $this->adapter->expects($this->at(1))->method('getSlice')->will($this->returnValue($currentPageResults1));
     $this->assertSame($currentPageResults0, $this->pagerfanta->getCurrentPageResults());
     $callback();
     $this->assertSame($currentPageResults1, $this->pagerfanta->getCurrentPageResults());
 }
コード例 #23
0
 /**
  * Lists past Shift entities that the user has picked up.
  *
  */
 public function pastAction()
 {
     $em = $this->getDoctrine()->getManager();
     $pastShifts = $em->getRepository('OpenSkedgeBundle:Shift')->findUserPastShifts($this->getUser()->getId());
     $page = $this->container->get('request')->query->get('page', 1);
     $adapter = new ArrayAdapter($pastShifts);
     $paginator = new Pagerfanta($adapter);
     $paginator->setMaxPerPage(15);
     $paginator->setCurrentPage($page);
     $entities = $paginator->getCurrentPageResults();
     return $this->render('OpenSkedgeBundle:Shift:past.html.twig', array('entities' => $entities, 'paginator' => $paginator));
 }
コード例 #24
0
 public function AllMoviesAction($page)
 {
     $maxActors = $this->getPosterViewMaxActors();
     $userListMovies = $this->get('bestophe_video_collection.movieUserManager')->getAllMovieUserList();
     $adapter = new ArrayAdapter($userListMovies);
     $pager = new Pagerfanta($adapter);
     $maxPerPage = $this->getPagerFantaMaxPerPage();
     $pager->setMaxPerPage($maxPerPage);
     $pager->setCurrentPage($page);
     $userListMovieCount = $pager->getNbResults();
     return $this->render('bestopheVideoCollectionBundle:MovieSection:MovieList/MoviePosterViewFanta.html.twig', array('listMovies' => $pager->getCurrentPageResults(), 'pager' => $pager, 'nbActors' => $maxActors, 'totalMovies' => $userListMovieCount));
 }
 /**
  * Get the content of the widget for the query mode
  *
  * @param Widget $widget
  *
  * @return string
  *
  */
 public function getWidgetQueryContent(Widget $widget)
 {
     $filterBuilder = $this->getWidgetQueryBuilder($widget);
     $adapter = new DoctrineORMAdapter($filterBuilder->getQuery());
     $pager = new Pagerfanta($adapter);
     if ($widget->getMaxResults() && is_integer($widget->getMaxResults())) {
         $pager->setMaxPerPage($widget->getMaxResults());
     }
     $pager->setCurrentPage($this->request->get('page') ?: 1);
     $items = $pager->getCurrentPageResults();
     $parameters = $this->getWidgetStaticContent($widget);
     return array_merge($parameters, array('items' => $items, 'pager' => $pager));
 }
 /**
  * Get the static content of the widget.
  *
  * @param Widget $widget
  *
  * @return string The static content
  *
  * @SuppressWarnings checkUnusedFunctionParameters
  */
 public function getWidgetQueryContent(Widget $widget)
 {
     $filterBuilder = $this->getWidgetQueryBuilder($widget);
     $filterBuilder->leftJoin('main_item.blog', 'blog')->addOrderBy('main_item.publishedAt', 'DESC')->addOrderBy('main_item.createdAt', 'DESC')->andWhere('main_item.status = :status')->orWhere('main_item.status = :scheduled_status AND main_item.publishedAt > :publicationDate')->setParameter('status', Article::PUBLISHED)->setParameter('scheduled_status', Article::SCHEDULED)->setParameter('publicationDate', new \DateTime());
     $adapter = new DoctrineORMAdapter($filterBuilder->getQuery());
     $pager = new Pagerfanta($adapter);
     if ($widget->getMaxResults() && is_int($widget->getMaxResults())) {
         $pager->setMaxPerPage($widget->getMaxResults());
     }
     $pager->setCurrentPage($this->request->get('page', $this->currentPage));
     $articles = $pager->getCurrentPageResults();
     $parameters = parent::getWidgetStaticContent($widget);
     return array_merge($parameters, ['items' => $articles, 'pager' => $pager]);
 }
コード例 #27
0
ファイル: Pagination.php プロジェクト: ceko/concrete5-1
 public function getCurrentPageResults()
 {
     $this->list->debugStart();
     $results = parent::getCurrentPageResults();
     $this->list->debugStop();
     $return = array();
     foreach ($results as $result) {
         $r = $this->list->getResult($result);
         if ($r != null) {
             $return[] = $r;
         }
     }
     return $return;
 }
コード例 #28
0
ファイル: Pager.php プロジェクト: bolt/Members
 /**
  * {@inheritdoc}
  */
 public function getCurrentPageResults()
 {
     $results = parent::getCurrentPageResults();
     if ($this->built === null) {
         foreach ($results as $key => $data) {
             $entity = $this->builder->getEntity();
             $this->builder->createFromDatabaseValues($data, $entity);
             $results[$key] = $entity;
         }
         $this->setCurrentPageResults($results);
         $this->built = true;
     }
     return $results;
 }
コード例 #29
0
 /**
  * @Route("/nearby", name="landmarx_landmark_nearby")
  * @Template("LandmarxLandmarkBundle:Landmark:index.html.twig")
  */
 public function nearbyAction()
 {
     $current = $this->ipinfo['ipinfo']['Location'];
     if (!is_array($current)) {
         $current = array('latitude' => 43.754419, 'longitude' => -70.409296);
         $this->get('session')->getFlashBag()->add('warning', 'your location could not accurately be determined. Default coordinates have been used.');
     }
     $radius = $this->getRequest()->get('radius', 25);
     $query = $this->get('doctrine_mongodb')->getRepository('LandmarxLandmarkBundle:Landmark')->createQueryBuilder('l')->field('coordinates')->geoNear($current['latitude'], $current['longitude'])->spherical(true)->distanceMultiplier(3963.192)->maxDistance($radius);
     $pager = new Pagerfanta(new DoctrineODMMongoDBAdapter($query));
     $pager->setMaxPerPage($this->getRequest()->get('pageMax', 10));
     $pager->setCurrentPage($this->getRequest()->get('page', 1));
     return array('landmarks' => $pager->getCurrentPageResults(), 'current' => $current, 'pager' => $pager);
 }
コード例 #30
0
 /**
  * Lists all Project entities.
  *
  * @Route("/", name="project")
  * @Template()
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     $page = $request->query->get('page', 1);
     // type?
     $type = $request->query->get('t', 0);
     if (!in_array($type, array(0, 1, 2))) {
         return $this->redirect($this->generateUrl('project'));
     }
     // category_id?
     $category_id = $request->query->get('c', 0);
     $q = $this->getDoctrine()->getEntityManager()->getRepository('ApplicationProjectBundle:Project')->getProjectsDQL($type, $category_id);
     $adapter = new DoctrineORMAdapter($q);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(10);
     // 10 by default
     $maxPerPage = $pagerfanta->getMaxPerPage();
     $pagerfanta->setCurrentPage($page);
     // 1 by default
     $entities = $pagerfanta->getCurrentPageResults();
     $routeGenerator = function ($page, $category_id, $type) {
         $url = '?page=' . $page;
         if ($category_id) {
             $url .= '&c=' . $category_id;
         }
         if ($type) {
             $url .= '&t=' . $type;
         }
         return $url;
     };
     $view = new DefaultView();
     $html = $view->render($pagerfanta, $routeGenerator, array('category_id' => (int) $category_id, 'type' => (int) $type));
     //$twig = $this->container->get('twig');
     //$twig->addExtension(new \Twig_Extensions_Extension_Text);
     switch ($type) {
         case 0:
             $page_title = 'Ideas';
             break;
         case 1:
             $page_title = 'Beta';
             break;
         case 2:
             $page_title = 'Startup';
             break;
         default:
             throw $this->createNotFoundException('Unable to find Category entity.');
             break;
     }
     return array('pager' => $html, 'entities' => $entities, 'type' => $type, 'page_title' => $page_title, 'category_id' => $category_id);
 }