Number of element per page
@return int element per page
502248
public function objectsPerPage()
    {
        $perPage = 10;
        if (!empty($this->headers[self::PER_PAGE]) && is_array($this->headers[self::PER_PAGE])) {
            $perPage = (int) $this->headers[self::PER_PAGE][0];
        }

        return $perPage;
    }
1177245
public function display_page_numbers() {
        $html = '';
        $topcount = count($this->items);
        $this->pagecount = (integer) ceil(($topcount + $this->offset)/ QUESTION_PAGE_LENGTH );
        if (!empty($this->page) && ($this->paged)) {
            $html = "<div class=\"paging\">".get_string('page').":\n";
            foreach (range(1,$this->pagecount) as $currentpage) {
                if ($this->page == $currentpage) {
                    $html .= " $currentpage \n";
                }
                else {
                    $html .= "<a href=\"".$this->pageurl->out(true, array($this->pageparamname => $currentpage))."\">";
                    $html .= " $currentpage </a>\n";
                }
            }
            $html .= "</div>";
        }
        return $html;
    }
157104
public function paginate(int $page = 1, int $perPage = 25) : self
    {
        return $this->limit($perPage, ($page - 1) * $perPage);
    }
519515
public function calculate(): Pagination
    {
        // calculate how many page
        $this->pages_count = 1;
        if ($this->items_count > 0 && $this->items_per_page > 0) {
            $this->pages_count = ceil(($this->items_count / $this->items_per_page));
        } elseif ($this->items_count == 0) {
            $this->pages_count = 0;
        }
        
        // generate pages array
        $this->pages = [];
        if ($this->pages_count > 0) {
            $this->pages = range(1, $this->pages_count);
        }

        // check current page
        if (!$this->isPage($this->current_page)) {
            throw new Exception(__CLASS__.': page '.$this->current_page.' doesn\'t exists');
        }

        $this->first_page = empty($this->pages) ? null : 1;
        $this->last_page = ($this->pages_count < 1) ? null : $this->pages_count;

        // prev/next page
        $this->prev_page = ($this->current_page > 1) ? $this->current_page  - 1 : null;
        $this->next_page = (($this->current_page + 1) <= $this->pages_count) ? $this->current_page + 1 : null;
        
        // item start/end page
        $this->item_start = (($this->current_page - 1) * $this->items_per_page);
        $this->item_end = $this->item_start + $this->items_per_page;
        
        if (($this->items_count != 0)) {
            ++$this->item_start;
        }
        if ($this->item_end > $this->items_count) {
            $this->item_end = $this->items_count;
        }

        // item start offset
        $this->offset = $this->item_start - 1;

        return $this;
    }
88545
public function paginate()
    {
        $totalCount = $this->getCount();

        $pageCount = $this->maxResults ? intval(ceil($totalCount / $this->maxResults)) : 1;
        $current = $this->page;
        $pageRange = 5;

        if ($pageCount < $current) {
            $current = $pageCount;
        }

        if ($pageRange > $pageCount) {
            $pageRange = $pageCount;
        }

        $delta = ceil($pageRange / 2);

        if ($current - $delta > $pageCount - $pageRange) {
            $pages = range($pageCount - $pageRange + 1, $pageCount);
        } else {
            if ($current - $delta < 0) {
                $delta = $current;
            }

            $offset = $current - $delta;
            $pages = range($offset + 1, $offset + $pageRange);
        }

        $proximity = floor($pageRange / 2);

        $startPage = $current - $proximity;
        $endPage = $current + $proximity;

        if ($startPage < 1) {
            $endPage = min($endPage + (1 - $startPage), $pageCount);
            $startPage = 1;
        }

        if ($endPage > $pageCount) {
            $startPage = max($startPage - ($endPage - $pageCount), 1);
            $endPage = $pageCount;
        }

        $pagination = [
            'last' => (int)$pageCount,
            'current' => (int)$current,
            'numItemsPerPage' => $this->maxResults ?? ucfirst(self::ALL_PARAMETER),
            'first' => 1,
            'pageCount' => (int)$pageCount,
            'totalCount' => (int)$totalCount,
            'pageRange' => $pageRange,
            'startPage' => (int)$startPage,
            'endPage' => (int)$endPage,
            'route' => $this->route,
            'routeParams' => $this->routeParams,
            'query' => $this->queryFilter,
            'pageParameterName' => 'page',
            'sort' => $this->sort,
        ];

        if ($current - 1 > 0) {
            $pagination['previous'] = $current - 1;
        }

        if ($current + 1 <= $pageCount) {
            $pagination['next'] = $current + 1;
        }

        $pagination['pagesInRange'] = $pages;
        $pagination['firstPageInRange'] = min($pages);
        $pagination['lastPageInRange'] = max($pages);

        $items = $this->getRecords();
        if ($items !== null) {
            $pagination['currentItemCount'] = (int)$totalCount;
            $pagination['firstItemNumber'] = $this->maxResults ? (($current - 1) * $this->maxResults) + 1 : 1;
            $pagination['lastItemNumber'] =  $pagination['firstItemNumber'] + $pagination['currentItemCount'] - 1;
        }

        return [
            'items' => $items,
            'pagination' => $pagination
        ];
    }
118376
public function getLastIndex()
    {	
		if (!$this->itemCountPerPage) return $this->getCountAll();
		$count = $this->itemCountPerPage + $this->itemCountPerPage * ($this->pageNumber - 1);
		if ($count > $this->getCountAll()) $count = $this->getCountAll();
		return $count;
	}
135935
public function currentPage()
    {
        $currentRoute = $this->router->getCurrentRoute();

        if (! $currentRoute) {
            return 1;
        }

        $query = $currentRoute->parameter('pageQuery');

        return (int) str_replace($this->pageKeyword.'/', '', $query) ?: 1;
    }
116204
public function getItemsPerPageSession()
    {
        $variable = 'search/' . $this->getSessionNamespace() . '/items_per_page';
        if ($this->session->has($variable)) {
            return (int) $this->session->get($variable);
        }

        return null;
    }
286084
public function getPagesNumber() {
		if ($this->_entirePagesNumber === null) {
			$this->_entirePagesNumbe = (int) ceil($this->getAdapter()->count() / $this->_itemsPerPage);
		}
		
		return $this->_entirePagesNumbe;
	}
723636
public function getCollectionSize()
    {
        $size = 0;
        foreach ($this->pageList as $page) {
            $size += $page->getPageElementCount();
        }
        return $size;
    }
623269
public function getTotalPages()
    {
        // Pages before
        $pages = ceil(($this->getFirstShown() - 1) / $this->getItemsPerPage());

        // Current page
        $pages++;

        // Pages after
        $pages += ceil(($this->getTotalRecords() - $this->getLastShown()) / $this->getItemsPerPage());

        return (int) $pages;
    }
304119
public function getTotalPages()
    {
        if (empty($this->totalPages)) {
            $this->totalPages = (int)ceil($this->getCursor()->count()/$this->limit);
        }

        return $this->totalPages;
    }
1085207
public function pageNum()
    {
        $link = $this->_doc->navigation('self');
        return ($link && isset($link->pagenum)) ? $link->pagenum : 1;
    }
821228
public function getPerPage()
	{
		$items_per_page_list = array_keys($this->getItemsPerPageList());

		$per_page = $this->per_page ?: reset($items_per_page_list);

		if (($per_page !== 'all' && !in_array((int) $this->per_page, $items_per_page_list, true))
			|| ($per_page === 'all' && !in_array($this->per_page, $items_per_page_list, true))) {
			$per_page = reset($items_per_page_list);
		}

		return $per_page;
	}
182106
protected function getPageList() {
		$linkPage = '';
		$linkPage .= $this->replaceLine(1);
		$lastList = floor($this->get('length') / 2);
		$i = 0;
		$length = 0;
		if ($this->pageTotal < $this->get('length') || $this->get('page') - $lastList < 2 || $this->pageTotal - $this->get('length') < 2) {
			$i = 2;
			if ($this->pageTotal <= $this->get('length')) {
				$length = $this->pageTotal - 1;
			} else {
				$length = $this->get('length');
			}
		} elseif ($this->get('page') - $lastList>= 2 && $this->get('page') + $lastList <= $this->pageTotal) {
			$i = $this->get('page')- $lastList;
			$length = $this->get('page') + $lastList- 1;
		} elseif ($this->get('page') + $lastList > $this->pageTotal) {
			$i = $this->pageTotal - $this->get('length') + 1;
			$length = $this->pageTotal - 1;
		}
		if ($this->get('page') > $lastList + 1 && $i > 2) {
			$linkPage .= $this->getOmit();
		}
		for (; $i <= $length; $i ++) {
			$linkPage .= $this->replaceLine($i);
		}
		if ($this->get('page') < $this->pageTotal - $lastList && $length < $this->pageTotal - 1) {
			$linkPage .= $this->getOmit();
		}
		$linkPage .= $this->replaceLine($this->pageTotal);
		return $linkPage;
	}
628741
public function getLastPage()
    {
        $perPage = max($this->paginatedResult->getQuery()->getItemsPerPage(), 1);
        $total = $this->getTotal();
        $pageCount = $total / $perPage;

        if (round($pageCount, 1) - round($pageCount, 0) > 0) {
            return round($pageCount, 0) + 1;
        }

        return round($pageCount, 0);
    }
626791
public int getPage() {
        int row = getRow();
        assert row % getPageSize() == 0 : "Invalid current row \"" + row + "\" for page size \"" + getPageSize() + "\"";
        assert getPageSize() > 0;
        return row / getPageSize();
    }