本文整理汇总了PHP中Pagerfanta\Pagerfanta::getCurrentPageResults方法的典型用法代码示例。如果您正苦于以下问题:PHP Pagerfanta::getCurrentPageResults方法的具体用法?PHP Pagerfanta::getCurrentPageResults怎么用?PHP Pagerfanta::getCurrentPageResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagerfanta\Pagerfanta
的用法示例。
在下文中一共展示了Pagerfanta::getCurrentPageResults方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
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: __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);
}
}
}
示例3: 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));
}
示例4: it_iterates_slice
/**
* @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: 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;
}
示例6: searchAction
/**
* 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: createResponseArray
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: 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;
}
示例9: viewAction
/**
* 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: indexAction
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: 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;
}
示例12: indexAction
/**
* 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: 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());
}
示例14: __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();
}
示例15: indexAction
/**
* @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);
}