ui = $ui; // parent::__construct( $items ); $this->to = $to; $this->_totalCount = $totalCount; $this->_perPage = $perPage; $this->_currentPage = $currentPage; $parts = array(); $disable = array(); if( $this->currentPage() == 1 ){ $disable[] = 'first'; $disable[] = 'previous'; } if( $this->currentPage() == 2 ){ $disable[] = 'first'; } if( $this->currentPage() == $this->numberOfPages() ){ $disable[] = 'next'; $disable[] = 'last'; } if( $this->currentPage() == ($this->numberOfPages() - 1) ){ $disable[] = 'last'; } $parts_config = array( 'first' => array( '<<', array('page' => 1) ), 'previous' => array( '<', array('page' => ($this->currentPage() - 1)) ), 'next' => array( '>', array('page' => ($this->currentPage() + 1)) ), 'last' => array( '>>', array('page' => $this->numberOfPages()) ), ); foreach( $parts_config as $k => $a ){ if( in_array($k, $disable) ){ $parts[$k] = $this->ui->makeBlockInline( $a[0] ) ->tag('border') ->tag('muted') ; } else { $parts[$k] = $this->ui->makeAhref( array($this->to, $a[1]), $a[0] ) // ->tag('border') ->tag('secondary') ; } } $parts['current'] = $this->ui->makeBlockInline( $this->currentPage() . ' / ' . $this->numberOfPages() ) ->tag('border') ->tag('secondary') ; parent::__construct( $parts ); } public function render() { $out = $this->ui->makeListInline() ->gutter(1) ; $parts = $this->getChildren(); $show_order = array('first', 'previous', 'current', 'next', 'last'); foreach( $show_order as $k ){ if( ! isset($parts[$k]) ){ continue; } $out->add( $parts[$k] ); } return $out; } public function numberOfPages() { if( ($this->_perPage == 0) || ($this->_totalCount == 0) ){ $return = 1; } else { $return = ceil( $this->_totalCount / $this->_perPage ); } return $return; } public function currentPage() { return $this->_currentPage; } }