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 function __construct(&$registry)
122 $this->registry
=& $registry;
125 // ###################################################################
131 * @param string Field name
132 * @param mixed Value of the field
134 function set($name, $value)
136 $this->registry
->do_set($name, $value, 'pagination');
139 // ###################################################################
145 * @param string Field name
147 * @return mixed Value of the field
149 function get($fieldname)
151 return $this->registry
->do_get($fieldname, 'pagination');
155 * Takes the variables and splits up the pages
159 function split_pages()
161 $this->page
= $this->registry
->input_clean($this->pagevar
, TYPE_INT
);
162 $this->perpage
= $this->registry
->input_clean($this->perpagevar
, TYPE_INT
);
163 $this->pagelinks
= $this->registry
->input_clean($this->pagelinkx
, TYPE_INT
);
165 if ($this->page
<= 0)
170 if ($this->perpage
<= 0)
172 $this->perpage
= $this->defaultperpage
;
174 if ($this->perpage
> $this->maxperpage
['maxpp'])
176 $this->perpage
= $this->maxperpage
['maxpp'];
179 $this->perpage
= $this->registry
->clean($this->perpage
, TYPE_INT
);
181 $this->pagecount
= ceil($this->total
/ $this->perpage
);
185 * Returns the lower limit of the pages
189 * @param integer Page number
191 * @return integer Lower result limit
193 function fetch_limit($page = null
)
200 $limit = $page * $this->perpage
;
207 else if ($page > $this->pagecount
)
209 $page = $this->pagecount
- 1;
210 $limit = $this->total
;
217 else if ($limit > $this->total
)
228 * Constructs the page navigator
232 * @param string Base link path
234 * @return string Generated HTML page navigator
236 function construct_page_nav($baselink)
241 if (strpos($baselink, '?') === false
)
245 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
247 $baselink .= '&';
250 // first page number in page nav
251 $startpage = $this->page
- $this->pagelinks
;
257 // last page number in page nav
258 $endpage = $this->page +
$this->pagelinks
;
259 if ($endpage > $this->pagecount
)
261 $endpage = $this->pagecount
;
264 // prev page in page nav
265 $prevpage = $this->page
- 1;
271 // next page in page nav
272 $nextpage = $this->page +
1;
273 if ($nextpage > $this->pagecount
)
275 $nextpage = $this->pagecount
;
278 // show the prev page
279 $show['prev'] = true
;
280 if ($this->page
== $startpage)
282 $show['prev'] = false
;
285 // show the next page
286 $show['next'] = true
;
287 if ($this->page
== $endpage)
289 $show['next'] = false
;
292 // show the first page
293 $show['first'] = false
;
296 $show['first'] = true
;
299 // show the last page
300 $show['last'] = false
;
301 if ($endpage < $this->pagecount
)
303 $show['last'] = true
;
306 // construct the page bits
307 for ($i = $startpage; $i <= $endpage; $i++
)
309 if ($i == $this->page
)
318 eval('$pagebits[] .= "' . $this->registry
->modules
['template']->fetch('pagenav_bit') . '";');
321 $pagebits = implode(",\n", $pagebits);
323 eval('$pagenav = "' . $this->registry
->modules
['template']->fetch('pagenav') . '";');
329 /*=====================================================================*\
330 || ###################################################################
333 || ###################################################################
334 \*=====================================================================*/