Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CBasePager
  • CLinkPager
  • CListPager
  • MobileRecordIndexPager
  • MobileTopicsPager
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * CLinkPager 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:  * CLinkPager displays a list of hyperlinks that lead to different pages of target.
 13:  *
 14:  * @author Qiang Xue <qiang.xue@gmail.com>
 15:  * @package system.web.widgets.pagers
 16:  * @since 1.0
 17:  */
 18: class CLinkPager extends CBasePager
 19: {
 20:     const CSS_FIRST_PAGE='first';
 21:     const CSS_LAST_PAGE='last';
 22:     const CSS_PREVIOUS_PAGE='previous';
 23:     const CSS_NEXT_PAGE='next';
 24:     const CSS_INTERNAL_PAGE='page';
 25:     const CSS_HIDDEN_PAGE='hidden';
 26:     const CSS_SELECTED_PAGE='selected';
 27: 
 28:     /**
 29:      * @var string the CSS class for the first page button. Defaults to 'first'.
 30:      * @since 1.1.11
 31:      */
 32:     public $firstPageCssClass=self::CSS_FIRST_PAGE;
 33:     /**
 34:      * @var string the CSS class for the last page button. Defaults to 'last'.
 35:      * @since 1.1.11
 36:      */
 37:     public $lastPageCssClass=self::CSS_LAST_PAGE;
 38:     /**
 39:      * @var string the CSS class for the previous page button. Defaults to 'previous'.
 40:      * @since 1.1.11
 41:      */
 42:     public $previousPageCssClass=self::CSS_PREVIOUS_PAGE;
 43:     /**
 44:      * @var string the CSS class for the next page button. Defaults to 'next'.
 45:      * @since 1.1.11
 46:      */
 47:     public $nextPageCssClass=self::CSS_NEXT_PAGE;
 48:     /**
 49:      * @var string the CSS class for the internal page buttons. Defaults to 'page'.
 50:      * @since 1.1.11
 51:      */
 52:     public $internalPageCssClass=self::CSS_INTERNAL_PAGE;
 53:     /**
 54:      * @var string the CSS class for the hidden page buttons. Defaults to 'hidden'.
 55:      * @since 1.1.11
 56:      */
 57:     public $hiddenPageCssClass=self::CSS_HIDDEN_PAGE;
 58:     /**
 59:      * @var string the CSS class for the selected page buttons. Defaults to 'selected'.
 60:      * @since 1.1.11
 61:      */
 62:     public $selectedPageCssClass=self::CSS_SELECTED_PAGE;
 63:     /**
 64:      * @var integer maximum number of page buttons that can be displayed. Defaults to 10.
 65:      */
 66:     public $maxButtonCount=10;
 67:     /**
 68:      * @var string the text label for the next page button. Defaults to 'Next &gt;'.
 69:      * Setting this to false will disable this button.
 70:      */
 71:     public $nextPageLabel;
 72:     /**
 73:      * @var string the text label for the previous page button. Defaults to '&lt; Previous'.
 74:      * Setting this to false will disable this button.
 75:      */
 76:     public $prevPageLabel;
 77:     /**
 78:      * @var string the text label for the first page button. Defaults to '&lt;&lt; First'.
 79:      * Setting this to false will disable this button.
 80:      */
 81:     public $firstPageLabel;
 82:     /**
 83:      * @var string the text label for the last page button. Defaults to 'Last &gt;&gt;'.
 84:      * Setting this to false will disable this button.
 85:      */
 86:     public $lastPageLabel;
 87:     /**
 88:      * @var string the text shown before page buttons. Defaults to 'Go to page: '.
 89:      */
 90:     public $header;
 91:     /**
 92:      * @var string the text shown after page buttons.
 93:      */
 94:     public $footer='';
 95:     /**
 96:      * @var mixed the CSS file used for the widget. Defaults to null, meaning
 97:      * using the default CSS file included together with the widget.
 98:      * If false, no CSS file will be used. Otherwise, the specified CSS file
 99:      * will be included when using this widget.
100:      */
101:     public $cssFile;
102:     /**
103:      * @var array HTML attributes for the pager container tag.
104:      */
105:     public $htmlOptions=array();
106: 
107:     /**
108:      * Initializes the pager by setting some default property values.
109:      */
110:     public function init()
111:     {
112:         if($this->nextPageLabel===null)
113:             $this->nextPageLabel=Yii::t('yii','Next &gt;');
114:         if($this->prevPageLabel===null)
115:             $this->prevPageLabel=Yii::t('yii','&lt; Previous');
116:         if($this->firstPageLabel===null)
117:             $this->firstPageLabel=Yii::t('yii','&lt;&lt; First');
118:         if($this->lastPageLabel===null)
119:             $this->lastPageLabel=Yii::t('yii','Last &gt;&gt;');
120:         if($this->header===null)
121:             $this->header=Yii::t('yii','Go to page: ');
122: 
123:         if(!isset($this->htmlOptions['id']))
124:             $this->htmlOptions['id']=$this->getId();
125:         if(!isset($this->htmlOptions['class']))
126:             $this->htmlOptions['class']='yiiPager';
127:     }
128: 
129:     /**
130:      * Executes the widget.
131:      * This overrides the parent implementation by displaying the generated page buttons.
132:      */
133:     public function run()
134:     {
135:         $this->registerClientScript();
136:         $buttons=$this->createPageButtons();
137:         if(empty($buttons))
138:             return;
139:         echo $this->header;
140:         echo CHtml::tag('ul',$this->htmlOptions,implode("\n",$buttons));
141:         echo $this->footer;
142:     }
143: 
144:     /**
145:      * Creates the page buttons.
146:      * @return array a list of page buttons (in HTML code).
147:      */
148:     protected function createPageButtons()
149:     {
150:         if(($pageCount=$this->getPageCount())<=1)
151:             return array();
152: 
153:         list($beginPage,$endPage)=$this->getPageRange();
154:         $currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
155:         $buttons=array();
156:         
157:         // first page
158:         if ($this->firstPageLabel !== false) {
159:             $buttons[]=$this->createPageButton($this->firstPageLabel,0,$this->firstPageCssClass,$currentPage<=0,false);
160:         }
161:         // prev page
162:         if ($this->prevPageLabel !== false) {
163:             if(($page=$currentPage-1)<0)
164:                 $page=0;
165:             $buttons[]=$this->createPageButton($this->prevPageLabel,$page,$this->previousPageCssClass,$currentPage<=0,false);
166:         }
167: 
168:         // internal pages
169:         for($i=$beginPage;$i<=$endPage;++$i)
170:             $buttons[]=$this->createPageButton($i+1,$i,$this->internalPageCssClass,false,$i==$currentPage);
171:         
172:         // next page
173:         if ($this->nextPageLabel !== false) {
174:             if(($page=$currentPage+1)>=$pageCount-1)
175:                 $page=$pageCount-1;
176:             $buttons[]=$this->createPageButton($this->nextPageLabel,$page,$this->nextPageCssClass,$currentPage>=$pageCount-1,false);
177:         }
178:         // last page
179:         if ($this->lastPageLabel !== false) {
180:             $buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,$this->lastPageCssClass,$currentPage>=$pageCount-1,false);
181:         }
182: 
183:         return $buttons;
184:     }
185: 
186:     /**
187:      * Creates a page button.
188:      * You may override this method to customize the page buttons.
189:      * @param string $label the text label for the button
190:      * @param integer $page the page number
191:      * @param string $class the CSS class for the page button.
192:      * @param boolean $hidden whether this page button is visible
193:      * @param boolean $selected whether this page button is selected
194:      * @return string the generated button
195:      */
196:     protected function createPageButton($label,$page,$class,$hidden,$selected)
197:     {
198:         if($hidden || $selected)
199:             $class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass);
200:         return '<li class="'.$class.'">'.CHtml::link($label,$this->createPageUrl($page)).'</li>';
201:     }
202: 
203:     /**
204:      * @return array the begin and end pages that need to be displayed.
205:      */
206:     protected function getPageRange()
207:     {
208:         $currentPage=$this->getCurrentPage();
209:         $pageCount=$this->getPageCount();
210: 
211:         $beginPage=max(0, $currentPage-(int)($this->maxButtonCount/2));
212:         if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount)
213:         {
214:             $endPage=$pageCount-1;
215:             $beginPage=max(0,$endPage-$this->maxButtonCount+1);
216:         }
217:         return array($beginPage,$endPage);
218:     }
219: 
220:     /**
221:      * Registers the needed client scripts (mainly CSS file).
222:      */
223:     public function registerClientScript()
224:     {
225:         if($this->cssFile!==false)
226:             self::registerCssFile($this->cssFile);
227:     }
228: 
229:     /**
230:      * Registers the needed CSS file.
231:      * @param string $url the CSS URL. If null, a default CSS URL will be used.
232:      */
233:     public static function registerCssFile($url=null)
234:     {
235:         if($url===null)
236:             $url=CHtml::asset(Yii::getPathOfAlias('system.web.widgets.pagers.pager').'.css');
237:         Yii::app()->getClientScript()->registerCssFile($url);
238:     }
239: }
240: 
API documentation generated by ApiGen 2.8.0