]>
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'];
85 $this->perpage
= intval($this->perpage
);
89 * Takes the variables and splits up the pages
93 function split_pages()
95 $this->pagecount
= ceil($this->total
/ $this->perpage
);
99 * Returns the lower limit of the pages
103 * @param integer Page number
105 * @return integer Lower result limit
107 function fetch_limit($page = null)
114 $limit = $page * $this->perpage
;
121 else if ($page > $this->pagecount
)
123 $page = $this->pagecount
- 1;
124 $limit = $this->total
;
131 else if ($limit > $this->total
)
142 * Constructs the page navigator
146 * @param string Base link path
148 * @return string Generated HTML page navigator
150 function construct_page_nav($baselink)
155 if (strpos($baselink, '?') === false)
159 else if (!preg_match('#\?$#', $baselink) AND !preg_match('#(&|&)$#', $baselink))
161 $baselink .= '&';
164 // first page number in page nav
165 $startpage = $this->page
- $this->pagelinks
;
171 // last page number in page nav
172 $endpage = $this->page +
$this->pagelinks
;
173 if ($endpage > $this->pagecount
)
175 $endpage = $this->pagecount
;
178 // prev page in page nav
179 $prevpage = $this->page
- 1;
185 // next page in page nav
186 $nextpage = $this->page +
1;
187 if ($nextpage > $this->pagecount
)
189 $nextpage = $this->pagecount
;
192 // show the prev page
193 $show['prev'] = true;
194 if ($this->page
== $startpage)
196 $show['prev'] = false;
199 // show the next page
200 $show['next'] = true;
201 if ($this->page
== $endpage)
203 $show['next'] = false;
206 // show the first page
207 $show['first'] = false;
210 $show['first'] = true;
213 // show the last page
214 $show['last'] = false;
215 if ($endpage < $this->pagecount
)
217 $show['last'] = true;
220 // construct the page bits
221 for ($i = $startpage; $i <= $endpage; $i++
)
223 if ($i == $this->page
)
231 eval('$pagebits[] .= "' . $bugsys->template
->fetch('pagenav_bit') . '";');
234 $pagebits = implode(",\n", $pagebits);
236 eval('$pagenav = "' . $bugsys->template
->fetch('pagenav') . '";');
242 /*=====================================================================*\
243 || ###################################################################
246 || ###################################################################
247 \*=====================================================================*/