Prepare pagination.

@param int $offset Offset number.
@param int $limit  Limit.

@return string|null

@throws PageNotFoundException When page parameter is out of bounds.
513097
protected function preparePagination(&$offset, &$limit): ?string
    {
        $total   = count($this->images);
        $perPage = $this->get('perPage');

        // Paginate the result of not randomly sorted (see #8033)
        if ($perPage > 0 && $this->get('sortBy') != 'random') {
            // Get the current page
            $parameter = 'page_g' . $this->get('id');
            $page      = (Input::get($parameter) !== null) ? Input::get($parameter) : 1;

            // Do not index or cache the page if the page number is outside the range
            if ($page < 1 || $page > max(ceil($total / $perPage), 1)) {
                throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
            }

            // Set limit and offset
            $offset = (($page - 1) * $perPage);
            $limit  = min(($perPage + $offset), $total);

            $pagination = new Pagination(
                $total,
                $perPage,
                Config::get('maxPaginationLinks'),
                $parameter
            );

            return $pagination->generate("\n  ");
        }

        return null;
    }
293668
protected function parseLimit($offset, $limit)
    {
        if(null === $limit)
        {
            return '';
        }
        else if(null === $offset)
        {
            $limitName = Query::getAutoParamName();
            $this->params[$limitName] = $limit;
            return ' limit ' . $limitName;
        }
        else
        {
            $offsetName = Query::getAutoParamName();
            $this->params[$offsetName] = $offset;
            $limitName = Query::getAutoParamName();
            $this->params[$limitName] = $limit;
            return ' limit ' . $offsetName . ',' . $limitName;
        }
    }
788384
public function limit($limit, $offset = null)
    {
        $this->queryBuilder->setLimit($limit, $offset);
        return $this;
    }
1029925
public function find($limit = 20, $offset = 0)
	{
		return $this->buildFind()
			->setLimit($limit)
			->setOffset($offset)
			->find();
	}
144466
public function limit($limit, $offset = NULL)
	{
		$this->emptyResult();

		$this->queryBuilder->limit($limit, $offset);
		return $this;
	}
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;
    }
410392
public function withOffsetLimit($offset, $limit)
    {
        $new = clone $this;
        $new->offset = $offset;
        $new->limit = $limit;
        $new->paginationType = self::OFFSET_LIMIT_PAGINATION;

        return $new;
    }
1106826
public function getPosts($limit = false, $offset = false)
    {
        if (!$limit) {
            $limit = Option::get('posts_per_page');
        }
        return Post::getByAuthor($this->ID, $limit, $offset);
    }
804498
private function addPagination(Search $search, $pageSize, $page, $limit)
    {
        $offset = 0;
        if ($pageSize) {
            $pageSize = intval($pageSize);
            $offset = ($page - 1) * $pageSize;
        }

        if (null === $limit) {
            $limit = $this->defaultLimit;
        }

        if (null === $pageSize || $offset + $pageSize > $limit) {
            $pageSize = $limit - $offset;

            if ($pageSize < 0) {
                $pageSize = 0;
            }
        }

        $search->setFrom($offset);
        $search->setSize($pageSize);
    }
899541
protected function set_limit($query, $limit = 0, $offset = 0)
    {
        $limit  = intval($limit);
        $offset = intval($offset);
        $end    = $offset + $limit;

        // query without OFFSET
        if (!$offset) {
            $query = preg_replace('/^SELECT\s/i', "SELECT TOP $limit ", $query);
            return $query;
        }

        $orderby = stristr($query, 'ORDER BY');
        $offset += 1;

        if ($orderby !== false) {
            $query = trim(substr($query, 0, -1 * strlen($orderby)));
        }
        else {
            // it shouldn't happen, paging without sorting has not much sense
            // @FIXME: I don't know how to build paging query without ORDER BY
            $orderby = "ORDER BY 1";
        }

        $query = preg_replace('/^SELECT\s/i', '', $query);
        $query = "WITH paging AS (SELECT ROW_NUMBER() OVER ($orderby) AS [RowNumber], $query)"
            . " SELECT * FROM paging WHERE [RowNumber] BETWEEN $offset AND $end ORDER BY [RowNumber]";

        return $query;
    }
1086376
public function limit($limit, $offset = 0)
    {
        return $this->alterDataQuery(function (DataQuery $query) use ($limit, $offset) {
            $query->limit($limit, $offset);
        });
    }
1083424
public function findAll($limit = 0, $offset = 0)
    {
        $limit = $this->getLimit($limit, $offset);
        $query = 'SELECT ' . $this->getFields(", ") . '
                  FROM ' . $this->tableName . '
                  ' . $limit . ' ;';
        $statement = $this->database->prepare($query);
        $statement->execute();
        return $this->buildAll($statement->fetchAll());
    }
1283391
public static <E> Page<E> offsetPage(int offset, int limit) {
        return offsetPage(offset, limit, DEFAULT_COUNT);
    }
902404
public function getPagedResults($limit = 50, $page = 0): Paginator
    {
        $dql = sprintf(self::DQL_GET_PAGED, TargetTemplate::class);
        return $this->getPaginator($dql, $limit, $page);
    }
1316551
public function paginate($limit)
    {
        try {
            if (!is_null($this->query)) {

                $limit = request()->limit ?? $limit;
                $offset = request()->offset ?? 0;

                $this->query .= ' LIMIT '.$limit. ' OFFSET '.$offset;

                $statement = $this->connect->prepare($this->query);
                $statement->execute();
                return $statement->fetchAll();
            }

        } catch (\Exception $exception) {
            var_dump($exception->getMessage());
        }
    }
947998
protected function doModifyLimitQuery($query, $limit, $offset)
    {
        if ($limit !== null) {
            $query .= ' LIMIT ' . $limit;
        }

        if ($offset > 0) {
            $query .= ' OFFSET ' . $offset;
        }

        return $query;
    }
550873
public function load(int $offset = 0, int $limit = 25): self
    {
        $this->data = array_map(
            function (Location $location) {
                return $this->valueFactory->createBookmark($location);
            },
            $this->bookmarkService->loadBookmarks($offset, $limit)->items
        );

        return $this;
    }