]>
src.bluestatic.org Git - isso.git/blob - pagination.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
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);
144 // ###################################################################
150 * @param string Field name
151 * @param mixed Value of the field
153 function set($name, $value)
155 $this->registry
->do_set($name, $value, 'pagination');
158 // ###################################################################
164 * @param string Field name
166 * @return mixed Value of the field
168 function get($fieldname)
170 return $this->registry
->do_get($fieldname, 'pagination');
174 * Takes the variables and splits up the pages
178 function split_pages()
180 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
181 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
182 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
184 if ($this->page
<= 0)
189 if ($this->perpage
<= 0)
191 $this->perpage
= $this->defaultperpage
;
193 if ($this->perpage
> $this->maxperpage
['maxpp'])
195 $this->perpage
= $this->maxperpage
['maxpp'];
198 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
200 $this->pagecount
= ceil($this->total
/ $this->perpage
);
204 * Returns the lower limit of the pages
208 * @param integer Page number
210 * @return integer Lower result limit
212 function fetch_limit($page = null)
219 $limit = $page * $this->perpage
;
226 else if ($page > $this->pagecount
)
228 $page = $this->pagecount
- 1;
229 $limit = $this->total
;
236 else if ($limit > $this->total
)
247 * Constructs the page navigator
251 * @param string Base link path
253 * @return string Generated HTML page navigator
255 function construct_page_nav($baselink)
260 if (strpos($baselink, '?') === false)
264 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
266 $baselink .= '&';
269 // first page number in page nav
270 $startpage = $this->page
- $this->pagelinks
;
276 // last page number in page nav
277 $endpage = $this->page +
$this->pagelinks
;
278 if ($endpage > $this->pagecount
)
280 $endpage = $this->pagecount
;
283 // prev page in page nav
284 $prevpage = $this->page
- 1;
290 // next page in page nav
291 $nextpage = $this->page +
1;
292 if ($nextpage > $this->pagecount
)
294 $nextpage = $this->pagecount
;
297 // show the prev page
298 $show['prev'] = true;
299 if ($this->page
== $startpage)
301 $show['prev'] = false;
304 // show the next page
305 $show['next'] = true;
306 if ($this->page
== $endpage)
308 $show['next'] = false;
311 // show the first page
312 $show['first'] = false;
315 $show['first'] = true;
318 // show the last page
319 $show['last'] = false;
320 if ($endpage < $this->pagecount
)
322 $show['last'] = true;
325 // construct the page bits
326 for ($i = $startpage; $i <= $endpage; $i++
)
328 if ($i == $this->page
)
337 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
340 $pagebits = implode(",\n", $pagebits);
342 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
348 /*=====================================================================*\
349 || ###################################################################
352 || ###################################################################
353 \*=====================================================================*/