]>
src.bluestatic.org Git - isso.git/blob - pagination.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
32 * On many pages, it is necessary to limit the amount of records to display.
33 * Using this class, you can set the maximum and minimum values to display,
34 * and then the input variables for page number and perpage. This will
35 * then create a page navigator and manage the SQL LIMIT statements.
38 * pagenav_bit - The individual page numbers in the page navigator
39 * pagenav - The entirity of the page navigtaor
42 * @copyright Copyright ©2002 - [#]year[#], Blue Static
62 * Number of page links
68 * Total number of results
74 * Total number of pages
80 * Name of page variable
86 * Name of per-page variable
92 * Maximum number of per-page results
95 private $maxperpage = 100;
98 * Default number of per-page results
101 private $defaultperpage = 20;
107 private $fields = array(
108 'total' => array(REQ_YES
, null, false),
109 'pagelinks' => array(REQ_YES
, null, false),
110 'pagevar' => array(REQ_YES
, null, false),
111 'perpagevar' => array(REQ_YES
, null, false),
112 'maxperpage' => array(REQ_YES
, null, true),
113 'defaultperpage' => array(REQ_YES
, null, true)
116 // ###################################################################
120 public function __construct(&$registry)
122 $this->registry
=& $registry;
125 // ###################################################################
129 * @param string Field name
130 * @param mixed Value of the field
132 public function set($name, $value)
134 $this->registry
->do_set($name, $value, 'pagination');
137 // ###################################################################
141 * @param string Field name
143 * @return mixed Value of the field
145 public function get($fieldname)
147 return $this->registry
->do_get($fieldname, 'pagination');
151 * Takes the variables and splits up the pages
153 public function split_pages()
155 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
156 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
157 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
159 if ($this->page
<= 0)
164 if ($this->perpage
<= 0)
166 $this->perpage
= $this->defaultperpage
;
168 if ($this->perpage
> $this->maxperpage
['maxpp'])
170 $this->perpage
= $this->maxperpage
['maxpp'];
173 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
175 $this->pagecount
= ceil($this->total
/ $this->perpage
);
179 * Returns the lower limit of the pages
181 * @param integer Page number
183 * @return integer Lower result limit
185 public function fetch_limit($page = null)
192 $limit = $page * $this->perpage
;
199 else if ($page > $this->pagecount
)
201 $page = $this->pagecount
- 1;
202 $limit = $this->total
;
209 else if ($limit > $this->total
)
220 * Constructs the page navigator
222 * @param string Base link path
224 * @return string Generated HTML page navigator
226 public function construct_page_nav($baselink)
231 if (strpos($baselink, '?') === false)
235 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
237 $baselink .= '&';
240 // first page number in page nav
241 $startpage = $this->page
- $this->pagelinks
;
247 // last page number in page nav
248 $endpage = $this->page +
$this->pagelinks
;
249 if ($endpage > $this->pagecount
)
251 $endpage = $this->pagecount
;
254 // prev page in page nav
255 $prevpage = $this->page
- 1;
261 // next page in page nav
262 $nextpage = $this->page +
1;
263 if ($nextpage > $this->pagecount
)
265 $nextpage = $this->pagecount
;
268 // show the prev page
269 $show['prev'] = true;
270 if ($this->page
== $startpage)
272 $show['prev'] = false;
275 // show the next page
276 $show['next'] = true;
277 if ($this->page
== $endpage)
279 $show['next'] = false;
282 // show the first page
283 $show['first'] = false;
286 $show['first'] = true;
289 // show the last page
290 $show['last'] = false;
291 if ($endpage < $this->pagecount
)
293 $show['last'] = true;
296 // construct the page bits
297 for ($i = $startpage; $i <= $endpage; $i++
)
299 if ($i == $this->page
)
308 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
311 $pagebits = implode(",\n", $pagebits);
313 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
319 /*=====================================================================*\
320 || ###################################################################
323 || ###################################################################
324 \*=====================================================================*/