1 <?php
2 3 4 5 6 7 8
9
10 11 12 13
14 class extends CLinkPager
15 {
16
17 const ALIGNMENT_CENTER = 'centered';
18 const ALIGNMENT_RIGHT = 'right';
19
20 21 22
23 public $alignment;
24 25 26 27
28 public = '';
29 30 31 32
33 public $cssFile = false;
34 35 36
37 public $displayFirstAndLast = false;
38
39 40 41
42 public function init()
43 {
44 if ($this->nextPageLabel === null)
45 $this->nextPageLabel = '→';
46
47 if ($this->prevPageLabel === null)
48 $this->prevPageLabel = '←';
49
50 $classes = array();
51
52 $validAlignments = array(self::ALIGNMENT_CENTER, self::ALIGNMENT_RIGHT);
53
54 if (in_array($this->alignment, $validAlignments))
55 $classes[] = 'pagination-'.$this->alignment;
56
57 if (!empty($classes))
58 {
59 $classes = implode(' ', $classes);
60 if (isset($this->htmlOptions['class']))
61 $this->htmlOptions['class'] = ' '.$classes;
62 else
63 $this->htmlOptions['class'] = $classes;
64 }
65
66 parent::init();
67 }
68
69 70 71 72
73 protected function createPageButtons()
74 {
75 if (($pageCount = $this->getPageCount()) <= 1)
76 return array();
77
78 list ($beginPage, $endPage) = $this->getPageRange();
79
80 $currentPage = $this->getCurrentPage(false);
81
82 $buttons = array();
83
84
85 if ($this->displayFirstAndLast)
86 $buttons[] = $this->createPageButton($this->firstPageLabel, 0, 'first', $currentPage <= 0, false);
87
88
89 if (($page = $currentPage - 1) < 0)
90 $page = 0;
91
92 $buttons[] = $this->createPageButton($this->prevPageLabel, $page, 'previous', $currentPage <= 0, false);
93
94
95 for ($i = $beginPage; $i <= $endPage; ++$i)
96 $buttons[] = $this->createPageButton($i + 1, $i, '', false, $i == $currentPage);
97
98
99 if (($page = $currentPage+1) >= $pageCount-1)
100 $page = $pageCount-1;
101
102 $buttons[] = $this->createPageButton($this->nextPageLabel, $page, 'next', $currentPage >= ($pageCount - 1), false);
103
104
105 if ($this->displayFirstAndLast)
106 $buttons[] = $this->createPageButton($this->lastPageLabel, $pageCount - 1, 'last', $currentPage >= ($pageCount - 1), false);
107
108 return $buttons;
109 }
110
111 112 113 114 115 116 117 118 119 120
121 protected function createPageButton($label, $page, $class, $hidden, $selected)
122 {
123 if ($hidden || $selected)
124 $class .= ' '.($hidden ? 'disabled' : 'active');
125
126 return CHtml::tag('li', array('class'=>$class), CHtml::link($label, $this->createPageUrl($page)));
127 }
128 }
129