当前位置: 首页>>代码示例>>PHP>>正文


PHP Pagerfanta::getNbResults方法代码示例

本文整理汇总了PHP中Pagerfanta\Pagerfanta::getNbResults方法的典型用法代码示例。如果您正苦于以下问题:PHP Pagerfanta::getNbResults方法的具体用法?PHP Pagerfanta::getNbResults怎么用?PHP Pagerfanta::getNbResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pagerfanta\Pagerfanta的用法示例。


在下文中一共展示了Pagerfanta::getNbResults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: searchAction

 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));
 }
开发者ID:KnpLabs,项目名称:KnpBundles,代码行数:60,代码来源:BundleController.php

示例2: __construct

 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);
         }
     }
 }
开发者ID:dstansby,项目名称:camdram,代码行数:25,代码来源:PaginatedCollection.php

示例3: execute

 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;
 }
开发者ID:KnpLabs,项目名称:KnpBundles,代码行数:28,代码来源:MigrateCommitsCommand.php

示例4: createRepresentationFromPagerfanta

 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;
 }
开发者ID:claroline,项目名称:distribution,代码行数:9,代码来源:PaginatedCollectionRepresentation.php

示例5: createCollection

 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;
 }
开发者ID:C3-TKO,项目名称:smash-api,代码行数:35,代码来源:PaginationFactory.php

示例6: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var SolrIndexer $indexer */
     $indexer = $this->getContainer()->get('knp_bundles.indexer.solr');
     /** @var EntityManager $em */
     $em = $this->getContainer()->get('doctrine')->getManager();
     /** @var \Solarium_Client $solarium */
     $solarium = $this->getContainer()->get('solarium.client');
     /** @var EntityRepository $repository */
     $repository = $em->getRepository('KnpBundlesBundle:Bundle');
     $query = $solarium->createSelect();
     $query->setFields(array('name', 'ownerName'));
     try {
         $hasMoreResults = true;
         $page = 1;
         while ($hasMoreResults) {
             $paginator = new Pagerfanta(new SolariumAdapter($solarium, $query));
             $paginator->setMaxPerPage(50)->setCurrentPage($page, false, true);
             foreach ($paginator as $bundle) {
                 $entity = $repository->findOneBy(array('name' => $bundle['name']));
                 if (!$entity) {
                     $entity = new Bundle();
                     $entity->setName($bundle['name']);
                     $entity->setOwnerName($bundle['ownerName']);
                     $indexer->deleteBundlesIndexes($entity);
                     $output->writeln(sprintf('The bundle "%s" was deleted from solr index.', $entity->getFullName()));
                 }
             }
             $hasMoreResults = $paginator->getNbResults() == 50;
             $page++;
         }
     } catch (\Solarium_Client_HttpException $e) {
         throw new \Exception('Seems that our search engine is currently offline. Please check later.');
     }
 }
开发者ID:KnpLabs,项目名称:KnpBundles,代码行数:35,代码来源:KbSolrRemoveFromIndexCommand.php

示例7: indexAction

 public function indexAction(Request $req)
 {
     $rawSpeakers = $this->app['spot']->mapper(\OpenCFP\Domain\Entity\User::class)->all()->order(['first_name' => 'ASC'])->toArray();
     $airports = $this->service(AirportInformationDatabase::class);
     $rawSpeakers = array_map(function ($speaker) use($airports) {
         try {
             $airport = $airports->withCode($speaker['airport']);
             $speaker['airport'] = ['code' => $airport->code, 'name' => $airport->name, 'country' => $airport->country];
         } catch (\Exception $e) {
             $speaker['airport'] = ['code' => null, 'name' => null, 'country' => null];
         }
         return $speaker;
     }, $rawSpeakers);
     // Set up our page stuff
     $adapter = new ArrayAdapter($rawSpeakers);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(20);
     $pagerfanta->getNbResults();
     if ($req->get('page') !== null) {
         $pagerfanta->setCurrentPage($req->get('page'));
     }
     // Create our default view for the navigation options
     $routeGenerator = function ($page) {
         return '/admin/speakers?page=' . $page;
     };
     $view = new TwitterBootstrap3View();
     $pagination = $view->render($pagerfanta, $routeGenerator, ['proximity' => 3]);
     $templateData = ['airport' => $this->app->config('application.airport'), 'arrival' => date('Y-m-d', $this->app->config('application.arrival')), 'departure' => date('Y-m-d', $this->app->config('application.departure')), 'pagination' => $pagination, 'speakers' => $pagerfanta, 'page' => $pagerfanta->getCurrentPage()];
     return $this->render('admin/speaker/index.twig', $templateData);
 }
开发者ID:intfrr,项目名称:opencfp,代码行数:30,代码来源:SpeakersController.php

示例8: createRepresentation

 /**
  * @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());
 }
开发者ID:uvillazon,项目名称:symfonysecuriy,代码行数:14,代码来源:PagerfantaFactory.php

示例9: __construct

 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();
 }
开发者ID:Koc,项目名称:stfalcon-test-task,代码行数:8,代码来源:PhotosCollection.php

示例10: getPager

 /**
  * Return pagers
  *
  * @return array
  */
 public function getPager()
 {
     // view
     if (!$this->pagerfanta) {
         return [];
     }
     $pager = ['maxPerPage' => $this->maxPerPage, 'current' => $this->currentPage, 'total' => $this->pagerfanta->getNbResults(), 'hasNext' => $this->pagerfanta->hasNextPage(), 'hasPrevious' => $this->pagerfanta->hasPreviousPage(), 'html' => $this->getHtml($this->pagerfanta)];
     return $pager;
 }
开发者ID:rsky,项目名称:BEAR.Package,代码行数:14,代码来源:Connection.php

示例11: createPaginatedRepresentation

 /**
  * @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());
 }
开发者ID:jared-fraser,项目名称:JsonApiBundle,代码行数:16,代码来源:PagerfantaHandler.php

示例12: AllMoviesAction

 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));
 }
开发者ID:ChristWood,项目名称:videoCollection,代码行数:12,代码来源:MovieSectionController.php

示例13: indexAction

 public function indexAction()
 {
     $contentService = $this->getRepository()->getContentService();
     $content = $contentService->loadContent(74);
     $location = $this->getRepository()->getLocationService()->loadLocation(73);
     $query = new Query();
     $query->criterion = new Criterion\LogicalAnd(array(new Criterion\ContentTypeIdentifier('projet')));
     $query->sortClauses = array(new SortClause\Field('projet', 'annee', Query::SORT_DESC, 'fre-FR'), new SortClause\Field('projet', 'mois', Query::SORT_DESC, 'fre-FR'));
     $pager = new Pagerfanta(new ContentSearchAdapter($query, $this->getRepository()->getSearchService()));
     $pager->setMaxPerPage(12);
     $pager->setCurrentPage($this->getRequest()->get('page', 1));
     $contentTypeService = $this->getRepository()->getContentTypeService();
     $contentType = $contentTypeService->loadContentTypeByIdentifier('projet');
     $categories = $contentType->getFieldDefinition('categorie')->fieldSettings['options'];
     return $this->render('SibilleEcommerceBundle:full:portfolio.html.twig', array('content' => $content, 'location' => $location, 'total' => $pager->getNbResults(), 'projets' => $pager, 'categories' => $categories));
 }
开发者ID:dsibille,项目名称:damien-sibille.fr,代码行数:16,代码来源:PortfolioController.php

示例14: serializePagerfanta

 /**
  * @param JsonApiSerializationVisitor $visitor
  * @param Pagerfanta                  $pagerfanta
  * @param array                       $type
  * @param Context                     $context
  * @return Pagerfanta
  */
 public function serializePagerfanta(JsonApiSerializationVisitor $visitor, Pagerfanta $pagerfanta, array $type, Context $context)
 {
     $request = $this->requestStack->getCurrentRequest();
     $pagerfanta->setNormalizeOutOfRangePages(true);
     $pagerfanta->setAllowOutOfRangePages(true);
     $pagerfanta->setMaxPerPage($request->get('page[limit]', $this->paginationOptions['limit'], true));
     $pagerfanta->setCurrentPage($request->get('page[number]', 1, true));
     $results = $pagerfanta->getCurrentPageResults();
     if ($results instanceof \ArrayIterator) {
         $results = $results->getArrayCopy();
     }
     $data = $context->accept($results);
     $root = $visitor->getRoot();
     $root['meta'] = array('page' => $pagerfanta->getCurrentPage(), 'limit' => $pagerfanta->getMaxPerPage(), 'pages' => $pagerfanta->getNbPages(), 'total' => $pagerfanta->getNbResults());
     $root['links'] = array('first' => $this->getUriForPage(1), 'last' => $this->getUriForPage($pagerfanta->getNbPages()), 'prev' => $pagerfanta->hasPreviousPage() ? $this->getUriForPage($pagerfanta->getPreviousPage()) : null, 'next' => $pagerfanta->hasNextPage() ? $this->getUriForPage($pagerfanta->getNextPage()) : null);
     $visitor->setRoot($root);
     return $data;
 }
开发者ID:aliebing,项目名称:JsonApiBundle,代码行数:25,代码来源:PagerfantaHandler.php

示例15: indexAction

 private function indexAction(Request $req)
 {
     $rawSpeakers = $this->app['spot']->mapper('OpenCFP\\Domain\\Entity\\User')->all()->order(['first_name' => 'ASC'])->toArray();
     // Set up our page stuff
     $adapter = new ArrayAdapter($rawSpeakers);
     $pagerfanta = new Pagerfanta($adapter);
     $pagerfanta->setMaxPerPage(20);
     $pagerfanta->getNbResults();
     if ($req->get('page') !== null) {
         $pagerfanta->setCurrentPage($req->get('page'));
     }
     // Create our default view for the navigation options
     $routeGenerator = function ($page) {
         return '/admin/speakers?page=' . $page;
     };
     $view = new TwitterBootstrap3View();
     $pagination = $view->render($pagerfanta, $routeGenerator, ['proximity' => 3]);
     $templateData = ['airport' => $this->app->config('application.airport'), 'arrival' => date('Y-m-d', $this->app->config('application.arrival')), 'departure' => date('Y-m-d', $this->app->config('application.departure')), 'pagination' => $pagination, 'speakers' => $pagerfanta, 'page' => $pagerfanta->getCurrentPage()];
     return $this->render('admin/speaker/index.twig', $templateData);
 }
开发者ID:EmpireJS,项目名称:opencfp,代码行数:20,代码来源:SpeakersController.php


注:本文中的Pagerfanta\Pagerfanta::getNbResults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。