]>
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.
37 * @author Iris Studios, Inc.
38 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
60 * Number of page links
67 * Total number of results
74 * Total number of pages
81 * Name of page variable
88 * Name of per-page variable
95 * Maximum number of per-page results
99 var $maxperpage = 100;
102 * Default number of per-page results
106 var $defaultperpage = 20;
114 'total' => array(REQ_YES
, null, false),
115 'pagelinks' => array(REQ_YES
, null, false),
116 'pagevar' => array(REQ_YES
, null, false),
117 'perpagevar' => array(REQ_YES
, null, false),
118 'maxperpage' => array(REQ_YES
, null, true),
119 'defaultperpage' => array(REQ_YES
, null, true)
122 // ###################################################################
126 function __construct(&$registry)
128 $this->registry
=& $registry;
131 // ###################################################################
133 * (PHP 4) Constructor
135 function Pagination(&$registry)
137 $this->__construct($registry);
141 * Constructor: sanitize incoming variables
143 * @param string Name of page number variable
144 * @param string Name of per-page variable
146 function Pagination($page, $perpage)
152 // ###################################################################
158 * @param string Field name
159 * @param mixed Value of the field
161 function set($name, $value)
163 $this->registry
->do_set($name, $value, 'pagination');
166 // ###################################################################
172 * @param string Field name
174 * @return mixed Value of the field
176 function get($fieldname)
178 return $this->registry
->do_get($fieldname, 'pagination');
182 * Takes the variables and splits up the pages
186 function split_pages()
188 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
189 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
190 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
192 if ($this->page
<= 0)
197 if ($this->perpage
<= 0)
199 $this->perpage
= $this->defaultperpage
;
201 if ($this->perpage
> $this->maxperpage
['maxpp'])
203 $this->perpage
= $this->maxperpage
['maxpp'];
206 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
208 $this->pagecount
= ceil($this->total
/ $this->perpage
);
212 * Returns the lower limit of the pages
216 * @param integer Page number
218 * @return integer Lower result limit
220 function fetch_limit($page = null)
227 $limit = $page * $this->perpage
;
234 else if ($page > $this->pagecount
)
236 $page = $this->pagecount
- 1;
237 $limit = $this->total
;
244 else if ($limit > $this->total
)
255 * Constructs the page navigator
259 * @param string Base link path
261 * @return string Generated HTML page navigator
263 function construct_page_nav($baselink)
268 if (strpos($baselink, '?') === false)
272 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
274 $baselink .= '&';
277 // first page number in page nav
278 $startpage = $this->page
- $this->pagelinks
;
284 // last page number in page nav
285 $endpage = $this->page +
$this->pagelinks
;
286 if ($endpage > $this->pagecount
)
288 $endpage = $this->pagecount
;
291 // prev page in page nav
292 $prevpage = $this->page
- 1;
298 // next page in page nav
299 $nextpage = $this->page +
1;
300 if ($nextpage > $this->pagecount
)
302 $nextpage = $this->pagecount
;
305 // show the prev page
306 $show['prev'] = true;
307 if ($this->page
== $startpage)
309 $show['prev'] = false;
312 // show the next page
313 $show['next'] = true;
314 if ($this->page
== $endpage)
316 $show['next'] = false;
319 // show the first page
320 $show['first'] = false;
323 $show['first'] = true;
326 // show the last page
327 $show['last'] = false;
328 if ($endpage < $this->pagecount
)
330 $show['last'] = true;
333 // construct the page bits
334 for ($i = $startpage; $i <= $endpage; $i++
)
336 if ($i == $this->page
)
345 eval('$pagebits[] .= "' . $bugsys->template
->fetch('pagenav_bit') . '";');
348 $pagebits = implode(",\n", $pagebits);
350 eval('$pagenav = "' . $bugsys->template
->fetch('pagenav') . '";');
356 /*=====================================================================*\
357 || ###################################################################
360 || ###################################################################
361 \*=====================================================================*/