]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/3rdparty/paginator.php
5 * @author David Carr - dave@daveismyname.com - http://www.daveismyname.com
7 * @date October 20, 2013
12 * set the number of items per page.
19 * set get parameter for fetching the page number
26 * sets the page number.
33 * set the limit for the data source
40 * set the total number of records/items.
44 private $_totalRows = 0;
51 * pass values when class is istantiated
53 * @param numeric $_perPage sets the number of iteems per page
54 * @param numeric $_instance sets the instance for the GET parameter
56 public function __construct($perPage,$instance){
57 $this->_instance
= $instance;
58 $this->_perPage
= $perPage;
59 $this->set_instance();
65 * creates the starting point for limiting the dataset
68 private function get_start(){
69 return ($this->_page
* $this->_perPage
) - $this->_perPage
;
75 * sets the instance parameter, if numeric value is 0 then set to 1
79 private function set_instance(){
80 $this->_page
= (int) (!isset($_GET[$this->_instance
]) ? 1 : $_GET[$this->_instance
]);
81 $this->_page
= ($this->_page
== 0 ? 1 : $this->_page
);
87 * collect a numberic value and assigns it to the totalRows
91 public function set_total($_totalRows){
92 $this->_totalRows
= $_totalRows;
98 * returns the limit for the data source, calling the get_start method and passing in the number of items perp page
102 public function get_limit(){
103 if (STORAGE
== 'postgres') {
104 return "LIMIT ".$this->_perPage
." OFFSET ".$this->get_start();
106 return "LIMIT ".$this->get_start().",".$this->_perPage
;
113 * create the html links for navigating through the dataset
115 * @var sting $path optionally set the path for the link
116 * @var sting $ext optionally pass in extra parameters to the GET
117 * @return string returns the html menu
119 public function page_links($path='?',$ext=null)
122 $prev = $this->_page
- 1;
123 $next = $this->_page +
1;
124 $lastpage = ceil($this->_totalRows
/$this->_perPage
);
125 $lpm1 = $lastpage - 1;
130 $pagination .= "<div class='pagination'>";
131 if ($this->_page
> 1)
132 $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous
</a
>";
134 $pagination.= "<span
class='disabled'>« previous
</span
>";
136 if ($lastpage < 7 + ($adjacents * 2))
138 for ($counter = 1; $counter <= $lastpage; $counter++)
140 if ($counter == $this->_page)
141 $pagination.= "<span
class='current'>$counter</span
>";
143 $pagination.= "<a href
='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
146 elseif($lastpage > 5 + ($adjacents * 2))
148 if($this->_page < 1 + ($adjacents * 2))
150 for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
152 if ($counter == $this->_page)
153 $pagination.= "<span class='current
'>$counter</span>";
155 $pagination.= "<a href='".$path."$this->_instance
=$counter"."$ext'>$counter</a>";
158 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a
>";
159 $pagination.= "<a href
='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
161 elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2))
163 $pagination.= "<a href='".$path."$this->_instance
=1"."$ext'>1</a
>";
164 $pagination.= "<a href
='".$path."$this->_instance=2"."$ext'>2</a>";
166 for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++)
168 if ($counter == $this->_page)
169 $pagination.= "<span class='current
'>$counter</span>";
171 $pagination.= "<a href='".$path."$this->_instance
=$counter"."$ext'>$counter</a>";
174 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a
>";
175 $pagination.= "<a href
='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
179 $pagination.= "<a href='".$path."$this->_instance
=1"."$ext'>1</a
>";
180 $pagination.= "<a href
='".$path."$this->_instance=2"."$ext'>2</a>";
182 for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
184 if ($counter == $this->_page)
185 $pagination.= "<span class='current
'>$counter</span>";
187 $pagination.= "<a href='".$path."$this->_instance
=$counter"."$ext'>$counter</a>";
192 if ($this->_page
< $counter - 1)
193 $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »
</a
>";
195 $pagination.= "<span
class='disabled'>next »
</span
>";
196 $pagination.= "</div
>\n";