本文整理汇总了PHP中Pagerfanta\Pagerfanta::setMaxPerPage方法的典型用法代码示例。如果您正苦于以下问题:PHP Pagerfanta::setMaxPerPage方法的具体用法?PHP Pagerfanta::setMaxPerPage怎么用?PHP Pagerfanta::setMaxPerPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pagerfanta\Pagerfanta
的用法示例。
在下文中一共展示了Pagerfanta::setMaxPerPage方法的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: 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));
}
示例3: getPagerfanta
/**
* @return Pagerfanta
*/
public function getPagerfanta()
{
if (is_null($this->pagerfanta)) {
$adapter = new DoctrineDBALAdapter($this->getQueryBuilder(), $this->getCountField(), $this->getUseDistinctCount());
$this->pagerfanta = new Pagerfanta($adapter);
$this->pagerfanta->setCurrentPage($this->getPage());
$this->pagerfanta->setMaxPerPage($this->getLimit());
}
return $this->pagerfanta;
}
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:13,代码来源:AbstractDoctrineDBALAdminListConfigurator.php
示例4: getPagerfanta
/**
* @return Pagerfanta
*/
public function getPagerfanta()
{
if (is_null($this->pagerfanta)) {
$adapter = new DoctrineORMAdapter($this->getQuery());
$this->pagerfanta = new Pagerfanta($adapter);
$this->pagerfanta->setNormalizeOutOfRangePages(true);
$this->pagerfanta->setMaxPerPage($this->getLimit());
$this->pagerfanta->setCurrentPage($this->getPage());
}
return $this->pagerfanta;
}
开发者ID:VickyDeschrijver,项目名称:KunstmaanBundlesCMS,代码行数:14,代码来源:AbstractDoctrineORMAdminListConfigurator.php
示例5: getPagerfantaRepresentation
/**
* Construct a pagerfanta representation from the current request
*
* @param AdapterInterface $adapter - The adapter to use
* @return QueryablePaginatedRepresentation
*/
protected function getPagerfantaRepresentation(Request $request, AdapterInterface $adapter)
{
$pagerfanta = new Pagerfanta($adapter);
$limit = $request->query->get('limit');
$zeroLimit = false;
if (!$limit && ($limit === 0 || $limit === '0')) {
$limit = $pagerfanta->count();
$zeroLimit = true;
}
if (!$limit) {
$limit = 10;
}
$pagerfanta->setMaxPerPage($limit);
$page = $request->query->get('page');
$nbPages = $pagerfanta->getNbPages();
if (!$page) {
$page = 1;
}
// Avoid errors: redirect to max page
if ($page > $nbPages) {
$page = $nbPages;
}
$pagerfanta->setCurrentPage($page);
$route = new Route($request->get('_route'), $request->attributes->get('_route_params'), false);
return new QueryablePaginatedRepresentation(new CollectionRepresentation($pagerfanta->getCurrentPageResults()), $route->getName(), $route->getParameters(), $pagerfanta->getCurrentPage(), $zeroLimit ? 0 : $pagerfanta->getMaxPerPage(), $nbPages, $pagerfanta->count(), null, null, $route->isAbsolute(), $request->query->get('where'), $request->query->get('search'), $request->query->get('order'), null, null, null);
}
示例6: renderResults
/**
* @param TaxonInterface $taxon
* @param Pagerfanta $results
* @param $template
* @param $page
* @param null $facets
* @param null $facetTags
* @param null $filters
* @param null $searchTerm
* @param null $searchParam
* @param null $requestMethod
* @return \Symfony\Component\HttpFoundation\Response
*/
private function renderResults(TaxonInterface $taxon, Pagerfanta $results, $template, $page, $facets = null, $facetTags = null, $filters = null, $searchTerm = null, $searchParam = null, $requestMethod = null)
{
$results->setCurrentPage($page, true, true);
$results->setMaxPerPage($this->config->getPaginationMaxPerPage());
$view = $this->view()->setTemplate($this->config->getTemplate($template))->setData(array('taxon' => $taxon, 'products' => $results, 'facets' => $facets, 'facetTags' => $facetTags, 'filters' => $filters, 'searchTerm' => $searchTerm, 'searchParam' => $searchParam, 'requestMethod' => $requestMethod));
return $this->handleView($view);
}
示例7: getPagerfanta
/**
* Get search results from Google.
*
* {@inheritdoc}
*/
public function getPagerfanta($query, $locale)
{
$adapter = new GoogleRestAdapter($this->googleApiKey, $this->getSearchKey($locale), $this->googleSearchAPIUrl, $query, $this->restrictLanguage ? $locale : false, $this->restrictToSite);
$pager = new Pagerfanta($adapter);
$pager->setMaxPerPage($this->maxPerPage);
return $pager;
}
示例8: 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;
}
示例9: listAction
/**
* @param int $page
* @return \Symfony\Component\HttpFoundation\Response
*/
public function listAction($page)
{
$pagerfanta = new Pagerfanta($this->galleryManager->createPagerfantaAdapter());
$pagerfanta->setMaxPerPage($this->galleriesPerPage);
$pagerfanta->setCurrentPage($page);
return $this->templating->renderResponse('FSiGalleryBundle:Gallery:list.html.twig', array('galleries' => $pagerfanta, 'preview_photos_count' => $this->previewPhotosCount));
}
示例10: renderPagination
/**
* @return string
*/
public function renderPagination(Page $page, Twig_Environment $environment)
{
$pagerfanta = new Pagerfanta(new PorpaginasAdapter($page));
$pagerfanta->setCurrentPage($page->getCurrentPage());
$pagerfanta->setMaxPerPage($page->getCurrentLimit());
return $environment->getExtension('pagerfanta')->renderPagerfanta($pagerfanta, $this->viewName, $this->options);
}
示例11: findLatest
/**
* @param int $page
*
* @return Pagerfanta
*/
public function findLatest($page = 1)
{
$paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false));
$paginator->setMaxPerPage(Post::NUM_ITEMS);
$paginator->setCurrentPage($page);
return $paginator;
}
示例12: 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.');
}
}
示例13: createOrmPaginator
/**
* Creates a Doctrine ORM paginator for the given query builder.
*
* @param DoctrineQuery|DoctrineQueryBuilder $queryBuilder
* @param int $page
* @param int $maxPerPage
*
* @return Pagerfanta
*/
public function createOrmPaginator($queryBuilder, $page = 1, $maxPerPage = self::MAX_ITEMS)
{
$paginator = new Pagerfanta(new DoctrineORMAdapter($queryBuilder, true, false));
$paginator->setMaxPerPage($maxPerPage);
$paginator->setCurrentPage($page);
return $paginator;
}
示例14: indexAction
/**
* @Route("/opencast/mediapackage", name="pumukitopencast")
* @Template()
*/
public function indexAction(Request $request)
{
if (!$this->has('pumukit_opencast.client')) {
throw $this->createNotFoundException('PumukitOpencastBundle not configured.');
}
$opencastClient = $this->get('pumukit_opencast.client');
$repository_multimediaobjects = $this->get('doctrine_mongodb')->getRepository('PumukitSchemaBundle:MultimediaObject');
$limit = 10;
$page = $request->get("page", 1);
$criteria = $this->getCriteria($request);
try {
list($total, $mediaPackages) = $opencastClient->getMediaPackages(isset($criteria["name"]) ? $criteria["name"]->regex : "", $limit, ($page - 1) * $limit);
} catch (\Exception $e) {
return new Response($this->render('PumukitOpencastBundle:MediaPackage:error.html.twig', array('message' => $e->getMessage())), 400);
}
$currentPageOpencastIds = array();
foreach ($mediaPackages as $mediaPackage) {
$currentPageOpencastIds[] = $mediaPackage["id"];
}
$adapter = new FixedAdapter($total, $mediaPackages);
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($limit);
$pagerfanta->setCurrentPage($page);
$repo = $repository_multimediaobjects->createQueryBuilder()->field("properties.opencast")->exists(true)->field("properties.opencast")->in($currentPageOpencastIds)->getQuery()->execute();
return array('mediaPackages' => $pagerfanta, 'multimediaObjects' => $repo, 'player' => $opencastClient->getPlayerUrl());
}
示例15: 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);
}