X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=inc%2F3rdparty%2Fpaginator.php;h=306756c0e565bee474ff382f46d950726fcea2d5;hb=667009727a38890eb651815843c1bc02869a4119;hp=e8801555bbfd16a062a0283531598c832b72e650;hpb=6a361945eaf86a978b82bd6fb3442fe64428d9df;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/3rdparty/paginator.php b/inc/3rdparty/paginator.php index e8801555..306756c0 100644 --- a/inc/3rdparty/paginator.php +++ b/inc/3rdparty/paginator.php @@ -9,99 +9,103 @@ class Paginator{ /** - * set the number of items per page. - * - * @var numeric - */ - private $_perPage; - - /** - * set get parameter for fetching the page number - * - * @var string - */ - private $_instance; - - /** - * sets the page number. - * - * @var numeric - */ - private $_page; - - /** - * set the limit for the data source - * - * @var string - */ - private $_limit; - - /** - * set the total number of records/items. - * - * @var numeric - */ - private $_totalRows = 0; - - - - /** - * __construct - * - * pass values when class is istantiated - * - * @param numeric $_perPage sets the number of iteems per page - * @param numeric $_instance sets the instance for the GET parameter - */ - public function __construct($perPage,$instance){ - $this->_instance = $instance; - $this->_perPage = $perPage; - $this->set_instance(); - } - - /** - * get_start - * - * creates the starting point for limiting the dataset - * @return numeric - */ - private function get_start(){ - return ($this->_page * $this->_perPage) - $this->_perPage; - } - - /** - * set_instance - * - * sets the instance parameter, if numeric value is 0 then set to 1 - * - * @var numeric - */ - private function set_instance(){ - $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); - $this->_page = ($this->_page == 0 ? 1 : $this->_page); - } - - /** - * set_total - * - * collect a numberic value and assigns it to the totalRows - * - * @var numeric - */ - public function set_total($_totalRows){ - $this->_totalRows = $_totalRows; - } - - /** - * get_limit - * - * returns the limit for the data source, calling the get_start method and passing in the number of items perp page - * - * @return string - */ - public function get_limit(){ - return "LIMIT ".$this->get_start().",$this->_perPage"; + * set the number of items per page. + * + * @var numeric + */ + private $_perPage; + + /** + * set get parameter for fetching the page number + * + * @var string + */ + private $_instance; + + /** + * sets the page number. + * + * @var numeric + */ + private $_page; + + /** + * set the limit for the data source + * + * @var string + */ + private $_limit; + + /** + * set the total number of records/items. + * + * @var numeric + */ + private $_totalRows = 0; + + + + /** + * __construct + * + * pass values when class is istantiated + * + * @param numeric $_perPage sets the number of iteems per page + * @param numeric $_instance sets the instance for the GET parameter + */ + public function __construct($perPage,$instance){ + $this->_instance = $instance; + $this->_perPage = $perPage; + $this->set_instance(); + } + + /** + * get_start + * + * creates the starting point for limiting the dataset + * @return numeric + */ + private function get_start(){ + return ($this->_page * $this->_perPage) - $this->_perPage; + } + + /** + * set_instance + * + * sets the instance parameter, if numeric value is 0 then set to 1 + * + * @var numeric + */ + private function set_instance(){ + $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); + $this->_page = ($this->_page == 0 ? 1 : $this->_page); + } + + /** + * set_total + * + * collect a numberic value and assigns it to the totalRows + * + * @var numeric + */ + public function set_total($_totalRows){ + $this->_totalRows = $_totalRows; + } + + /** + * get_limit + * + * returns the limit for the data source, calling the get_start method and passing in the number of items perp page + * + * @return string + */ + public function get_limit(){ + if (STORAGE == 'postgres') { + return "LIMIT ".$this->_perPage." OFFSET ".$this->get_start(); + } else { + return "LIMIT ".$this->get_start().",".$this->_perPage; } + } /** * page_links @@ -112,87 +116,87 @@ class Paginator{ * @var sting $ext optionally pass in extra parameters to the GET * @return string returns the html menu */ - public function page_links($path='?',$ext=null) - { - $adjacents = "2"; - $prev = $this->_page - 1; - $next = $this->_page + 1; - $lastpage = ceil($this->_totalRows/$this->_perPage); - $lpm1 = $lastpage - 1; - - $pagination = ""; - if($lastpage > 1) - { - $pagination .= "\n"; - } - - - return $pagination; - } + public function page_links($path='?',$ext=null) + { + $adjacents = "2"; + $prev = $this->_page - 1; + $next = $this->_page + 1; + $lastpage = ceil($this->_totalRows/$this->_perPage); + $lpm1 = $lastpage - 1; + + $pagination = ""; + if($lastpage > 1) + { + $pagination .= "\n"; + } + + + return $pagination; + } }