| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TPager class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TPager.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* TPager class.
|
|
|
15 |
*
|
|
|
16 |
* TPager creates a pager that provides UI for end-users to interactively
|
|
|
17 |
* specify which page of data to be rendered in a {@link TDataBoundControl}-derived control,
|
|
|
18 |
* such as {@link TDataList}, {@link TRepeater}, {@link TCheckBoxList}, etc.
|
|
|
19 |
* The target data-bound control is specified by {@link setControlToPaginate ControlToPaginate},
|
|
|
20 |
* which must be the ID path of the target control reaching from the pager's
|
|
|
21 |
* naming container. Note, the target control must have its {@link TDataBoundControl::setAllowPaging AllowPaging}
|
|
|
22 |
* set to true.
|
|
|
23 |
*
|
|
|
24 |
* TPager can display three different UIs, specified via {@link setMode Mode}:
|
|
|
25 |
* - NextPrev: a next page and a previous page button are rendered.
|
|
|
26 |
* - Numeric: a list of page index buttons are rendered.
|
|
|
27 |
* - List: a dropdown list of page indices are rendered.
|
|
|
28 |
*
|
|
|
29 |
* When the pager mode is either NextPrev or Numeric, the paging buttons may be displayed
|
|
|
30 |
* in three types by setting {@link setButtonType ButtonType}:
|
|
|
31 |
* - LinkButton: a hyperlink button
|
|
|
32 |
* - PushButton: a normal button
|
|
|
33 |
* - ImageButton: an image button (please set XXXPageImageUrl properties accordingly to specify the button images.)
|
|
|
34 |
*
|
|
|
35 |
* TPager raises an {@link onPageIndexChanged OnPageIndexChanged} event when
|
|
|
36 |
* the end-user interacts with it and specifies a new page (e.g. clicking
|
|
|
37 |
* on a page button that leads to a new page.) The new page index may be obtained
|
|
|
38 |
* from the event parameter's property {@link TPagerPageChangedEventParameter::getNewPageIndex NewPageIndex}.
|
|
|
39 |
* Normally, in the event handler, one can set the {@link TDataBoundControl::getCurrentPageIndex CurrentPageIndex}
|
|
|
40 |
* to this new page index so that the new page of data is rendered.
|
|
|
41 |
*
|
|
|
42 |
* Multiple pagers can be associated with the same data-bound control.
|
|
|
43 |
*
|
|
|
44 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
45 |
* @version $Id: TPager.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
46 |
* @package System.Web.UI.WebControls
|
|
|
47 |
* @since 3.0.2
|
|
|
48 |
*/
|
|
|
49 |
class TPager extends TWebControl implements INamingContainer
|
|
|
50 |
{
|
|
|
51 |
/**
|
|
|
52 |
* Command name that TPager understands.
|
|
|
53 |
*/
|
|
|
54 |
const CMD_PAGE='Page';
|
|
|
55 |
const CMD_PAGE_NEXT='Next';
|
|
|
56 |
const CMD_PAGE_PREV='Previous';
|
|
|
57 |
const CMD_PAGE_FIRST='First';
|
|
|
58 |
const CMD_PAGE_LAST='Last';
|
|
|
59 |
|
|
|
60 |
private $_pageCount=0;
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Restores the pager state.
|
|
|
64 |
* This method overrides the parent implementation and is invoked when
|
|
|
65 |
* the control is loading persistent state.
|
|
|
66 |
*/
|
|
|
67 |
public function loadState()
|
|
|
68 |
{
|
|
|
69 |
parent::loadState();
|
|
|
70 |
if($this->getEnableViewState(true))
|
|
|
71 |
{
|
|
|
72 |
$this->getControls()->clear();
|
|
|
73 |
$this->buildPager();
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* @return string the ID path of the control whose content would be paginated.
|
|
|
79 |
*/
|
|
|
80 |
public function getControlToPaginate()
|
|
|
81 |
{
|
|
|
82 |
return $this->getViewState('ControlToPaginate','');
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Sets the ID path of the control whose content would be paginated.
|
|
|
87 |
* The ID path is the dot-connected IDs of the controls reaching from
|
|
|
88 |
* the pager's naming container to the target control.
|
|
|
89 |
* @param string the ID path
|
|
|
90 |
*/
|
|
|
91 |
public function setControlToPaginate($value)
|
|
|
92 |
{
|
|
|
93 |
$this->setViewState('ControlToPaginate',$value,'');
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* @return TPagerMode pager mode. Defaults to TPagerMode::NextPrev.
|
|
|
98 |
*/
|
|
|
99 |
public function getMode()
|
|
|
100 |
{
|
|
|
101 |
return $this->getViewState('Mode',TPagerMode::NextPrev);
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* @param TPagerMode pager mode.
|
|
|
106 |
*/
|
|
|
107 |
public function setMode($value)
|
|
|
108 |
{
|
|
|
109 |
$this->setViewState('Mode',TPropertyValue::ensureEnum($value,'TPagerMode'),TPagerMode::NextPrev);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* @return TPagerButtonType the type of command button for paging. Defaults to TPagerButtonType::LinkButton.
|
|
|
114 |
*/
|
|
|
115 |
public function getButtonType()
|
|
|
116 |
{
|
|
|
117 |
return $this->getViewState('ButtonType',TPagerButtonType::LinkButton);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* @param TPagerButtonType the type of command button for paging.
|
|
|
122 |
*/
|
|
|
123 |
public function setButtonType($value)
|
|
|
124 |
{
|
|
|
125 |
$this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'TPagerButtonType'),TPagerButtonType::LinkButton);
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* @return string text for the next page button. Defaults to '>'.
|
|
|
130 |
*/
|
|
|
131 |
public function getNextPageText()
|
|
|
132 |
{
|
|
|
133 |
return $this->getViewState('NextPageText','>');
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* @param string text for the next page button.
|
|
|
138 |
*/
|
|
|
139 |
public function setNextPageText($value)
|
|
|
140 |
{
|
|
|
141 |
$this->setViewState('NextPageText',$value,'>');
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
* @return string text for the previous page button. Defaults to '<'.
|
|
|
146 |
*/
|
|
|
147 |
public function getPrevPageText()
|
|
|
148 |
{
|
|
|
149 |
return $this->getViewState('PrevPageText','<');
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
* @param string text for the next page button.
|
|
|
154 |
*/
|
|
|
155 |
public function setPrevPageText($value)
|
|
|
156 |
{
|
|
|
157 |
$this->setViewState('PrevPageText',$value,'<');
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
/**
|
|
|
161 |
* @return string text for the first page button. Defaults to '<<'.
|
|
|
162 |
*/
|
|
|
163 |
public function getFirstPageText()
|
|
|
164 |
{
|
|
|
165 |
return $this->getViewState('FirstPageText','<<');
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
/**
|
|
|
169 |
* @param string text for the first page button. If empty, the first page button will not be rendered.
|
|
|
170 |
*/
|
|
|
171 |
public function setFirstPageText($value)
|
|
|
172 |
{
|
|
|
173 |
$this->setViewState('FirstPageText',$value,'<<');
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/**
|
|
|
177 |
* @return string text for the last page button. Defaults to '>>'.
|
|
|
178 |
*/
|
|
|
179 |
public function getLastPageText()
|
|
|
180 |
{
|
|
|
181 |
return $this->getViewState('LastPageText','>>');
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
/**
|
|
|
185 |
* @param string text for the last page button. If empty, the last page button will not be rendered.
|
|
|
186 |
*/
|
|
|
187 |
public function setLastPageText($value)
|
|
|
188 |
{
|
|
|
189 |
$this->setViewState('LastPageText',$value,'>>');
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
/**
|
|
|
193 |
* @return string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
194 |
* @since 3.1.1
|
|
|
195 |
*/
|
|
|
196 |
public function getFirstPageImageUrl()
|
|
|
197 |
{
|
|
|
198 |
return $this->getViewState('FirstPageImageUrl','');
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/**
|
|
|
202 |
* @param string the image URL for the first page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
203 |
* @since 3.1.1
|
|
|
204 |
*/
|
|
|
205 |
public function setFirstPageImageUrl($value)
|
|
|
206 |
{
|
|
|
207 |
$this->setViewState('FirstPageImageUrl',$value);
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
/**
|
|
|
211 |
* @return string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
212 |
* @since 3.1.1
|
|
|
213 |
*/
|
|
|
214 |
public function getLastPageImageUrl()
|
|
|
215 |
{
|
|
|
216 |
return $this->getViewState('LastPageImageUrl','');
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* @param string the image URL for the last page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
221 |
* @since 3.1.1
|
|
|
222 |
*/
|
|
|
223 |
public function setLastPageImageUrl($value)
|
|
|
224 |
{
|
|
|
225 |
$this->setViewState('LastPageImageUrl',$value);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
/**
|
|
|
229 |
* @return string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
230 |
* @since 3.1.1
|
|
|
231 |
*/
|
|
|
232 |
public function getNextPageImageUrl()
|
|
|
233 |
{
|
|
|
234 |
return $this->getViewState('NextPageImageUrl','');
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
/**
|
|
|
238 |
* @param string the image URL for the next page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
239 |
* @since 3.1.1
|
|
|
240 |
*/
|
|
|
241 |
public function setNextPageImageUrl($value)
|
|
|
242 |
{
|
|
|
243 |
$this->setViewState('NextPageImageUrl',$value);
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
/**
|
|
|
247 |
* @return string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
248 |
* @since 3.1.1
|
|
|
249 |
*/
|
|
|
250 |
public function getPrevPageImageUrl()
|
|
|
251 |
{
|
|
|
252 |
return $this->getViewState('PrevPageImageUrl','');
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
/**
|
|
|
256 |
* @param string the image URL for the previous page button. This is only used when {@link getButtonType ButtonType} is 'ImageButton'.
|
|
|
257 |
* @since 3.1.1
|
|
|
258 |
*/
|
|
|
259 |
public function setPrevPageImageUrl($value)
|
|
|
260 |
{
|
|
|
261 |
$this->setViewState('PrevPageImageUrl',$value);
|
|
|
262 |
}
|
|
|
263 |
|
|
|
264 |
/**
|
|
|
265 |
* @return string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
|
|
|
266 |
* @see setNumericPageImageUrl
|
|
|
267 |
* @since 3.1.1
|
|
|
268 |
*/
|
|
|
269 |
public function getNumericPageImageUrl()
|
|
|
270 |
{
|
|
|
271 |
return $this->getViewState('NumericPageImageUrl','');
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
/**
|
|
|
275 |
* Sets the image URL for the numeric page buttons.
|
|
|
276 |
* This is actually a template for generating a set of URLs corresponding to numeric button 1, 2, 3, .., etc.
|
|
|
277 |
* Use {0} as the placeholder for the numbers.
|
|
|
278 |
* For example, the image URL http://example.com/images/button{0}.gif
|
|
|
279 |
* will be replaced as http://example.com/images/button1.gif, http://example.com/images/button2.gif, etc.
|
|
|
280 |
* @param string the image URL for the numeric page buttons. This is only used when {@link getButtonType ButtonType} is 'ImageButton' and {@link getMode Mode} is 'Numeric'.
|
|
|
281 |
* @since 3.1.1
|
|
|
282 |
*/
|
|
|
283 |
public function setNumericPageImageUrl($value)
|
|
|
284 |
{
|
|
|
285 |
$this->setViewState('NumericPageImageUrl',$value);
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
/**
|
|
|
289 |
* @return integer maximum number of pager buttons to be displayed. Defaults to 10.
|
|
|
290 |
*/
|
|
|
291 |
public function getPageButtonCount()
|
|
|
292 |
{
|
|
|
293 |
return $this->getViewState('PageButtonCount',10);
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
/**
|
|
|
297 |
* @param integer maximum number of pager buttons to be displayed
|
|
|
298 |
* @throws TInvalidDataValueException if the value is less than 1.
|
|
|
299 |
*/
|
|
|
300 |
public function setPageButtonCount($value)
|
|
|
301 |
{
|
|
|
302 |
if(($value=TPropertyValue::ensureInteger($value))<1)
|
|
|
303 |
throw new TInvalidDataValueException('pager_pagebuttoncount_invalid');
|
|
|
304 |
$this->setViewState('PageButtonCount',$value,10);
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
/**
|
|
|
308 |
* @return integer the zero-based index of the current page. Defaults to 0.
|
|
|
309 |
*/
|
|
|
310 |
public function getCurrentPageIndex()
|
|
|
311 |
{
|
|
|
312 |
return $this->getViewState('CurrentPageIndex',0);
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
/**
|
|
|
316 |
* @param integer the zero-based index of the current page
|
|
|
317 |
* @throws TInvalidDataValueException if the value is less than 0
|
|
|
318 |
*/
|
|
|
319 |
protected function setCurrentPageIndex($value)
|
|
|
320 |
{
|
|
|
321 |
if(($value=TPropertyValue::ensureInteger($value))<0)
|
|
|
322 |
throw new TInvalidDataValueException('pager_currentpageindex_invalid');
|
|
|
323 |
$this->setViewState('CurrentPageIndex',$value,0);
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
/**
|
|
|
327 |
* @return integer number of pages of data items available
|
|
|
328 |
*/
|
|
|
329 |
public function getPageCount()
|
|
|
330 |
{
|
|
|
331 |
return $this->getViewState('PageCount',0);
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
/**
|
|
|
335 |
* @param integer number of pages of data items available
|
|
|
336 |
* @throws TInvalidDataValueException if the value is less than 0
|
|
|
337 |
*/
|
|
|
338 |
protected function setPageCount($value)
|
|
|
339 |
{
|
|
|
340 |
if(($value=TPropertyValue::ensureInteger($value))<0)
|
|
|
341 |
throw new TInvalidDataValueException('pager_pagecount_invalid');
|
|
|
342 |
$this->setViewState('PageCount',$value,0);
|
|
|
343 |
}
|
|
|
344 |
|
|
|
345 |
/**
|
|
|
346 |
* @return boolean whether the current page is the first page Defaults to false.
|
|
|
347 |
*/
|
|
|
348 |
public function getIsFirstPage()
|
|
|
349 |
{
|
|
|
350 |
return $this->getCurrentPageIndex()===0;
|
|
|
351 |
}
|
|
|
352 |
|
|
|
353 |
/**
|
|
|
354 |
* @return boolean whether the current page is the last page
|
|
|
355 |
*/
|
|
|
356 |
public function getIsLastPage()
|
|
|
357 |
{
|
|
|
358 |
return $this->getCurrentPageIndex()===$this->getPageCount()-1;
|
|
|
359 |
}
|
|
|
360 |
|
|
|
361 |
/**
|
|
|
362 |
* Performs databinding to populate data items from data source.
|
|
|
363 |
* This method is invoked by {@link dataBind()}.
|
|
|
364 |
* You may override this function to provide your own way of data population.
|
|
|
365 |
* @param Traversable the bound data
|
|
|
366 |
*/
|
|
|
367 |
public function onPreRender($param)
|
|
|
368 |
{
|
|
|
369 |
parent::onPreRender($param);
|
|
|
370 |
|
|
|
371 |
$controlID=$this->getControlToPaginate();
|
|
|
372 |
if(($targetControl=$this->getNamingContainer()->findControl($controlID))===null || !($targetControl instanceof TDataBoundControl))
|
|
|
373 |
throw new TConfigurationException('pager_controltopaginate_invalid',$controlID);
|
|
|
374 |
|
|
|
375 |
if($targetControl->getAllowPaging())
|
|
|
376 |
{
|
|
|
377 |
$this->_pageCount=$targetControl->getPageCount();
|
|
|
378 |
$this->getControls()->clear();
|
|
|
379 |
$this->setPageCount($targetControl->getPageCount());
|
|
|
380 |
$this->setCurrentPageIndex($targetControl->getCurrentPageIndex());
|
|
|
381 |
$this->buildPager();
|
|
|
382 |
}
|
|
|
383 |
else
|
|
|
384 |
$this->_pageCount=0;
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
/**
|
|
|
388 |
* Renders the control.
|
|
|
389 |
* The method overrides the parent implementation by rendering
|
|
|
390 |
* the pager only when there are two or more pages.
|
|
|
391 |
* @param THtmlWriter the writer
|
|
|
392 |
*/
|
|
|
393 |
public function render($writer)
|
|
|
394 |
{
|
|
|
395 |
if($this->_pageCount>1)
|
|
|
396 |
parent::render($writer);
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
/**
|
|
|
400 |
* Builds the pager content based on the pager mode.
|
|
|
401 |
* Current implementation includes building 'NextPrev', 'Numeric' and 'DropDownList' pagers.
|
|
|
402 |
* Derived classes may override this method to provide additional pagers.
|
|
|
403 |
*/
|
|
|
404 |
protected function buildPager()
|
|
|
405 |
{
|
|
|
406 |
switch($this->getMode())
|
|
|
407 |
{
|
|
|
408 |
case TPagerMode::NextPrev:
|
|
|
409 |
$this->buildNextPrevPager();
|
|
|
410 |
break;
|
|
|
411 |
case TPagerMode::Numeric:
|
|
|
412 |
$this->buildNumericPager();
|
|
|
413 |
break;
|
|
|
414 |
case TPagerMode::DropDownList:
|
|
|
415 |
$this->buildListPager();
|
|
|
416 |
break;
|
|
|
417 |
}
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
/**
|
|
|
421 |
* Creates a pager button.
|
|
|
422 |
* Depending on the button type, a TLinkButton or a TButton may be created.
|
|
|
423 |
* If it is enabled (clickable), its command name and parameter will also be set.
|
|
|
424 |
* Derived classes may override this method to create additional types of buttons, such as TImageButton.
|
|
|
425 |
* @param string button type, either LinkButton or PushButton
|
|
|
426 |
* @param boolean whether the button should be enabled
|
|
|
427 |
* @param string caption of the button.
|
|
|
428 |
* @param string CommandName corresponding to the OnCommand event of the button.
|
|
|
429 |
* @param string CommandParameter corresponding to the OnCommand event of the button
|
|
|
430 |
* @return mixed the button instance
|
|
|
431 |
*/
|
|
|
432 |
protected function createPagerButton($buttonType,$enabled,$text,$commandName,$commandParameter)
|
|
|
433 |
{
|
|
|
434 |
if($buttonType===TPagerButtonType::LinkButton)
|
|
|
435 |
{
|
|
|
436 |
if($enabled)
|
|
|
437 |
$button=new TLinkButton;
|
|
|
438 |
else
|
|
|
439 |
{
|
|
|
440 |
$button=new TLabel;
|
|
|
441 |
$button->setText($text);
|
|
|
442 |
return $button;
|
|
|
443 |
}
|
|
|
444 |
}
|
|
|
445 |
else
|
|
|
446 |
{
|
|
|
447 |
if($buttonType===TPagerButtonType::ImageButton)
|
|
|
448 |
{
|
|
|
449 |
$button=new TImageButton;
|
|
|
450 |
$button->setImageUrl($this->getPageImageUrl($text,$commandName));
|
|
|
451 |
}
|
|
|
452 |
else
|
|
|
453 |
$button=new TButton;
|
|
|
454 |
if(!$enabled)
|
|
|
455 |
$button->setEnabled(false);
|
|
|
456 |
}
|
|
|
457 |
$button->setText($text);
|
|
|
458 |
$button->setCommandName($commandName);
|
|
|
459 |
$button->setCommandParameter($commandParameter);
|
|
|
460 |
$button->setCausesValidation(false);
|
|
|
461 |
return $button;
|
|
|
462 |
}
|
|
|
463 |
|
|
|
464 |
/**
|
|
|
465 |
* @param string the caption of the image button
|
|
|
466 |
* @param string the command name associated with the image button
|
|
|
467 |
* @since 3.1.1
|
|
|
468 |
*/
|
|
|
469 |
protected function getPageImageUrl($text,$commandName)
|
|
|
470 |
{
|
|
|
471 |
switch($commandName)
|
|
|
472 |
{
|
|
|
473 |
case self::CMD_PAGE:
|
|
|
474 |
$url=$this->getNumericPageImageUrl();
|
|
|
475 |
return str_replace('{0}',$text,$url);
|
|
|
476 |
case self::CMD_PAGE_NEXT:
|
|
|
477 |
return $this->getNextPageImageUrl();
|
|
|
478 |
case self::CMD_PAGE_PREV:
|
|
|
479 |
return $this->getPrevPageImageUrl();
|
|
|
480 |
case self::CMD_PAGE_FIRST:
|
|
|
481 |
return $this->getFirstPageImageUrl();
|
|
|
482 |
case self::CMD_PAGE_LAST:
|
|
|
483 |
return $this->getLastPageImageUrl();
|
|
|
484 |
default:
|
|
|
485 |
return '';
|
|
|
486 |
}
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
/**
|
|
|
490 |
* Builds a next-prev pager
|
|
|
491 |
*/
|
|
|
492 |
protected function buildNextPrevPager()
|
|
|
493 |
{
|
|
|
494 |
$buttonType=$this->getButtonType();
|
|
|
495 |
$controls=$this->getControls();
|
|
|
496 |
if($this->getIsFirstPage())
|
|
|
497 |
{
|
|
|
498 |
if(($text=$this->getFirstPageText())!=='')
|
|
|
499 |
{
|
|
|
500 |
$label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_FIRST,'');
|
|
|
501 |
$controls->add($label);
|
|
|
502 |
$controls->add("\n");
|
|
|
503 |
}
|
|
|
504 |
$label=$this->createPagerButton($buttonType,false,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
|
|
|
505 |
$controls->add($label);
|
|
|
506 |
}
|
|
|
507 |
else
|
|
|
508 |
{
|
|
|
509 |
if(($text=$this->getFirstPageText())!=='')
|
|
|
510 |
{
|
|
|
511 |
$button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
|
|
|
512 |
$controls->add($button);
|
|
|
513 |
$controls->add("\n");
|
|
|
514 |
}
|
|
|
515 |
$button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE_PREV,'');
|
|
|
516 |
$controls->add($button);
|
|
|
517 |
}
|
|
|
518 |
$controls->add("\n");
|
|
|
519 |
if($this->getIsLastPage())
|
|
|
520 |
{
|
|
|
521 |
$label=$this->createPagerButton($buttonType,false,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
|
|
|
522 |
$controls->add($label);
|
|
|
523 |
if(($text=$this->getLastPageText())!=='')
|
|
|
524 |
{
|
|
|
525 |
$controls->add("\n");
|
|
|
526 |
$label=$this->createPagerButton($buttonType,false,$text,self::CMD_PAGE_LAST,'');
|
|
|
527 |
$controls->add($label);
|
|
|
528 |
}
|
|
|
529 |
}
|
|
|
530 |
else
|
|
|
531 |
{
|
|
|
532 |
$button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE_NEXT,'');
|
|
|
533 |
$controls->add($button);
|
|
|
534 |
if(($text=$this->getLastPageText())!=='')
|
|
|
535 |
{
|
|
|
536 |
$controls->add("\n");
|
|
|
537 |
$button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
|
|
|
538 |
$controls->add($button);
|
|
|
539 |
}
|
|
|
540 |
}
|
|
|
541 |
}
|
|
|
542 |
|
|
|
543 |
/**
|
|
|
544 |
* Builds a numeric pager
|
|
|
545 |
*/
|
|
|
546 |
protected function buildNumericPager()
|
|
|
547 |
{
|
|
|
548 |
$buttonType=$this->getButtonType();
|
|
|
549 |
$controls=$this->getControls();
|
|
|
550 |
$pageCount=$this->getPageCount();
|
|
|
551 |
$pageIndex=$this->getCurrentPageIndex()+1;
|
|
|
552 |
$maxButtonCount=$this->getPageButtonCount();
|
|
|
553 |
$buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
|
|
|
554 |
$startPageIndex=1;
|
|
|
555 |
$endPageIndex=$buttonCount;
|
|
|
556 |
if($pageIndex>$endPageIndex)
|
|
|
557 |
{
|
|
|
558 |
$startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
|
|
|
559 |
if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
|
|
|
560 |
$endPageIndex=$pageCount;
|
|
|
561 |
if($endPageIndex-$startPageIndex+1<$maxButtonCount)
|
|
|
562 |
{
|
|
|
563 |
if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
|
|
|
564 |
$startPageIndex=1;
|
|
|
565 |
}
|
|
|
566 |
}
|
|
|
567 |
|
|
|
568 |
if($startPageIndex>1)
|
|
|
569 |
{
|
|
|
570 |
if(($text=$this->getFirstPageText())!=='')
|
|
|
571 |
{
|
|
|
572 |
$button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_FIRST,'');
|
|
|
573 |
$controls->add($button);
|
|
|
574 |
$controls->add("\n");
|
|
|
575 |
}
|
|
|
576 |
$prevPageIndex=$startPageIndex-1;
|
|
|
577 |
$button=$this->createPagerButton($buttonType,true,$this->getPrevPageText(),self::CMD_PAGE,"$prevPageIndex");
|
|
|
578 |
$controls->add($button);
|
|
|
579 |
$controls->add("\n");
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
for($i=$startPageIndex;$i<=$endPageIndex;++$i)
|
|
|
583 |
{
|
|
|
584 |
if($i===$pageIndex)
|
|
|
585 |
{
|
|
|
586 |
$label=$this->createPagerButton($buttonType,false,"$i",self::CMD_PAGE,'');
|
|
|
587 |
$controls->add($label);
|
|
|
588 |
}
|
|
|
589 |
else
|
|
|
590 |
{
|
|
|
591 |
$button=$this->createPagerButton($buttonType,true,"$i",self::CMD_PAGE,"$i");
|
|
|
592 |
$controls->add($button);
|
|
|
593 |
}
|
|
|
594 |
if($i<$endPageIndex)
|
|
|
595 |
$controls->add("\n");
|
|
|
596 |
}
|
|
|
597 |
|
|
|
598 |
if($pageCount>$endPageIndex)
|
|
|
599 |
{
|
|
|
600 |
$controls->add("\n");
|
|
|
601 |
$nextPageIndex=$endPageIndex+1;
|
|
|
602 |
$button=$this->createPagerButton($buttonType,true,$this->getNextPageText(),self::CMD_PAGE,"$nextPageIndex");
|
|
|
603 |
$controls->add($button);
|
|
|
604 |
if(($text=$this->getLastPageText())!=='')
|
|
|
605 |
{
|
|
|
606 |
$controls->add("\n");
|
|
|
607 |
$button=$this->createPagerButton($buttonType,true,$text,self::CMD_PAGE_LAST,'');
|
|
|
608 |
$controls->add($button);
|
|
|
609 |
}
|
|
|
610 |
}
|
|
|
611 |
}
|
|
|
612 |
|
|
|
613 |
/**
|
|
|
614 |
* Builds a dropdown list pager
|
|
|
615 |
*/
|
|
|
616 |
protected function buildListPager()
|
|
|
617 |
{
|
|
|
618 |
$list=new TDropDownList;
|
|
|
619 |
$this->getControls()->add($list);
|
|
|
620 |
$list->setDataSource(range(1,$this->getPageCount()));
|
|
|
621 |
$list->dataBind();
|
|
|
622 |
$list->setSelectedIndex($this->getCurrentPageIndex());
|
|
|
623 |
$list->setAutoPostBack(true);
|
|
|
624 |
$list->attachEventHandler('OnSelectedIndexChanged',array($this,'listIndexChanged'));
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
/**
|
|
|
628 |
* Event handler to the OnSelectedIndexChanged event of the dropdown list.
|
|
|
629 |
* This handler will raise {@link onPageIndexChanged OnPageIndexChanged} event.
|
|
|
630 |
* @param TDropDownList the dropdown list control raising the event
|
|
|
631 |
* @param TEventParameter event parameter
|
|
|
632 |
*/
|
|
|
633 |
public function listIndexChanged($sender,$param)
|
|
|
634 |
{
|
|
|
635 |
$pageIndex=$sender->getSelectedIndex();
|
|
|
636 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
|
|
|
637 |
}
|
|
|
638 |
|
|
|
639 |
/**
|
|
|
640 |
* This event is raised when page index is changed due to a page button click.
|
|
|
641 |
* @param TPagerPageChangedEventParameter event parameter
|
|
|
642 |
*/
|
|
|
643 |
public function onPageIndexChanged($param)
|
|
|
644 |
{
|
|
|
645 |
$this->raiseEvent('OnPageIndexChanged',$this,$param);
|
|
|
646 |
}
|
|
|
647 |
|
|
|
648 |
/**
|
|
|
649 |
* Processes a bubbled event.
|
|
|
650 |
* This method overrides parent's implementation by wrapping event parameter
|
|
|
651 |
* for <b>OnCommand</b> event with item information.
|
|
|
652 |
* @param TControl the sender of the event
|
|
|
653 |
* @param TEventParameter event parameter
|
|
|
654 |
* @return boolean whether the event bubbling should stop here.
|
|
|
655 |
*/
|
|
|
656 |
public function bubbleEvent($sender,$param)
|
|
|
657 |
{
|
|
|
658 |
if($param instanceof TCommandEventParameter)
|
|
|
659 |
{
|
|
|
660 |
$command=$param->getCommandName();
|
|
|
661 |
if(strcasecmp($command,self::CMD_PAGE)===0)
|
|
|
662 |
{
|
|
|
663 |
$pageIndex=TPropertyValue::ensureInteger($param->getCommandParameter())-1;
|
|
|
664 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
|
|
|
665 |
return true;
|
|
|
666 |
}
|
|
|
667 |
else if(strcasecmp($command,self::CMD_PAGE_NEXT)===0)
|
|
|
668 |
{
|
|
|
669 |
$pageIndex=$this->getCurrentPageIndex()+1;
|
|
|
670 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
|
|
|
671 |
return true;
|
|
|
672 |
}
|
|
|
673 |
else if(strcasecmp($command,self::CMD_PAGE_PREV)===0)
|
|
|
674 |
{
|
|
|
675 |
$pageIndex=$this->getCurrentPageIndex()-1;
|
|
|
676 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$pageIndex));
|
|
|
677 |
return true;
|
|
|
678 |
}
|
|
|
679 |
else if(strcasecmp($command,self::CMD_PAGE_FIRST)===0)
|
|
|
680 |
{
|
|
|
681 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,0));
|
|
|
682 |
return true;
|
|
|
683 |
}
|
|
|
684 |
else if(strcasecmp($command,self::CMD_PAGE_LAST)===0)
|
|
|
685 |
{
|
|
|
686 |
$this->onPageIndexChanged(new TPagerPageChangedEventParameter($sender,$this->getPageCount()-1));
|
|
|
687 |
return true;
|
|
|
688 |
}
|
|
|
689 |
return false;
|
|
|
690 |
}
|
|
|
691 |
else
|
|
|
692 |
return false;
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
/**
|
|
|
697 |
* TPagerPageChangedEventParameter class
|
|
|
698 |
*
|
|
|
699 |
* TPagerPageChangedEventParameter encapsulates the parameter data for
|
|
|
700 |
* {@link TPager::onPageIndexChanged PageIndexChanged} event of {@link TPager} controls.
|
|
|
701 |
*
|
|
|
702 |
* The {@link getCommandSource CommandSource} property refers to the control
|
|
|
703 |
* that originally raises the OnCommand event, while {@link getNewPageIndex NewPageIndex}
|
|
|
704 |
* returns the new page index carried with the page command.
|
|
|
705 |
*
|
|
|
706 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
707 |
* @version $Id: TPager.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
708 |
* @package System.Web.UI.WebControls
|
|
|
709 |
* @since 3.0.2
|
|
|
710 |
*/
|
|
|
711 |
class TPagerPageChangedEventParameter extends TEventParameter
|
|
|
712 |
{
|
|
|
713 |
/**
|
|
|
714 |
* @var integer new page index
|
|
|
715 |
*/
|
|
|
716 |
private $_newIndex;
|
|
|
717 |
/**
|
|
|
718 |
* @var TControl original event sender
|
|
|
719 |
*/
|
|
|
720 |
private $_source=null;
|
|
|
721 |
|
|
|
722 |
/**
|
|
|
723 |
* Constructor.
|
|
|
724 |
* @param TControl the control originally raises the <b>OnCommand</b> event.
|
|
|
725 |
* @param integer new page index
|
|
|
726 |
*/
|
|
|
727 |
public function __construct($source,$newPageIndex)
|
|
|
728 |
{
|
|
|
729 |
$this->_source=$source;
|
|
|
730 |
$this->_newIndex=$newPageIndex;
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
/**
|
|
|
734 |
* @return TControl the control originally raises the <b>OnCommand</b> event.
|
|
|
735 |
*/
|
|
|
736 |
public function getCommandSource()
|
|
|
737 |
{
|
|
|
738 |
return $this->_source;
|
|
|
739 |
}
|
|
|
740 |
|
|
|
741 |
/**
|
|
|
742 |
* @return integer new page index
|
|
|
743 |
*/
|
|
|
744 |
public function getNewPageIndex()
|
|
|
745 |
{
|
|
|
746 |
return $this->_newIndex;
|
|
|
747 |
}
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
|
|
|
751 |
/**
|
|
|
752 |
* TPagerMode class.
|
|
|
753 |
* TPagerMode defines the enumerable type for the possible modes that a {@link TPager} control can take.
|
|
|
754 |
*
|
|
|
755 |
* The following enumerable values are defined:
|
|
|
756 |
* - NextPrev: pager buttons are displayed as next and previous pages
|
|
|
757 |
* - Numeric: pager buttons are displayed as numeric page numbers
|
|
|
758 |
* - DropDownList: a dropdown list is used to select pages
|
|
|
759 |
*
|
|
|
760 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
761 |
* @version $Id: TPager.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
762 |
* @package System.Web.UI.WebControls
|
|
|
763 |
* @since 3.0.4
|
|
|
764 |
*/
|
|
|
765 |
class TPagerMode extends TEnumerable
|
|
|
766 |
{
|
|
|
767 |
const NextPrev='NextPrev';
|
|
|
768 |
const Numeric='Numeric';
|
|
|
769 |
const DropDownList='DropDownList';
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
|
|
|
773 |
/**
|
|
|
774 |
* TPagerButtonType class.
|
|
|
775 |
* TPagerButtonType defines the enumerable type for the possible types of pager buttons.
|
|
|
776 |
*
|
|
|
777 |
* The following enumerable values are defined:
|
|
|
778 |
* - LinkButton: link buttons
|
|
|
779 |
* - PushButton: form submit buttons
|
|
|
780 |
*
|
|
|
781 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
782 |
* @version $Id: TPager.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
783 |
* @package System.Web.UI.WebControls
|
|
|
784 |
* @since 3.0.4
|
|
|
785 |
*/
|
|
|
786 |
class TPagerButtonType extends TEnumerable
|
|
|
787 |
{
|
|
|
788 |
const LinkButton='LinkButton';
|
|
|
789 |
const PushButton='PushButton';
|
|
|
790 |
const ImageButton='ImageButton';
|
|
|
791 |
}
|
|
|
792 |
|