|
Class PageView {
/** Page number **/
Public $ pageNo = 1;
/** Page size **/
Public $ pageSize = 20;
/** Total number of pages **/
Public $ pageCount = 0;
/** Total number of records **/
Public $ totalNum = 0;
/** Offset, starting line of the current page **/
Public $ offSet = 0;
/** Data per page **/
Public $ pageData = array ();
/** Whether the previous page exists **/
Public $ hasPrePage = true;
/** Whether the next page exists **/
Public $ hasNextPage = true;
Public $ pageNoList = array ();
Public $ jsFunction = 'jsfunction ';
/**
*
* @ Param unknown_type $ count total number of rows
* @ Param unknown_type $ size page size
* @ Param unknown_type $ string
*/
Public function _ construct ($ count = 0, $ size = 20, $ pageNo = 1, $ pageData = array (), $ jsFunction = 'jsfunction '){
$ This-> totalNum = $ count; // total number of records
$ This-> pageSize = $ size; // size of each page
$ This-> pageNo = $ pageNo;
// Calculate the total number of pages
$ This-> pageCount = ceil ($ this-> totalNum/$ this-> pageSize );
$ This-> pageCount = ($ this-> pageCount <= 0 )? 1: $ this-> pageCount;
// Check pageNo
$ This-> pageNo = 0? 1: $ this-> pageNo;
$ This-> pageNo = $ this-> pageNo> $ this-> pageCount? $ This-> pageCount: $ this-> pageNo;
// Calculate the offset
$ This-> offset = ($ this-> pageNo-1) * $ this-> pageSize;
// Check whether the previous page is displayed
$ This-> hasPrePage = $ this-> pageNo = 1? False: true;
$ This-> hasNextPage = $ this-> pageNo >=$ this-> pageCount? False: true;
$ This-> pageData = $ pageData;
$ This-> jsFunction = $ jsFunction;
}
/**
* Paging algorithm
* @ Return
*/
Private function generatePageList (){
$ PageList = array ();
If ($ this-> pageCount <= 9 ){
For ($ I = 0; $ I <$ this-> pageCount; $ I ++ ){
Array_push ($ pageList, $ I + 1 );
}
} Else {
If ($ this-> pageNo <= 4 ){
For ($ I = 0; $ I <5; $ I ++ ){
Array_push ($ pageList, $ I + 1 );
}
Array_push ($ pageList,-1 );
Array_push ($ pageList, $ this-> pageCount );
} Else if ($ this-> pageNo> $ this-> pageCount-4 ){
Array_push ($ pageList, 1 );
Array_push ($ pageList,-1 );
For ($ I = 5; $ I> 0; $ I --){
Array_push ($ pageList, $ this-> pageCount-$ I + 1 );
}
} Else if ($ this-> pageNo> 4 & $ this-> pageNo <= $ this-> pageCount-4 ){
Array_push ($ pageList, 1 );
Array_push ($ pageList,-1 );
Array_push ($ pageList, $ this-> pageNo-2 );
Array_push ($ pageList, $ this-> pageNo-1 );
Array_push ($ pageList, $ this-> pageNo );
Array_push ($ pageList, $ this-> pageNo + 1 );
Array_push ($ pageList, $ this-> pageNo + 2 );
Array_push ($ pageList,-1 );
Array_push ($ pageList, $ this-> pageCount );
}
}
Return $ pageList;
}
/***
* Create a paging Control
* @ Param
* @ Return String
*/
Public function echoPageAsDiv (){
$ PageList = $ this-> generatePageList ();
$ PageString ="
";
If (! Empty ($ pageList )){
If ($ this-> pageCount> 1 ){
If ($ this-> hasPrePage ){
$ PageString = $ pageString. "jsFunction." (". ($ this-> pageNo-1).") "> previous page ";
}
Foreach ($ pageList as $ k => $ p ){
If ($ this-> pageNo = $ p ){
$ PageString = $ pageString. "". $ this-> pageNo ."";
Continue;
}
If ($ p =-1 ){
$ PageString = $ pageString ."...";
Continue;
}
$ PageString = $ pageString. "jsFunction." (". $ p.") ">". $ p ."";
}
If ($ this-> hasNextPage ){
$ PageString = $ pageString. "jsFunction." (". ($ this-> pageNo + 1).") "> next page ";
}
}
}
$ PageString = $ pageString .("
");
Return $ pageString;
}
}
?> |