aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/paginator.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/paginator.php')
-rw-r--r--inc/3rdparty/paginator.php354
1 files changed, 179 insertions, 175 deletions
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 @@
9class Paginator{ 9class Paginator{
10 10
11 /** 11 /**
12 * set the number of items per page. 12 * set the number of items per page.
13 * 13 *
14 * @var numeric 14 * @var numeric
15 */ 15 */
16 private $_perPage; 16 private $_perPage;
17 17
18 /** 18 /**
19 * set get parameter for fetching the page number 19 * set get parameter for fetching the page number
20 * 20 *
21 * @var string 21 * @var string
22 */ 22 */
23 private $_instance; 23 private $_instance;
24 24
25 /** 25 /**
26 * sets the page number. 26 * sets the page number.
27 * 27 *
28 * @var numeric 28 * @var numeric
29 */ 29 */
30 private $_page; 30 private $_page;
31 31
32 /** 32 /**
33 * set the limit for the data source 33 * set the limit for the data source
34 * 34 *
35 * @var string 35 * @var string
36 */ 36 */
37 private $_limit; 37 private $_limit;
38 38
39 /** 39 /**
40 * set the total number of records/items. 40 * set the total number of records/items.
41 * 41 *
42 * @var numeric 42 * @var numeric
43 */ 43 */
44 private $_totalRows = 0; 44 private $_totalRows = 0;
45 45
46 46
47 47
48 /** 48 /**
49 * __construct 49 * __construct
50 * 50 *
51 * pass values when class is istantiated 51 * pass values when class is istantiated
52 * 52 *
53 * @param numeric $_perPage sets the number of iteems per page 53 * @param numeric $_perPage sets the number of iteems per page
54 * @param numeric $_instance sets the instance for the GET parameter 54 * @param numeric $_instance sets the instance for the GET parameter
55 */ 55 */
56 public function __construct($perPage,$instance){ 56 public function __construct($perPage,$instance){
57 $this->_instance = $instance; 57 $this->_instance = $instance;
58 $this->_perPage = $perPage; 58 $this->_perPage = $perPage;
59 $this->set_instance(); 59 $this->set_instance();
60 } 60 }
61 61
62 /** 62 /**
63 * get_start 63 * get_start
64 * 64 *
65 * creates the starting point for limiting the dataset 65 * creates the starting point for limiting the dataset
66 * @return numeric 66 * @return numeric
67 */ 67 */
68 private function get_start(){ 68 private function get_start(){
69 return ($this->_page * $this->_perPage) - $this->_perPage; 69 return ($this->_page * $this->_perPage) - $this->_perPage;
70 } 70 }
71 71
72 /** 72 /**
73 * set_instance 73 * set_instance
74 * 74 *
75 * sets the instance parameter, if numeric value is 0 then set to 1 75 * sets the instance parameter, if numeric value is 0 then set to 1
76 * 76 *
77 * @var numeric 77 * @var numeric
78 */ 78 */
79 private function set_instance(){ 79 private function set_instance(){
80 $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]); 80 $this->_page = (int) (!isset($_GET[$this->_instance]) ? 1 : $_GET[$this->_instance]);
81 $this->_page = ($this->_page == 0 ? 1 : $this->_page); 81 $this->_page = ($this->_page == 0 ? 1 : $this->_page);
82 } 82 }
83 83
84 /** 84 /**
85 * set_total 85 * set_total
86 * 86 *
87 * collect a numberic value and assigns it to the totalRows 87 * collect a numberic value and assigns it to the totalRows
88 * 88 *
89 * @var numeric 89 * @var numeric
90 */ 90 */
91 public function set_total($_totalRows){ 91 public function set_total($_totalRows){
92 $this->_totalRows = $_totalRows; 92 $this->_totalRows = $_totalRows;
93 } 93 }
94 94
95 /** 95 /**
96 * get_limit 96 * get_limit
97 * 97 *
98 * returns the limit for the data source, calling the get_start method and passing in the number of items perp page 98 * returns the limit for the data source, calling the get_start method and passing in the number of items perp page
99 * 99 *
100 * @return string 100 * @return string
101 */ 101 */
102 public function get_limit(){ 102 public function get_limit(){
103 return "LIMIT ".$this->get_start().",$this->_perPage"; 103 if (STORAGE == 'postgres') {
104 return "LIMIT ".$this->_perPage." OFFSET ".$this->get_start();
105 } else {
106 return "LIMIT ".$this->get_start().",".$this->_perPage;
104 } 107 }
108 }
105 109
106 /** 110 /**
107 * page_links 111 * page_links
@@ -112,87 +116,87 @@ class Paginator{
112 * @var sting $ext optionally pass in extra parameters to the GET 116 * @var sting $ext optionally pass in extra parameters to the GET
113 * @return string returns the html menu 117 * @return string returns the html menu
114 */ 118 */
115 public function page_links($path='?',$ext=null) 119 public function page_links($path='?',$ext=null)
116 { 120 {
117 $adjacents = "2"; 121 $adjacents = "2";
118 $prev = $this->_page - 1; 122 $prev = $this->_page - 1;
119 $next = $this->_page + 1; 123 $next = $this->_page + 1;
120 $lastpage = ceil($this->_totalRows/$this->_perPage); 124 $lastpage = ceil($this->_totalRows/$this->_perPage);
121 $lpm1 = $lastpage - 1; 125 $lpm1 = $lastpage - 1;
122 126
123 $pagination = ""; 127 $pagination = "";
124 if($lastpage > 1) 128 if($lastpage > 1)
125 { 129 {
126 $pagination .= "<div class='pagination'>"; 130 $pagination .= "<div class='pagination'>";
127 if ($this->_page > 1) 131 if ($this->_page > 1)
128 $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>"; 132 $pagination.= "<a href='".$path."$this->_instance=$prev"."$ext'>« previous</a>";
129 else 133 else
130 $pagination.= "<span class='disabled'>« previous</span>"; 134 $pagination.= "<span class='disabled'>« previous</span>";
131 135
132 if ($lastpage < 7 + ($adjacents * 2)) 136 if ($lastpage < 7 + ($adjacents * 2))
133 { 137 {
134 for ($counter = 1; $counter <= $lastpage; $counter++) 138 for ($counter = 1; $counter <= $lastpage; $counter++)
135 { 139 {
136 if ($counter == $this->_page) 140 if ($counter == $this->_page)
137 $pagination.= "<span class='current'>$counter</span>"; 141 $pagination.= "<span class='current'>$counter</span>";
138 else 142 else
139 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; 143 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
140 } 144 }
141 } 145 }
142 elseif($lastpage > 5 + ($adjacents * 2)) 146 elseif($lastpage > 5 + ($adjacents * 2))
143 { 147 {
144 if($this->_page < 1 + ($adjacents * 2)) 148 if($this->_page < 1 + ($adjacents * 2))
145 { 149 {
146 for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) 150 for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
147 { 151 {
148 if ($counter == $this->_page) 152 if ($counter == $this->_page)
149 $pagination.= "<span class='current'>$counter</span>"; 153 $pagination.= "<span class='current'>$counter</span>";
150 else 154 else
151 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; 155 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
152 } 156 }
153 $pagination.= "..."; 157 $pagination.= "...";
154 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; 158 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
155 $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; 159 $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
156 } 160 }
157 elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2)) 161 elseif($lastpage - ($adjacents * 2) > $this->_page && $this->_page > ($adjacents * 2))
158 { 162 {
159 $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; 163 $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
160 $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; 164 $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
161 $pagination.= "..."; 165 $pagination.= "...";
162 for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++) 166 for ($counter = $this->_page - $adjacents; $counter <= $this->_page + $adjacents; $counter++)
163 { 167 {
164 if ($counter == $this->_page) 168 if ($counter == $this->_page)
165 $pagination.= "<span class='current'>$counter</span>"; 169 $pagination.= "<span class='current'>$counter</span>";
166 else 170 else
167 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; 171 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
168 } 172 }
169 $pagination.= ".."; 173 $pagination.= "..";
170 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>"; 174 $pagination.= "<a href='".$path."$this->_instance=$lpm1"."$ext'>$lpm1</a>";
171 $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>"; 175 $pagination.= "<a href='".$path."$this->_instance=$lastpage"."$ext'>$lastpage</a>";
172 } 176 }
173 else 177 else
174 { 178 {
175 $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>"; 179 $pagination.= "<a href='".$path."$this->_instance=1"."$ext'>1</a>";
176 $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>"; 180 $pagination.= "<a href='".$path."$this->_instance=2"."$ext'>2</a>";
177 $pagination.= ".."; 181 $pagination.= "..";
178 for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) 182 for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
179 { 183 {
180 if ($counter == $this->_page) 184 if ($counter == $this->_page)
181 $pagination.= "<span class='current'>$counter</span>"; 185 $pagination.= "<span class='current'>$counter</span>";
182 else 186 else
183 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>"; 187 $pagination.= "<a href='".$path."$this->_instance=$counter"."$ext'>$counter</a>";
184 } 188 }
185 } 189 }
186 } 190 }
187 191
188 if ($this->_page < $counter - 1) 192 if ($this->_page < $counter - 1)
189 $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>"; 193 $pagination.= "<a href='".$path."$this->_instance=$next"."$ext'>next »</a>";
190 else 194 else
191 $pagination.= "<span class='disabled'>next »</span>"; 195 $pagination.= "<span class='disabled'>next »</span>";
192 $pagination.= "</div>\n"; 196 $pagination.= "</div>\n";
193 } 197 }
194 198
195 199
196 return $pagination; 200 return $pagination;
197 } 201 }
198} 202}