本文整理汇总了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;
}
示例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();
}
示例3: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
if (null === $this->_result) {
return parent::getIterator();
}
return new \ArrayIterator($this->_result);
}
示例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());
}
示例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());
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例12: getIterator
/**
* {@inheritdoc}
*/
public function getIterator()
{
return $this->paginator->getIterator();
}
示例13: getItems
/**
* {@inheritDoc}
*
* @api
*/
public function getItems($offset, $limit)
{
$this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($limit);
return iterator_to_array($this->paginator->getIterator());
}
示例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());
}
示例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);
}