1: <?php
2: /**
3: * CListPager class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11:
12: /**
13: * CListPager displays a dropdown list that contains options leading to different pages of target.
14: *
15: * @author Qiang Xue <qiang.xue@gmail.com>
16: * @package system.web.widgets.pagers
17: * @since 1.0
18: */
19: class CListPager extends CBasePager
20: {
21: /**
22: * @var string the text shown before page buttons. Defaults to 'Go to page: '.
23: */
24: public $header;
25: /**
26: * @var string the text shown after page buttons.
27: */
28: public $footer;
29: /**
30: * @var string the text displayed as a prompt option in the dropdown list. Defaults to null, meaning no prompt.
31: */
32: public $promptText;
33: /**
34: * @var string the format string used to generate page selection text.
35: * The sprintf function will be used to perform the formatting.
36: */
37: public $pageTextFormat;
38: /**
39: * @var array HTML attributes for the enclosing 'div' tag.
40: */
41: public $htmlOptions=array();
42:
43: /**
44: * Initializes the pager by setting some default property values.
45: */
46: public function init()
47: {
48: if($this->header===null)
49: $this->header=Yii::t('yii','Go to page: ');
50: if(!isset($this->htmlOptions['id']))
51: $this->htmlOptions['id']=$this->getId();
52: if($this->promptText!==null)
53: $this->htmlOptions['prompt']=$this->promptText;
54: if(!isset($this->htmlOptions['onchange']))
55: $this->htmlOptions['onchange']="if(this.value!='') {window.location=this.value;};";
56: }
57:
58: /**
59: * Executes the widget.
60: * This overrides the parent implementation by displaying the generated page buttons.
61: */
62: public function run()
63: {
64: if(($pageCount=$this->getPageCount())<=1)
65: return;
66: $pages=array();
67: for($i=0;$i<$pageCount;++$i)
68: $pages[$this->createPageUrl($i)]=$this->generatePageText($i);
69: $selection=$this->createPageUrl($this->getCurrentPage());
70: echo $this->header;
71: echo CHtml::dropDownList($this->getId(),$selection,$pages,$this->htmlOptions);
72: echo $this->footer;
73: }
74:
75: /**
76: * Generates the list option for the specified page number.
77: * You may override this method to customize the option display.
78: * @param integer $page zero-based page number
79: * @return string the list option for the page number
80: */
81: protected function generatePageText($page)
82: {
83: if($this->pageTextFormat!==null)
84: return sprintf($this->pageTextFormat,$page+1);
85: else
86: return $page+1;
87: }
88: }