本文整理汇总了PHP中Doctrine\ORM\Tools\Pagination\Paginator::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Paginator::getQuery方法的具体用法?PHP Paginator::getQuery怎么用?PHP Paginator::getQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\Pagination\Paginator
的用法示例。
在下文中一共展示了Paginator::getQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIterator
/**
* Required by interface IteratorAggregate.
*
* {@inheritdoc}
*/
public function getIterator()
{
$query = $this->paginator->getQuery();
$query->setFirstResult(null);
$query->setMaxResults(null);
return $this->paginator;
}
示例2: __construct
/**
* @param Query|QueryBuilder $query
* @param int $limit
* @param int $currentPage
*/
public function __construct($query, $limit, $currentPage = 1)
{
$this->paginator = new DoctrinePaginator($query);
$this->totalCount = $this->paginator->count();
$this->limit = $limit;
$this->pagesCount = (int) ceil($this->totalCount / $this->limit);
if ($this->pagesCount > 0 && $currentPage > $this->pagesCount) {
$currentPage = $this->pagesCount;
}
$this->currentPage = $currentPage;
$this->paginator->getQuery()->setFirstResult($this->limit * ($this->currentPage - 1))->setMaxResults($this->limit);
$this->query = $query;
}
示例3: paginate
/**
* Paginator Helper
* Pass through a query object, current page & limit
* the offset is calculated from the page and limit
* returns an `Paginator` instance, which you can call the following on:
* $paginator->getIterator()->count() # Total fetched (ie: `5` posts)
* $paginator->count() # Count of ALL posts (ie: `20` posts)
* $paginator->getIterator() # ArrayIterator
*
* @param Doctrine\ORM\Query $dql
* DQL Query Object
* @param integer $page
* Current page (defaults to 1)
* @param integer $limit
* The total number per page (defaults to 5)
* @return \Doctrine\ORM\Tools\Pagination\Paginator
*/
public function paginate($dql, $page = 1, $limit = 15)
{
$paginator = new Paginator($dql);
$paginator->getQuery()->setFirstResult($limit * ($page - 1))->setMaxResults($limit);
// Limit
return $paginator;
}
示例4: findByCollector
/**
* @param string $collector
* @param int $page
* @param int $maxItemPerPage
*
* @return Paginator
*/
public function findByCollector($collector, $page, $maxItemPerPage)
{
$query = $this->createQueryBuilder('c')->where('c.collector = :collector')->setParameter('collector', $collector)->getQuery();
$paginator = new Paginator($query);
$paginator->getQuery()->setFirstResult($maxItemPerPage * ($page - 1))->setMaxResults($maxItemPerPage);
return $paginator;
}
示例5: __construct
/**
* @param Query|QueryBuilder $query
* @param int $perPage
* @param int $page
*/
public function __construct($query, $perPage, $page)
{
$paginator = new Paginator($query);
$paginator->getQuery()->setFirstResult($perPage * ($page - 1))->setMaxResults($perPage);
$this->resource = $paginator;
$this->page = $page;
$this->perPage = $perPage;
}
示例6: __construct
public function __construct(DoctrineOrmPaginator $paginator)
{
$this->paginator = $paginator;
$this->query = $paginator->getQuery();
$this->firstResult = $this->query->getFirstResult();
$this->maxResults = $this->query->getMaxResults();
$this->totalItems = count($paginator);
}
示例7: paginate
public function paginate($dql, $offset = 1, $limit = 10)
{
if ($limit > 100 || $limit <= 0) {
$limit = 100;
}
$paginator = new Paginator($dql, false);
$paginator->getQuery()->setMaxResults($limit)->setFirstResult(($offset - 1) * $limit);
return $paginator;
}
示例8: findAllStartsWith
public function findAllStartsWith($letter, $page, $per_page)
{
$query = $this->joinQuery();
if ($letter != 'ALL') {
$query->where('s.name LIKE :letter')->setParameter('letter', "{$letter}%");
}
$query->orderBy('s.name', 'ASC')->addOrderBy('p.name', 'ASC')->addOrderBy('i.imageName', 'ASC');
$paginator = new Paginator($query, $fetchJoinCollection = true);
$paginator->getQuery()->setFirstResult(($page - 1) * $per_page)->setMaxResults($per_page);
return $paginator;
}
示例9: paginate
/**
* Generate paginated output
*
* @param \Doctrine\ORM\QueryBuilder $qb
* @param int $limit
* @param int $offset
*
* @return \FOS\RestBundle\View\View
*/
protected function paginate(\Doctrine\ORM\QueryBuilder $qb, $limit = null, $offset = null)
{
if ($offset != null && intval($offset) > 0) {
$qb->setFirstResult($offset);
}
if ($limit != null && intval($limit) > 0) {
$qb->setMaxResults($limit);
}
$paginator = new Paginator($qb, $fetchJoinCollection = true);
$view = $this->createView($paginator->getQuery()->getResult());
$view->setHeader('X-Pagination-Total-Results', count($paginator));
return $view;
}
示例10: paginate
public static function paginate($query, &$pageSize = 10, &$currentPage = 1)
{
$pageSize = (int) $pageSize;
$currentPage = (int) $currentPage;
if ($pageSize < 1) {
$pageSize = 10;
}
if ($currentPage < 1) {
$currentPage = 1;
}
$paginator = new Paginator($query);
$paginator->getQuery()->setFirstResult($pageSize * ($currentPage - 1))->setMaxResults($pageSize);
return $paginator;
}
示例11: findByAccount
/**
* recuperer les transactions d un compte et entres 2 dates
* @param type $oAccount
* @param type $sDateBegin
* @param type $sDateEnd
* @return null
*/
public function findByAccount($oAccount, $sDateBegin, $sDateEnd, $oCategory = null, $sWording = null, $sOperation = null, $nFirstResult = null, $nPerPage = null)
{
try {
if (is_null($nPerPage)) {
$nPerPage = self::PER_PAGE;
}
$sOperator = null;
if (!is_null($sOperation)) {
$sOperator = '<';
if ($sOperation == self::CREDIT) {
$sOperator = '>';
}
}
$oQB = $this->createQueryBuilder('t');
$oQB->innerJoin('t.account', 'a');
$oQB->innerJoin('t.category', 'c');
$oQB->OrderBy('t.date', 'ASC');
$oQB->where('t.account = :account')->setParameter('account', $oAccount);
$oQB->andWhere('t.date >= :date_b ')->setParameter('date_b', $sDateBegin);
$oQB->andWhere('t.date <= :date_f ')->setParameter('date_f', $sDateEnd);
if (!is_null($sOperator)) {
$oQB->andWhere('t.amount ' . $sOperator . ' :val')->setParameter('val', 0);
}
if (!is_null($oCategory)) {
$oQB->andWhere('t.category = :category')->setParameter('category', $oCategory);
}
if (!is_null($sWording)) {
$oQB->andWhere('t.wording LIKE :word')->setParameter('word', '%' . $sWording . '%');
}
$oQB->addSelect('c');
$oQB->addSelect('a');
$nTotalResult = count($oQB->getQuery()->getResult());
if (!is_null($nFirstResult)) {
$oQB->setFirstResult($nFirstResult);
$oQB->setMaxResults($nPerPage);
$paginator = new Paginator($oQB->getQuery(), $fetchJoinCollection = true);
return array('TotalRecordCount' => $nTotalResult, 'Records' => $paginator->getQuery()->getResult());
}
return $oQB->getQuery()->getResult();
} catch (NoResultException $ex) {
return null;
}
}
示例12: getSlice
/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
$this->paginator->getQuery()->setFirstResult($offset)->setMaxResults($length);
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: searchUsers
public function searchUsers($filters)
{
$entityManager = $this->getEntityManager();
$query = $entityManager->createQueryBuilder();
if ($filters['fields']) {
$fields = 'partial u.{' . implode($this->getFieldsAndOrFilter($filters['fields']), ',') . '}';
} else {
$fields = 'partial u.{' . implode($this->getFieldsAndOrFilter(), ',') . '}';
}
$query->select($fields);
$query->from('Api:User', 'u');
if ($filters['query']) {
foreach ($filters['query'] as $q) {
if ($q['operator'] == '=' || $q['operator'] == 'LIKE') {
$query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' :' . $q['field']);
$query->setParameter($q['field'], $q['values']);
} elseif ($q['operator'] == 'IN') {
$query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' (:' . $q['field'] . ')');
$query->setParameter($q['field'], $q['values']);
} elseif ($q['operator'] == 'BETWEEN') {
$query->andWhere('u.' . $q['field'] . ' ' . $q['operator'] . ' :' . $q['field'] . 'A AND :' . $q['field'] . 'B');
$query->setParameter($q['field'] . 'A', $q['values'][0]);
$query->setParameter($q['field'] . 'B', $q['values'][1]);
}
}
}
if ($filters['sort']) {
foreach ($filters['sort'] as $key => $value) {
$query->addOrderBy('u.' . $key, $value);
}
}
if ($filters['offset']) {
$query->setFirstResult($filters['offset']);
}
if ($filters['limit']) {
$query->setMaxResults($filters['limit']);
} else {
$query->setMaxResults(10);
}
$paginator = new Paginator($query, true);
$results = $paginator->getQuery()->getResult(Query::HYDRATE_ARRAY);
return ['metadata' => ['total_rows' => count($paginator), 'result_rows' => count($results)], 'results' => $results];
}
示例15: paginate
private function paginate($query, $offset, $limit)
{
$paginator = new Paginator($query);
$paginator->getQuery()->setFirstResult($offset)->setMaxResults($limit);
return $paginator;
}