]>
src.bluestatic.org Git - bugdar.git/blob - includes/class_pagination.php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
14 * Class that is responsible for paginating data. Takes passed
15 * parameters and creates pagination links.
32 * Number of page links
38 * Total number of results
44 * Total number of pages
56 * Constructor: sanitize incoming variables
58 * @param string Name of page number variable
59 * @param string Name of per-page variable
61 function Pagination($page, $perpage)
65 $this->page
= intval($bugsys->in
["$page"]);
66 $this->perpage = intval($bugsys->in["$perpage"]);
67 $this->pagelinks
= intval($bugsys->options
['pagelinks']);
69 $this->vars
= array('p' => $page, 'pp' => $perpage);
76 if ($this->perpage
<= 0)
78 $this->perpage
= $bugsys->options
['defaultpp'];
80 if ($this->perpage
> $bugsys->options
['maxpp'])
82 $this->perpage
= $bugsys->options
['maxpp'];
87 * Takes the variables and splits up the pages
91 function split_pages()
93 $this->pagecount
= ceil($this->total
/ $this->perpage
);
97 * Returns the lower limit of the pages
101 * @param integer Page number
103 * @return integer Lower result limit
105 function fetch_limit($page = null)
112 $limit = $page * $this->perpage
;
119 else if ($page > $this->pagecount
)
121 $page = $this->pagecount
- 1;
122 $limit = $this->total
;
129 else if ($limit > $this->total
)
140 * Constructs the page navigator
144 * @param string Base link path
146 * @return string Generated HTML page navigator
148 function construct_page_nav($baselink)
153 if (strpos($baselink, '?') === false)
157 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
159 $baselink .= '&';
162 // first page number in page nav
163 $startpage = $this->page
- $this->pagelinks
;
169 // last page number in page nav
170 $endpage = $this->page +
$this->pagelinks
;
171 if ($endpage > $this->pagecount
)
173 $endpage = $this->pagecount
;
176 // prev page in page nav
177 $prevpage = $this->page
- 1;
183 // next page in page nav
184 $nextpage = $this->page +
1;
185 if ($nextpage > $this->pagecount
)
187 $nextpage = $this->pagecount
;
190 // show the prev page
191 $show['prev'] = true;
192 if ($this->page
== $startpage)
194 $show['prev'] = false;
197 // show the next page
198 $show['next'] = true;
199 if ($this->page
== $endpage)
201 $show['next'] = false;
204 // show the first page
205 $show['first'] = false;
208 $show['first'] = true;
211 // show the last page
212 $show['last'] = false;
213 if ($endpage < $this->pagecount
)
215 $show['last'] = true;
218 // construct the page bits
219 for ($i = $startpage; $i <= $endpage; $i++
)
221 if ($i == $this->page
)
229 eval('$pagebits[] .= "' . $bugsys->template
->fetch('pagenav_bit') . '";');
232 $pagebits = implode(",\n", $pagebits);
234 eval('$pagenav = "' . $bugsys->template
->fetch('pagenav') . '";');
240 /*=====================================================================*\
241 || ###################################################################
244 || ###################################################################
245 \*=====================================================================*/