Source for file TPageNavigation.php
Documentation is available at TPageNavigation.php
namespace
Adianti \
Widget \
Datagrid ;
use
Adianti \
Widget \
Container \
TTable ;
* Page Navigation provides navigation for a datagrid
* @author Pablo Dall'Oglio
* @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
* @license http://www.adianti.com.br/framework-license
private function getResume ( )
* Set the Amount of displayed records
* @param $limit An integer
$this -> limit = (int)
$limit ;
* Returns the limit of records
* Define the PageNavigation's width
* @param $width PageNavigation's width
* Define the total count of records
* @param $count An integer (the total count of records)
$this -> count = (int)
$count ;
* Return the total count of records
* Define the current page
* @param $page An integer (the current page)
$this -> page = (int)
$page ;
* Returns the current page
* @param $page An integer (the first page)
$this -> first_page = (int)
$first_page ;
* @param $order A string containint the column name
* @param $direction asc, desc
$this -> direction =
$direction ;
* Set the page navigation properties
* @param $properties array of properties
$order = isset
( $properties [ 'order' ] ) ?
addslashes ( $properties [ 'order' ] ) :
'' ;
$page = isset
( $properties [ 'page' ] ) ?
$properties [ 'page' ] :
1 ;
$direction =
( isset
( $properties [ 'direction' ] ) AND in_array ( $properties [ 'direction' ] , array ( 'asc' , 'desc' ))) ?
$properties [ 'direction' ] :
NULL ;
$first_page = isset
( $properties [ 'first_page' ] ) ?
$properties [ 'first_page' ] :
1 ;
* Define the PageNavigation action
* @param $action TAction object (fired when the user navigates)
* Show the PageNavigation widget
if ( ! $this -> action instanceof
TAction )
$total -> { 'class' } =
'tpagenavigation_resume' ;
$total -> add ( $this -> getResume ( )) ;
$first_page = isset
( $this -> first_page ) ?
$this -> first_page :
1 ;
$page_size = isset
( $this -> limit ) ?
$this -> limit :
10 ;
$registros =
$this -> count ;
$pages = (int)
( $registros /
$page_size ) -
$first_page +
1 ;
$resto =
$registros %
$page_size ;
$pages +=
$resto >
0 ?
1 :
0 ;
$last_page =
min ( $pages , $max ) ;
$nav -> { 'class' } =
'tpagenavigation' ;
$nav -> { 'align' } =
'center' ;
$ul -> { 'class' } =
'pagination' ;
$ul -> { 'style' } =
'display:inline-flex;' ;
$link -> { 'aria-label' } =
'Previous' ;
$this -> action -> setParameter ( 'offset' , 0 ) ;
$this -> action -> setParameter ( 'limit' , $page_size ) ;
$this -> action -> setParameter ( 'direction' , $this -> direction ) ;
$this -> action -> setParameter ( 'page' , 1 ) ;
$this -> action -> setParameter ( 'first_page' , 1 ) ;
$this -> action -> setParameter ( 'order' , $this -> order ) ;
$link -> { 'class' } =
"page-link" ;
$link -> { 'href' } =
$this -> action -> serialize ( ) ;
$link -> { 'generator' } =
'adianti' ;
$span -> add ( TElement :: tag ( 'span' , '' , [ 'class' =>
'fa fa-angle-double-left' ] )) ;
$link -> { 'aria-label' } =
'Previous' ;
$this -> action -> setParameter ( 'offset' , ( $first_page -
$max -
1 ) *
$page_size ) ;
$this -> action -> setParameter ( 'limit' , $page_size ) ;
$this -> action -> setParameter ( 'direction' , $this -> direction ) ;
$this -> action -> setParameter ( 'page' , $first_page -
$max ) ;
$this -> action -> setParameter ( 'first_page' , $first_page -
$max ) ;
$this -> action -> setParameter ( 'order' , $this -> order ) ;
$link -> { 'class' } =
"page-link" ;
$link -> { 'href' } =
$this -> action -> serialize ( ) ;
$link -> { 'generator' } =
'adianti' ;
$span -> add ( TElement :: tag ( 'span' , '' , [ 'class' =>
'fa fa-angle-left' ] )) ; //$span->add('«');
for ( $n =
$first_page ; $n <=
$last_page +
$first_page -
1 ; $n ++
)
$offset =
( $n -
1 ) *
$page_size ;
$this -> action -> setParameter ( 'offset' , $offset ) ;
$this -> action -> setParameter ( 'limit' , $page_size ) ;
$this -> action -> setParameter ( 'direction' , $this -> direction ) ;
$this -> action -> setParameter ( 'page' , $n ) ;
$this -> action -> setParameter ( 'first_page' , $first_page ) ;
$this -> action -> setParameter ( 'order' , $this -> order ) ;
$link -> { 'href' } =
$this -> action -> serialize ( ) ;
$link -> { 'generator' } =
'adianti' ;
$link -> { 'class' } =
'page-link' ;
$item -> { 'class' } =
'active page-item' ;
// inactive pages/placeholders
for ( $z =
$n ; $z <=
10 ; $z ++
)
$item -> { 'class' } =
'off page-item' ;
$link -> { 'class' } =
'page-link' ;
$link -> { 'aria-label' } =
"Next" ;
$this -> action -> setParameter ( 'offset' , ( $n -
1 ) *
$page_size ) ;
$this -> action -> setParameter ( 'limit' , $page_size ) ;
$this -> action -> setParameter ( 'direction' , $this -> direction ) ;
$this -> action -> setParameter ( 'page' , $n ) ;
$this -> action -> setParameter ( 'first_page' , $n ) ;
$this -> action -> setParameter ( 'order' , $this -> order ) ;
$link -> { 'class' } =
"page-link" ;
$link -> { 'href' } =
$this -> action -> serialize ( ) ;
$link -> { 'generator' } =
'adianti' ;
$span -> add ( TElement :: tag ( 'span' , '' , [ 'class' =>
'fa fa-angle-right' ] )) ; //$span->add('»');
$link -> { 'aria-label' } =
"Next" ;
$this -> action -> setParameter ( 'offset' , ceil ( $registros /
$page_size ) *
$page_size -
$page_size ) ;
$this -> action -> setParameter ( 'limit' , $page_size ) ;
$this -> action -> setParameter ( 'direction' , $this -> direction ) ;
$this -> action -> setParameter ( 'page' , ceil ( $registros /
$page_size )) ;
$this -> action -> setParameter ( 'first_page' , (int)
( $registros /
( $page_size *
10 )) *
10 +
1 ) ;
$this -> action -> setParameter ( 'order' , $this -> order ) ;
$link -> { 'class' } =
"page-link" ;
$link -> { 'href' } =
$this -> action -> serialize ( ) ;
$link -> { 'generator' } =
'adianti' ;
$span -> add ( TElement :: tag ( 'span' , '' , [ 'class' =>
'fa fa-angle-double-right' ] )) ;