Paginate the results of the query.

@param ActiveQueryInterface $query
@param int $pageNumber
@param int $count

@return ActiveQueryInterface
766522
private function paginateRecords(ActiveQueryInterface $query, $pageNumber, $count)
    {
        $offset = ($pageNumber - 1) * $count;
        $limit = $count;

        return $query->offset($offset)->limit($limit);
    }
205893
public function count($parentId, array $query = [])
    {
        $resource = $this->createPartialResourceUrlForList($parentId).'/count';

        return $this->client->get($resource, $query)['count'];
    }
307787
final public function queryPager(
        string $querySelect,
        string $queryCount = '',
        int $page = 1,
        int $recordsPerPage = 20
    ) {
        try {
            return $this->createPager($querySelect, $queryCount, $page, $recordsPerPage);
        } catch (\Throwable $exception) {
            $this->logger->error("DBAL::queryPager failure running $querySelect");
            return false;
        }
    }
37995
public function scopeSimplePaginateFilter($query, $perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    {
        $perPage = $perPage ?: config('eloquentfilter.paginate_limit');
        $paginator = $query->simplePaginate($perPage, $columns, $pageName, $page);
        $paginator->appends($this->filtered);

        return $paginator;
    }
455769
public function paginate(AbstractQuery $query, $perPage, $pageName = 'page', $fetchJoinCollection = true)
    {
        return PaginatorAdapter::fromRequest(
            $query,
            $perPage,
            $pageName,
            $fetchJoinCollection
        )->make();
    }
496791
public function paginate($size = null, $page = null)
    {
        $this->page($size, $page);

        $items = $this->fetch(true);

        if ($this->_limit === null) {
            $count = count($items);
        } elseif (count($items) % $this->_limit === 0) {
            $count = $this->count();
        } else {
            $count = $this->_offset + count($items);
        }

        $paginator = $this->paginator;

        $paginator->items = $items;

        return $paginator->paginate($count, $this->_limit, (int)($this->_offset / $this->_limit) + 1);
    }
513243
public function listByPageId(int $pageId, int $begin, int $count)
    {
        $params = [
            'type' => 2,
            'page_id' => $pageId,
            'begin' => $begin,
            'count' => $count,
        ];

        return $this->httpPostJson('shakearound/relation/search', $params);
    }
886198
public function pagination($page, $limit, $query = null, $orderBy = null, $sort = 'ASC', $filter = null)
    {
        $entityClassAlias = $this->getEntityClassAlias();

        // Create a Doctrine Collection
        $queryBuilder = $this->getObjectManager()->createQueryBuilder();
        $queryBuilder->select($entityClassAlias)
                     ->from($this->getEntityClass(), $entityClassAlias);

        $paramCounter = 0;

        if (is_array($filter)) {
            $paramCounter = $this->addFilterToQueryBuilder($filter, $queryBuilder);
        }

        //Add joins to query builder
        $this->addJoinTablesToQueryBuilder($queryBuilder);

        if (null !== $query) {
            $properties    = $this->getQueryableProperties();
            $orExpressions = array();
            $paramCounter++;

            foreach ($properties as $property) {
                $orExpressions[] = $queryBuilder->expr()->like($property, '?' . $paramCounter);
            }

            $queryBuilder->andWhere(
                call_user_func_array(array($queryBuilder->expr(), "orX"), $orExpressions)
            );

            $queryBuilder->setParameter($paramCounter, $query);
        }

        if ($orderBy) {
            $orderByIdentifier = $this->getOrderByIdentifier($orderBy);

            if (!$sort) {
                $sort = 'ASC';
            }
            $queryBuilder->orderBy($orderByIdentifier, $sort);
        }

        // Create the paginator itself
        $paginator = new Paginator(
            new DoctrinePaginator(new ORMPaginator($queryBuilder))
        );

        $paginator->setCurrentPageNumber($page)
                  ->setItemCountPerPage($limit)
                  ->setPageRange(5);

        return $paginator;
    }
759740
public static function page( int $page , int $count , int $pagesize = 10) :array
    {

//        if(empty($count)){
//            throw new \Exception('Tools page throw : count must is integer and greater than 0!');
//        }
        if( empty($page) || !is_numeric($page) ){
            $page = 1;
        }

        if( empty($pagesize) || !is_numeric($pagesize)){
            $pagesize = 10;
        }

        $maxpage = ceil($count / $pagesize);//获取最大页数

        $limit = [($page - 1) * $pagesize,$pagesize];

        return [
            'page' => $page,
            'pagesize' => $pagesize,
            'count' => $count,
            'maxpage' => $maxpage,
            'limit' => $limit
        ];
    }
104561
private function query($count)
    {
        $this->applyQueryFilters();

        if ($this->hasTranslating()) {
            $this->applyTranslationFilter();
        }

        if ($this->orderBy()) {
            $this->query = $this->query->orderBy(
                                $this->orderBy(),
                                $this->sortBy()
                            );
        }

        if ($count) {
            return $this->query->count();
        }

        if ($this->perPage > 0) {
            return $this->query->paginate($this->perPage);
        }

        return $this->query->get();
    }
1037346
private function createSelectablePaginator(Selectable $selectable, Criteria $criteria, $page, $count)
    {
        return $this->createPaginator(new DoctrineSelectableAdapter($selectable, $criteria), $page, $count);
    }
1273957
function paginate($conditions, $fields, $order, $limit, $page, $recursive){

		$sql  = $this->sql;
		$sql .= " LIMIT " . $this->limit . " ";
		$sql .= " OFFSET " . (($page - 1) * $this->limit);

		return $this->query($sql);
	}
1224942
public function paginate(array $data, $page, $limit , $url, $params = array())
    {
        $pager = $this->makePagerFromArray($data, $page, $limit);

        return $this->factory->createCollectionFromPager($pager, $url, $params);
    }
11786
protected function each(Builder $query, $count = 100): Generator
    {
        $query = $this->exportableQuery($query);

        // enforce order by statement.
        if (empty($query->orders) && empty($query->unionOrders)) {
            $query->orderBy($query->getModel()->getQualifiedKeyName(), 'asc');
        }

        $page = 1;

        do {
            // We'll execute the query for the given page and get the results. If there are
            // no results we can just break and return from here. When there are results
            // we will call the callback with the current chunk of these results here.
            $results = $query->forPage($page, $count)->get();

            $countResults = $results->count();

            if (0 === $countResults) {
                break;
            }

            // On each chunk result set, we will pass them to the callback and then let the
            // developer take care of everything within the callback, which allows us to
            // keep the memory low for spinning through large result sets for working.
            foreach ($results as $index => $item) {
                yield $index = $item;
            }

            unset($results);

            ++$page;
        } while ($countResults === $count);
    }
347420
public function iterNextPage($count = 3)
    {
        if ($this->getPage() == 1 && $this->getPagesCount() >= $count * 2) {
            $count *= 2;
        }
        $pages = [];
        foreach (range(1, $count) as $i) {
            $page = $this->getPage() + $i;
            if ($page <= $this->getPagesCount()) {
                $pages[] = $page;
            }
        }

        return $pages;
    }
767506
private SelectQuery incrementQueryPagination(SelectQuery query, SelectResultValue prevResult)
  {
    Map<String, Integer> pagingIdentifiers = prevResult.getPagingIdentifiers();
    Map<String, Integer> newPagingIdentifers = new HashMap<>();

    for (String segmentId : pagingIdentifiers.keySet()) {
      int newOffset = pagingIdentifiers.get(segmentId) + 1;
      newPagingIdentifers.put(segmentId, newOffset);
    }

    return query.withPagingSpec(new PagingSpec(newPagingIdentifers, pagingThreshold));
  }
690288
private function endQuery(SelectInterface $query, $count) {
    $result = $query
      ->range(0, $count)
      ->execute()
      ->fetchCol();

    return !empty($result) ? $result : [];
  }