? Php + versions + | PHPVersion4 | + ---------------------------------------------------------------------- + | Copyright (c) 1997-2002ThePHPGroup | + ------------------------ // + ------------------------------------------------------------------------ +
// | PHP Version 4 |
// + ------------------------------------------------------------------------ +
// | Copyright (c) 1997-2002 The PHP Group |
// + ------------------------------------------------------------------------ +
// | This source file is subject to version 2.02 of the PHP license, |
// | That is bundled with this package in the file LICENSE, and is |
// | Available at through the world-wide-web at |
// | Http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | Obtain it through the world-wide-web, please send a note to |
// License@php.net so we can mail you a copy immediately. |
// + ------------------------------------------------------------------------ +
// | Authors: Richard Heyes |
// + ------------------------------------------------------------------------ +
/**
* Pager class
*
* Handles paging a set of data. For usage see the example. php provided.
*
*/
Class Pager {
/**
* Current page
* @ Var integer
*/
Var $ _ currentPage;
/**
* Items per page
* @ Var integer
*/
Var $ _ perPage;
/**
* Total number of pages
* @ Var integer
*/
Var $ _ totalPages;
/**
* Item data. Numerically indexed array...
* @ Var array
*/
Var $ _ itemData;
/**
* Total number of items in the data
* @ Var integer
*/
Var $ _ totalItems;
/**
* Page data generated by this class
* @ Var array
*/
Var $ _ pageData;
/**
* Constructor
*
* Sets up the object and calculates the total number of items.
*
* @ Param $ params An associative array of parameters This can contain:
* CurrentPage Current Page number (optional)
* PerPage Items per page (optional)
* ItemData Data to page
*/
Function pager ($ params = array ())
{
Global $ HTTP_GET_VARS;
/**
* Returns pageID for given offset
*
* @ Param $ index Offset to get pageID
* @ Return int PageID for given offset
*/
Function getPageIdByOffset ($ index)
{
If (! Isset ($ this-> _ pageData )){
$ This-> _ generatePageData ();
}
/**
* Returns offsets for given pageID. Eg, if you
* Pass it pageID one and your perPage limit is 10
* It will return you 1 and 10. PageID of 2 wowould
* Give you 11 and 20.
*
* @ Params pageID PageID to get offsets
* @ Return array First and last offsets
*/
Function getOffsetByPageId ($ pageid = null)
{
$ Pageid = isset ($ pageid )? $ Pageid: $ this-> _ currentPage;
If (! Isset ($ this-> _ pageData )){
$ This-> _ generatePageData ();
}
/**
* Returns number of pages
*
* @ Return int Number of pages
*/
Function numPages ()
{
Return $ this-> _ totalPages;
}
/**
* Returns whether current page is first page
*
* @ Return bool First page or not
*/
Function isFirstPage ()
{
Return ($ this-> _ currentPage = 1 );
}
/**
* Returns whether current page is last page
*
* @ Return bool Last page or not
*/
Function isLastPage ()
{
Return ($ this-> _ currentPage = $ this-> _ totalPages );
}
/**
* Returns whether last page is complete
*
* @ Return bool Last age complete or not
*/
Function isLastPageComplete ()
{
Return! ($ This-> _ totalItems % $ this-> _ perPage );
}
/**
* Returns back link
*
* @ Param $ url URL to use in the link
* @ Param $ link HTML to use as the link
* @ Return string The link
*/
Function _ getBackLink ($ url, $ link = '<back ')
{
// Back link
If ($ this-> _ currentPage> 1 ){
$ Back = '_ currentPage-1).' "> '. $ link .'';
} Else {
$ Back = ';
}
Return $ back;
}
/**
* Returns pages link
*
* @ Param $ url URL to use in the link
* @ Return string Links
*/
Function _ getPageLinks ($ url)
{
// Create the range
$ Params ['itemdata'] = range (1, max (1, $ this-> _ totalPages ));
$ Pager = & new Pager ($ params );
$ Links = $ pager-> getPageData ($ pager-> getPageIdByOffset ($ this-> _ currentPage ));
For ($ I = 0; $ I If ($ links [$ I]! = $ This-> _ currentPage ){
$ Links [$ I] = '_ getLinksUrl (). $ links [$ I].' "> '. $ links [$ I].'';
}
}
Return implode ('', $ links );
}
/**
* Returns next link
*
* @ Param $ url URL to use in the link
* @ Param $ link HTML to use as the link
* @ Return string The link
*/
Function _ getNextLink ($ url, $ link = 'next> ')
{
If ($ this-> _ currentPage <$ this-> _ totalPages ){
$ Next = '_ currentPage + 1).' "> '. $ link .'';
} Else {
$ Next = ';
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.