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


PHP Paginator::getIterator方法代码示例

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


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

示例1: getIterator

 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     if (null === $this->iterator) {
         $this->iterator = $this->paginator->getIterator();
     }
     return $this->iterator;
 }
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:10,代码来源:Paginator.php

示例2: paginate

 /**
  * @inheritDoc
  */
 public function paginate($target, $offset, $limit)
 {
     $target->setFirstResult($offset)->setMaxResults($limit);
     $paginator = new Paginator($target);
     $this->total = $paginator->count();
     return $paginator->getIterator();
 }
开发者ID:xideapl,项目名称:base,代码行数:10,代码来源:QueryBuilder.php

示例3: getIterator

 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     if (null === $this->_result) {
         return parent::getIterator();
     }
     return new \ArrayIterator($this->_result);
 }
开发者ID:gobjila,项目名称:BackBee,代码行数:10,代码来源:SettablePaginator.php

示例4: paginateAll

 /**
  * @param  int         $offset
  * @param  int         $limit
  * @param  string|null $status
  * @return PaginationResult
  */
 public function paginateAll($offset, $limit, $status = null)
 {
     $queryBuilder = $this->entityRepository->createQueryBuilder('invoice');
     $queryBuilder->innerJoin('invoice.client', 'client');
     $queryBuilder->setFirstResult($offset);
     $queryBuilder->setMaxResults($limit);
     $queryBuilder->orderBy('invoice.id', 'desc');
     switch ($status) {
         case 'paid':
             $queryBuilder->andWhere('invoice.payDate IS NOT NULL');
             break;
         case 'late':
             $queryBuilder->andWhere('invoice.payDate IS NULL');
             $queryBuilder->andWhere('invoice.dueDate IS NOT NULL');
             $queryBuilder->andWhere('invoice.dueDate < :now');
             $queryBuilder->setParameter('now', new DateTime());
             break;
         case 'sent':
             $queryBuilder->andWhere('invoice.payDate IS NULL');
             $queryBuilder->andWhere('invoice.dueDate IS NULL OR invoice.dueDate >= :now');
             $queryBuilder->andWhere('invoice.sendDate IS NOT NULL');
             $queryBuilder->setParameter('now', new DateTime());
             break;
         case 'draft':
             $queryBuilder->andWhere('invoice.payDate IS NULL');
             $queryBuilder->andWhere('invoice.dueDate IS NULL OR invoice.dueDate >= :now');
             $queryBuilder->andWhere('invoice.sendDate IS NULL');
             $queryBuilder->setParameter('now', new DateTime());
             break;
     }
     $paginator = new Paginator($queryBuilder->getQuery(), false);
     return new PaginationResult($paginator->getIterator(), $paginator->count());
 }
开发者ID:DavidHavl,项目名称:Ajasta,代码行数:39,代码来源:InvoiceRepository.php

示例5: indexAction

 /**
  * Lists all Viaggio entities.
  *
  * @Route("/", name="travel")
  * @Method("GET")
  * @Template("AppBundle:Viaggio:mete-visitate.html.twig")
  */
 public function indexAction()
 {
     $this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!');
     $em = $this->getDoctrine()->getManager();
     $user = $this->container->get('security.context')->getToken()->getUser();
     $user_id = $user->getId();
     // $entities = $em->getRepository('AppBundle:Viaggio')->findBy(['utente'=>$user, 'salvato'=>true],['id' => 'DESC']);
     // Limit per page.
     $limit = 4;
     $page = $this->getRequest()->query->get("page", 1);
     $thisPage = $page;
     $query = $em->createQuery("SELECT viaggio, viaggio.id, viaggio.descrizione, viaggio.meta, viaggio.partenza, viaggio.arrivo, viaggio.periodo, viaggio.salvato, user.id\n            FROM AppBundle:Viaggio viaggio\n            JOIN AppBundle:User user WHERE (viaggio.utente = {$user_id})\n            WHERE viaggio.salvato = true\n            ORDER BY viaggio.id DESC")->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
     // $questo=$query->getResult();
     $paginator = new Paginator($query, $fetchJoinCollection = true);
     $maxPages = ceil($paginator->count() / $limit);
     // $c = count($paginator);
     // foreach ($paginator as $post) {
     //     echo $post->getHeadline() . "\n";
     // }
     $birthDate = $user->getDataDiNascita();
     $age = null;
     if ($birthDate != null) {
         //explode the date to get month, day and year
         $birthDate = explode("-", $birthDate);
         //get age from date or birthdate
         $age = date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? date("Y") - $birthDate[2] - 1 : date("Y") - $birthDate[2];
     }
     $ultimaSalvata = $em->getRepository('AppBundle:Viaggio')->findOneBy(array('utente' => $user->getId(), 'salvato' => true), array('id' => 'DESC'));
     return array('eta' => $age, 'salvata' => $ultimaSalvata, 'user' => $user, 'maxPages' => $maxPages, 'thisPage' => $thisPage, 'issues' => $paginator->getIterator());
 }
开发者ID:antoninoSTB,项目名称:dovados,代码行数:37,代码来源:ViaggioController.php

示例6: createPaginated

 /**
  * @return PaginatedResourceCollection
  */
 protected function createPaginated()
 {
     $entities = $this->paginator->getIterator()->getArrayCopy();
     $metadata = $this->mineMetadata($entities);
     $resources = array_map([$this, 'createResource'], $entities);
     $collection = new PaginatedResourceCollection($resources, $metadata);
     $collection->setPaginator($this->paginator);
     return $collection;
 }
开发者ID:gointegro,项目名称:hateoas,代码行数:12,代码来源:ResourceCollectionFactory.php

示例7: findWithJoins

 /**
  * @param $params
  *
  * @return mixed
  */
 public function findWithJoins($params)
 {
     $queryBuilder = $this->createQueryBuilder('h')->select('h, s, t, lc, cer, pm, hp, tr')->leftJoin('h.services', 's')->leftJoin('h.thematics', 't')->leftJoin('h.linkedCities', 'lc')->leftJoin('h.certificates', 'cer')->leftJoin('h.paymentMethods', 'pm')->leftJoin('h.hotelPois', 'hp')->leftJoin('h.transports', 'tr');
     $i = 0;
     foreach ($params as $key => $value) {
         $queryBuilder->andWhere("h.{$key} = :param_{$i}")->setParameter("param_{$i}", $value);
         $i++;
     }
     $query = $queryBuilder->setMaxResults(1)->getQuery();
     $results = new Paginator($query, $fetchJoin = true);
     return $results->getIterator()->current();
 }
开发者ID:blab2015,项目名称:seh,代码行数:17,代码来源:HotelRepository.php

示例8: fetch

 /**
  * @param mixed $query      query
  * @param int   $page       page
  * @param int   $maxPerPage maxPerPage
  *
  * @throws \Exception
  * @return \Traversable
  */
 public function fetch($query, $page = 1, $maxPerPage = 10)
 {
     if (!$query instanceof DoctrineQueryBuilder) {
         throw new \Exception('Not supported yet');
     }
     if ($maxPerPage) {
         $offset = ($page - 1) * (int) $maxPerPage;
         $query->setFirstResult($offset)->setMaxResults($maxPerPage);
     }
     // use pager even if it's a query executor, to fix number of results returned issue.
     $paginator = new Paginator($query, true);
     return (array) $paginator->getIterator();
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:21,代码来源:QueryExecutor.php

示例9: fetchItems

 /**
  * Fetch items by node
  * http://docs.doctrine-project.org/en/latest/tutorials/pagination.html
  * http://stackoverflow.com/questions/10043588/doctrine-2-pagination-with-association-mapping
  * http://docs.doctrine-project.org/en/latest/reference/query-builder.html
  * @param object $node The node
  * @param array $options Associtive array
  * $options = array(
  *  'page' => $theCurrentPage,
  *  'rowsPerPage' => $theRowsPerPage
  *  'sortField' => $theFieldToSort
  *  'sortDirection' => $theDirectionToSort
  * )
  * @return object \Zend\Paginator
  */
 public function fetchItems($node, $options = array())
 {
     $page = (int) isset($options['page']) ? $options['page'] : 0;
     $maxRows = (int) isset($options['rowsPerPage']) ? $options['rowsPerPage'] : 15;
     $sortField = isset($options['sortField']) ? $options['sortField'] : 'created';
     $sortDirection = isset($options['sortDirection']) ? $options['sortDirection'] : 'DESC';
     $cacheName = $this->cacheName($node->getId() . 'collection' . __FUNCTION__ . $page . $maxRows . $sortField . $sortDirection);
     $query = $this->_em->createQuery("\n\t\t\tSELECT i\n\t\t\t FROM DxBuySell\\Entity\\Item i \n\t\t\t  INNER JOIN i.categories c\n\t\t\t  WHERE c.id = " . $node->getId() . " \n\t\t\t  ORDER By i." . $sortField . " " . $sortDirection);
     $query->useResultCache($this->cacheEnabled, $this->cacheLifetime, $cacheName);
     $paginator = new Paginator($query, $fetchJoinCollection = true);
     $zendPaginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\Iterator($paginator->getIterator()));
     $zendPaginator->setItemCountPerPage($maxRows)->setCurrentPageNumber($page);
     return $zendPaginator;
 }
开发者ID:dennesabing,项目名称:dx-buy-sell,代码行数:29,代码来源:Category.php

示例10: paginate

 /**
  * {@inheritdoc}
  */
 public function paginate($target, $page = 1, $limit = 10)
 {
     if (!$target instanceof DoctrineQueryBuilder) {
         throw new \Exception('Not supported yet');
     }
     if ($limit) {
         $offset = ($page - 1) * (int) $limit;
         $target->setFirstResult($offset)->setMaxResults($limit);
     }
     $paginator = new Paginator($target, true);
     $this->page = $page;
     $this->items = (array) $paginator->getIterator();
     $this->nbResults = count($paginator);
     $this->lastPage = intval(ceil($this->nbResults / $limit));
     return $this;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:19,代码来源:Pager.php

示例11: getResult

 /**
  * Sets up the query, builds the output and returns it ready for JSON encoding
  */
 public function getResult()
 {
     $query = $this->getQueryBuilder()->getQuery();
     // Only use the paginator if we have joins
     if (!empty($this->links)) {
         $paginator = new Paginator($query, true);
         $results = iterator_to_array($paginator->getIterator());
     } else {
         $results = $query->getResult();
     }
     // Build the output array
     if ($this->field) {
         $this->buildFieldOutput($results, $this->field);
     } else {
         // Get meta info for the root type
         $this->buildOutputMeta($results);
         // Get Doctrine to add the missing collection data
         $this->performAllHydrations();
         $this->buildOutput($results);
     }
     return $this->output;
 }
开发者ID:soundintheory,项目名称:fuel-cmf,代码行数:25,代码来源:query.php

示例12: getIterator

 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     return $this->paginator->getIterator();
 }
开发者ID:reminec,项目名称:DunglasApiBundle,代码行数:7,代码来源:Paginator.php

示例13: getItems

 /**
  * {@inheritDoc}
  *
  * @api
  */
 public function getItems($offset, $limit)
 {
     $this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($limit);
     return iterator_to_array($this->paginator->getIterator());
 }
开发者ID:kgilden,项目名称:pager,代码行数:10,代码来源:DqlAdapter.php

示例14: testCloneQuery

 public function testCloneQuery()
 {
     $dql = "SELECT u FROM Doctrine\\Tests\\Models\\CMS\\CmsUser u";
     $query = $this->_em->createQuery($dql);
     $paginator = new Paginator($query);
     $paginator->getIterator();
     $this->assertTrue($query->getParameters()->isEmpty());
 }
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:8,代码来源:PaginationTest.php

示例15: getResult

 public function getResult()
 {
     $perPage = $this->getPerPage();
     $page = $this->getPage();
     $queryBuilder = $this->createResultQueryBuilder();
     try {
         if ($perPage !== null) {
             $queryBuilder->setMaxResults($perPage);
             $queryBuilder->setFirstResult($perPage * ($page - 1));
             $query = $queryBuilder->getQuery();
             $paginator = new Paginator($query, true);
             $entities = $paginator->getIterator()->getArrayCopy();
         } else {
             $query = $queryBuilder->getQuery();
             $entities = $query->getResult();
         }
         $total = $this->getTotal();
     } catch (NoResultException $e) {
         $entities = array();
         $total = 0;
     }
     $routeParameters = $this->getRouteParameters();
     return new EntityFinderResult($entities, $total, $page, $perPage, $routeParameters);
 }
开发者ID:Kyoushu,项目名称:CommonBundle,代码行数:24,代码来源:AbstractEntityFinder.php


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