]>
src.bluestatic.org Git - isso.git/blob - pagination.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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
41 * @author Iris Studios, Inc.
42 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
64 * Number of page links
71 * Total number of results
78 * Total number of pages
85 * Name of page variable
92 * Name of per-page variable
99 * Maximum number of per-page results
103 var $maxperpage = 100;
106 * Default number of per-page results
110 var $defaultperpage = 20;
118 'total' => array(REQ_YES
, null, false),
119 'pagelinks' => array(REQ_YES
, null, false),
120 'pagevar' => array(REQ_YES
, null, false),
121 'perpagevar' => array(REQ_YES
, null, false),
122 'maxperpage' => array(REQ_YES
, null, true),
123 'defaultperpage' => array(REQ_YES
, null, true)
126 // ###################################################################
130 function __construct(&$registry)
132 $this->registry
=& $registry;
135 // ###################################################################
137 * (PHP 4) Constructor
139 function Pagination(&$registry)
141 $this->__construct($registry);
145 * Constructor: sanitize incoming variables
147 * @param string Name of page number variable
148 * @param string Name of per-page variable
150 function Pagination($page, $perpage)
156 // ###################################################################
162 * @param string Field name
163 * @param mixed Value of the field
165 function set($name, $value)
167 $this->registry
->do_set($name, $value, 'pagination');
170 // ###################################################################
176 * @param string Field name
178 * @return mixed Value of the field
180 function get($fieldname)
182 return $this->registry
->do_get($fieldname, 'pagination');
186 * Takes the variables and splits up the pages
190 function split_pages()
192 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
193 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
194 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
196 if ($this->page
<= 0)
201 if ($this->perpage
<= 0)
203 $this->perpage
= $this->defaultperpage
;
205 if ($this->perpage
> $this->maxperpage
['maxpp'])
207 $this->perpage
= $this->maxperpage
['maxpp'];
210 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
212 $this->pagecount
= ceil($this->total
/ $this->perpage
);
216 * Returns the lower limit of the pages
220 * @param integer Page number
222 * @return integer Lower result limit
224 function fetch_limit($page = null)
231 $limit = $page * $this->perpage
;
238 else if ($page > $this->pagecount
)
240 $page = $this->pagecount
- 1;
241 $limit = $this->total
;
248 else if ($limit > $this->total
)
259 * Constructs the page navigator
263 * @param string Base link path
265 * @return string Generated HTML page navigator
267 function construct_page_nav($baselink)
272 if (strpos($baselink, '?') === false)
276 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
278 $baselink .= '&';
281 // first page number in page nav
282 $startpage = $this->page
- $this->pagelinks
;
288 // last page number in page nav
289 $endpage = $this->page +
$this->pagelinks
;
290 if ($endpage > $this->pagecount
)
292 $endpage = $this->pagecount
;
295 // prev page in page nav
296 $prevpage = $this->page
- 1;
302 // next page in page nav
303 $nextpage = $this->page +
1;
304 if ($nextpage > $this->pagecount
)
306 $nextpage = $this->pagecount
;
309 // show the prev page
310 $show['prev'] = true;
311 if ($this->page
== $startpage)
313 $show['prev'] = false;
316 // show the next page
317 $show['next'] = true;
318 if ($this->page
== $endpage)
320 $show['next'] = false;
323 // show the first page
324 $show['first'] = false;
327 $show['first'] = true;
330 // show the last page
331 $show['last'] = false;
332 if ($endpage < $this->pagecount
)
334 $show['last'] = true;
337 // construct the page bits
338 for ($i = $startpage; $i <= $endpage; $i++
)
340 if ($i == $this->page
)
349 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
352 $pagebits = implode(",\n", $pagebits);
354 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
360 /*=====================================================================*\
361 || ###################################################################
364 || ###################################################################
365 \*=====================================================================*/