1 : <?php
2 :
3 :
4 :
5 :
6 :
7 :
8 :
9 :
10 :
11 :
12 : class JetPager{
13 : private $currentPageNumber;
14 : private $pageParItems;
15 : private $totalItemCount;
16 : private $viewPageLinks;
17 : private $pageParItemType;
18 : private $scriptName;
19 :
20 : private $parameterPageString = "page";
21 : private $parameterPageParString = "pagePar";
22 :
23 :
24 :
25 :
26 :
27 :
28 :
29 :
30 :
31 :
32 :
33 : public function __construct(
34 : $currentPageNumber = 1,
35 : $pageParItems = 10,
36 : $viewPageLinks = 10,
37 : $scriptName = null){
38 34 : $this->currentPageNumber = $currentPageNumber;
39 34 : $this->pageParItems = $pageParItems;
40 34 : $this->viewPageLinks = $viewPageLinks;
41 34 : $this->scriptName = $scriptName;
42 :
43 34 : $this->pageParItemType = array("10"=>"10", "30"=>"30", "50"=>"50");
44 34 : $this->setTotalItemCount(0);
45 34 : }
46 :
47 :
48 :
49 :
50 :
51 :
52 :
53 :
54 : public function setTotalItemCount($totalItemCount){
55 34 : $this->totalItemCount = $totalItemCount;
56 34 : }
57 :
58 :
59 :
60 :
61 :
62 :
63 :
64 :
65 : public function getTotalItemCount(){
66 1 : return $this->totalItemCount;
67 : }
68 :
69 :
70 :
71 :
72 :
73 :
74 :
75 :
76 : public function setPageParItems($pageParItems){
77 4 : $this->pageParItems = $pageParItems;
78 4 : }
79 :
80 :
81 :
82 :
83 :
84 :
85 :
86 :
87 : public function getPageParItems(){
88 4 : return $this->pageParItems;
89 : }
90 :
91 :
92 :
93 :
94 :
95 :
96 :
97 :
98 : public function setCurrentPageNumber($currentPageNumber){
99 7 : $this->currentPageNumber = $currentPageNumber;
100 7 : }
101 :
102 :
103 :
104 :
105 :
106 :
107 :
108 :
109 : public function getCurrentPageNumber(){
110 5 : return $this->currentPageNumber;
111 : }
112 :
113 :
114 :
115 :
116 :
117 :
118 :
119 :
120 : public function getMaxPage(){
121 7 : return ceil($this->totalItemCount / $this->pageParItems);
122 : }
123 :
124 :
125 :
126 :
127 :
128 :
129 :
130 :
131 : public function getViewMaxPage(){
132 4 : $page = $this->currentPageNumber;
133 4 : $totalPageCount = $this->getMaxPage();
134 4 : $startViewPageLink = $page - ceil($this->viewPageLinks / 2) - 1;
135 4 : $endViewPageLink = $page + ceil($this->viewPageLinks / 2) - 1;
136 :
137 4 : if($startViewPageLink < 1){
138 4 : $sa = 0 - $startViewPageLink;
139 4 : $startViewPageLink = 0;
140 4 : $endViewPageLink += $sa;
141 : }
142 4 : if($endViewPageLink > $totalPageCount){
143 4 : $sa = $endViewPageLink - $totalPageCount;
144 4 : $endViewPageLink = $totalPageCount;
145 4 : $startViewPageLink -= $sa;
146 : }
147 4 : return $endViewPageLink;
148 : }
149 :
150 :
151 :
152 :
153 :
154 :
155 :
156 :
157 : public function getViewMinPage(){
158 4 : $page = $this->currentPageNumber;
159 4 : $totalPageCount = $this->getMaxPage();
160 4 : if($totalPageCount < 1){
161 2 : return 0;
162 : }
163 4 : $startViewPageLink = $page - ceil($this->viewPageLinks / 2) - 1;
164 4 : $endViewPageLink = $page + ceil($this->viewPageLinks / 2) - 1;
165 :
166 4 : if($endViewPageLink > $totalPageCount){
167 4 : $sa = $endViewPageLink - $totalPageCount;
168 4 : $endViewPageLink = $totalPageCount;
169 4 : $startViewPageLink -= $sa;
170 : }
171 4 : if($startViewPageLink < 1){
172 4 : $sa = 0 - $startViewPageLink;
173 4 : $startViewPageLink = 0;
174 4 : $endViewPageLink += $sa;
175 : }
176 4 : return $startViewPageLink + 1;
177 : }
178 :
179 : public function getViewPageLinkCount(){
180 0 : return $this->viewPageLinks();
181 : }
182 :
183 :
184 :
185 :
186 :
187 :
188 :
189 :
190 :
191 :
192 :
193 :
194 :
195 : public function getBasicPagerHtml($attributeArray = array()){
196 5 : $page = $this->currentPageNumber;
197 5 : if(!is_numeric($page)){
198 1 : return null;
199 : }
200 5 : if($page < 1){
201 1 : return null;
202 : }
203 :
204 4 : $totalPageCount = $this->getMaxPage();
205 4 : if(!is_numeric($totalPageCount)){
206 0 : return null;
207 : }
208 4 : if($totalPageCount < 1){
209 2 : return null;
210 : }
211 :
212 3 : $startViewPageLink = $this->getViewMinPage();
213 3 : if(!is_numeric($startViewPageLink)){
214 0 : return null;
215 : }
216 3 : if($startViewPageLink < 1){
217 0 : return null;
218 : }
219 :
220 3 : $endViewPageLink = $this->getViewMaxPage();
221 3 : if(!is_numeric($endViewPageLink)){
222 0 : return null;
223 : }
224 3 : if($endViewPageLink < 1){
225 0 : return null;
226 : }
227 :
228 3 : foreach($attributeArray as $attribute){
229 2 : if($attribute->key == $this->parameterPageString){
230 2 : continue;
231 : }
232 2 : if($attribute->key == $this->parameterPageParString){
233 2 : $pageAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);
234 2 : continue;
235 : }
236 1 : $pageAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);
237 1 : $pageParAttributeString .= "&" . $attribute->key . "=" . urlencode($attribute->value);
238 1 : }
239 :
240 3 : $text = "Page:";
241 3 : for($i = $startViewPageLink; $i <= $endViewPageLink; $i++){
242 3 : if($i == $page){
243 3 : $text .= $i;
244 3 : }else{
245 2 : $text .= "<a href=\"" . $this->scriptname . "?";
246 2 : $text .= $this->parameterPageString . "=" . $i . $pageAttributeString ."\">";
247 2 : $text .= $i;
248 2 : $text .= "</a>";
249 : }
250 3 : if($i != $totalPageCount){
251 2 : $text .= " ";
252 : }
253 2 : }
254 :
255 3 : $text .= " ";
256 3 : $text .= " ";
257 3 : $text .= " ";
258 3 : $text .= "Items:";
259 3 : foreach($this->pageParItemType as $pageParItemKey=>$pageParItemValue){
260 3 : if($pageParItemValue == $this->pageParItems){
261 2 : $text .= $pageParItemValue . " ";
262 2 : }else{
263 3 : $text .= "<a href=\"" . $this->scriptname . "?";
264 3 : $text .= $this->parameterPageString . "=1" . $pageParAttributeString;
265 3 : $text .= "&" . $this->parameterPageParString . "=" . $pageParItemValue . "\">";
266 3 : $text .= $pageParItemKey;
267 3 : $text .= "</a> ";
268 : }
269 3 : }
270 3 : return $text;
271 : }
272 : }
273 : ?>
|