Calculate the current page to inform the user about the pagination state.

@param  int  $first
@param  int  $after
@param  int  $defaultPage
@return int
354241
public static function calculateCurrentPage(int $first, int $after, int $defaultPage = 1): int
    {
        return $first && $after
            ? (int) floor(($first + $after) / $first)
            : $defaultPage;
    }
702105
public function getCurrentPage()
    {
        $page = $this->getRequest()->query->getInt($this->getActionQueryParameter(static::QUERY_PARAMETER_PAGE), 1);
        if ($page < 1) {
            $page = 1;
        }
        return $page;
    }
192935
public function _INDEX_NewPage(&$page)
    {
        if ($page) {
            $oldPage = $this->pdf->getPage();
            $this->pdf->setPage($page);
            $this->pdf->SetXY($this->_margeLeft, $this->_margeTop);
            $this->_maxH = 0;
            $page++;
            return $oldPage;
        } else {
            $this->_setNewPage();
            return null;
        }
    }
1109668
public int getNextPage(int prevPage) {
		reportFreePage(prevPage);
		
		if (iter.hasNextULL()) {
			//ArrayList<Long> toDelete = new ArrayList<>();
			LongLongIndex.LLEntry e = iter.nextULL();
			long pageId = e.getKey();
			long value = e.getValue();
			
			// do not return pages that are PID_DO_NOT_USE.
			while ((value > maxFreeTxId || value < 0) && iter.hasNextULL()) {
				if (value < 0 && ((-value) <= maxFreeTxId)) {
					//optimisation:, collect in list and remove later?
					toDelete.add((int)pageId);
//					idx.removeLong(pageId);
//					//idx.insertLong(pageId, -currentTxId);
//					iter.close();
//					iter = (LLIterator) idx.iterator(pageId+1, Long.MAX_VALUE);
					//idx.removeLong(pageId, value);
					//TODO or implement iter.remove() ?!
				}
				e = iter.nextULL();
				pageId = e.getKey();
				value = e.getValue();
			}
//			if (!toDelete.isEmpty()) {
//				for (Long l: toDelete) {
//					idx.removeLong(l);
//				}
//			}
			if (value >= 0 && value <= maxFreeTxId) {
				//TODO or implement iter.updateValue() ?!
				//idx.removeLong(pageId);
				idx.insertLong(pageId, -currentTxId);
				iter.close();
				iter = idx.iterator(pageId+1, Long.MAX_VALUE);
				return (int) pageId;
			}
//			if (!toDelete.isEmpty()) {
//				iter.close();
//				iter = (LLIterator) idx.iterator(pageId+1, Long.MAX_VALUE);
//			}
		}
		
		//If we didn't find any we allocate a new page.
		return lastPage.addAndGet(1);
	}
816286
def pagination(page, limit, length):
        
        realpage = page
        page = page or CtsCapitainsLocalResolver.DEFAULT_PAGE
        limit = limit or CtsCapitainsLocalResolver.PER_PAGE[1]

        if limit < CtsCapitainsLocalResolver.PER_PAGE[0] or limit > CtsCapitainsLocalResolver.PER_PAGE[2]:
            limit = CtsCapitainsLocalResolver.PER_PAGE[1]

        page = (page - 1) * limit

        if page > length:
            realpage = int(ceil(length / limit))
            page = limit * (realpage - 1)
            count = length - 1
        elif limit - 1 + page < length:
            count = limit - 1 + page
        else:
            count = length - 1

        return page, count + 1, realpage, count - page + 1
1122517
public function getAvailablePage ($total_count, $current_page = 1, $limit = PagerUtility::DISP_PER_PAGE, $options = []) {
 		$max_page = PagerUtility::GetMaxPage($total_count, $limit);
 		return ($current_page <= $max_page) ? $current_page : $max_page;
 	}
1128224
public function getDefaultPerPage()
    {
        if (!in_array($this->defaultPerPage, $this->perPageList)) {
            $this->defaultPerPage = $this->perPageList[0];
        }

        return $this->defaultPerPage;
    }
450365
public function setCurrentPage($page)
    {
        if ($page > 0 && $page <= $this->getPageCount()) {
            $this->currentpage = $page;
        } else {
            $this->currentpage = 1;
        }

        // $start = ($this->currentpage - 1) * $this->pagesize;
        // $this->setPageRows($start, $this->pagesize);
        //  $this->Reload();
    }
818578
public static function page($total, $perPage)
        {
            $page = (null === request()->getCrudNumPage()) ? 1 : request()->getCrudNumPage();

            // The page will be validated and adjusted if it is less than one or greater
            // than the last page. For example, if the current page is not an integer or
            // less than one, one will be returned. If the current page is greater than
            // the last page, the last page will be returned.
            if (is_numeric($page) && $page > $last = ceil($total / $perPage)) {
                return ($last > 0) ? $last : 1;
            }

            return (static::valid($page)) ? $page : 1;
        }
719197
def first(self):
        

        if self.total and self.limit < self.total:
            return {'page[offset]': 0, 'page[limit]': self.limit}
        else:
            return None
146419
public function calculate()
    {
        $this->calculatePageLimitAndOffset();
        $pageNumber = $this->getPageNumber();
        $offset = $this->getPaginationOffset();


        /* Setup page vars for display. */
        if ($pageNumber == 0) {
            $pageNumber = 1; //if no page var is given, default to 1.
        }
        $this->previous = $pageNumber - 1;
        $this->next = $pageNumber + 1;
        //last page is = total pages / items per page, rounded up.
        $this->lastPage = ceil($this->getTotalNumberOfPages() / $this->perPage);

        $this->lastPageMinusOne = $this->lastPage - 1;  //last page minus 1
        $this->create();
    }
615096
public function getCurrentPage()
    {
        $page = (int) $this->request->getParam(self::PAGE_PARM_NAME);
        return $page ? $page : 1;
    }
872545
protected function calculateEndPageForStartPageUnderflow(int $startPage, int $endPage, int $nbPages): int
    {
        return min($endPage + (1 - $startPage), $nbPages);
    }
283275
public function page($page = 1, $step = 20) {
        $start = ($page - 1) * $step;
        $this->limit($start, $step);
        $data = $this->findAll();
        return $data;
    }
1205667
private function setPagination()
    {
        // ALl Pages
        if ($this->perPage == 'all') return;

        $this->firstPage    = 1;
        $this->lastPage     = ceil($this->totalCount / $this->perPage);

        // if current page is greater than the total page
        // then set the current page equal to total page
        $this->page = min($this->page, $this->lastPage);

        // Calculate the offset of where the retrieval index start at
        $this->offset   = ($this->page - 1) * $this->perPage;
        $this->limit    = $this->perPage;

        // Next Page And Previous Page
        $this->nextPage = min($this->page + 1, $this->lastPage);
        $this->prevPage = max($this->page - 1, $this->firstPage);
    }
1201229
protected function calculateCurrentPage($lastPage)
	{
		$page = $this->env->getCurrentPage();

		// The page number will get validated and adjusted if it either less than one
		// or greater than the last page available based on the count of the given
		// items array. If it's greater than the last, we'll give back the last.
		if (is_numeric($page) && $page > $lastPage)
		{
			return $lastPage > 0 ? $lastPage : 1;
		}

		return $this->isValidPageNumber($page) ? (int) $page : 1;
	}
195889
protected function calculateStartAndEndPage()
    {
        $currentPage = $this->pagerfanta->getCurrentPage();
        $nbPages = $this->pagerfanta->getNbPages();

        $startPage = $currentPage - $this->proximity;
        $endPage = $currentPage + $this->proximity;

        if ($startPage < 1) {
            $endPage = $this->calculateEndPageForStartPageUnderflow($startPage, $endPage, $nbPages);
            $startPage = 1;
        }

        if ($endPage > $nbPages) {
            $startPage = $this->calculateStartPageForEndPageOverflow($startPage, $endPage, $nbPages);
            $endPage = $nbPages;
        }

        $this->startPage = (int) $startPage;
        $this->endPage = (int) $endPage;
    }