Skip to content

Commit 167385c

Browse files
committed
Update PaginatorHelper to deal with first and last options.
1 parent 41c2147 commit 167385c

File tree

1 file changed

+74
-32
lines changed

1 file changed

+74
-32
lines changed

src/View/Helper/BootstrapPaginatorHelper.php

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class BootstrapPaginatorHelper extends PaginatorHelper {
2828

2929
use BootstrapTrait ;
30-
30+
3131
/**
3232
* Default config for this class
3333
*
@@ -59,34 +59,34 @@ class BootstrapPaginatorHelper extends PaginatorHelper {
5959
'last' => '<li><a href="{{url}}">{{text}}</a></li>',
6060
'number' => '<li><a href="{{url}}">{{text}}</a></li>',
6161
'current' => '<li class="active"><a href="{{url}}">{{text}}</a></li>',
62-
'ellipsis' => '<li class="ellipsis">...</li>',
62+
'ellipsis' => '<li class="ellipsis disabled"><a>...</a></li>',
6363
'sort' => '<a href="{{url}}">{{text}}</a>',
6464
'sortAsc' => '<a class="asc" href="{{url}}">{{text}}</a>',
6565
'sortDesc' => '<a class="desc" href="{{url}}">{{text}}</a>',
6666
'sortAscLocked' => '<a class="asc locked" href="{{url}}">{{text}}</a>',
6767
'sortDescLocked' => '<a class="desc locked" href="{{url}}">{{text}}</a>',
6868
]
6969
];
70-
70+
7171
/**
72-
*
72+
*
7373
* Get pagination link list.
74-
*
74+
*
7575
* @param $options Options for link element
7676
*
7777
* Extra options:
7878
* - size small/normal/large (default normal)
79-
*
79+
*
8080
**/
81-
public function numbers (array $options = array()) {
82-
83-
$class = 'pagination' ;
81+
public function numbers (array $options = []) {
82+
83+
$options += [
84+
'class' => ''
85+
];
86+
87+
$class = 'pagination '.$options['class'] ;
88+
unset($options['class']);
8489

85-
if (isset($options['class'])) {
86-
$class .= ' '.$options['class'] ;
87-
unset($options['class']) ;
88-
}
89-
9090
if (isset($options['size'])) {
9191
switch ($options['size']) {
9292
case 'small':
@@ -98,46 +98,88 @@ public function numbers (array $options = array()) {
9898
}
9999
unset($options['size']) ;
100100
}
101-
101+
102102
if (!isset($options['before'])) {
103103
$options['before'] = '<ul class="'.$class.'">' ;
104104
}
105-
105+
106106
if (!isset($options['after'])) {
107107
$options['after'] = '</ul>' ;
108108
}
109109

110+
return parent::numbers($options);
111+
112+
}
113+
114+
/**
115+
* Generates the numbers for the paginator numbers() method.
116+
*
117+
* @param \Cake\View\StringTemplate $templater StringTemplate instance.
118+
* @param array $params Params from the numbers() method.
119+
* @param array $options Options from the numbers() method.
120+
* @return string Markup output.
121+
*/
122+
protected function _modulusNumbers($templater, $params, $options) {
123+
124+
$options += [
125+
'before' => '',
126+
'after' => ''
127+
];
128+
129+
$first = $prev = $next = $last = '';
130+
131+
/* Previous and Next buttons (addition from standard PaginatorHelper). */
132+
110133
if (isset($options['prev'])) {
111134
$title = $options['prev'] ;
112135
$opts = [] ;
113-
if (is_array($title)) {
114-
$title = $title['title'] ;
115-
unset ($options['prev']['title']) ;
116-
$opts = $options['prev'] ;
136+
if (is_array($title)) {
137+
$title = $title['title'] ;
138+
unset ($options['prev']['title']) ;
139+
$opts = $options['prev'] ;
117140
}
118-
$options['before'] .= $this->prev($title, $opts) ;
141+
$prev = $this->prev($title, $opts) ;
142+
unset($options['prev']);
119143
}
120144

121145
if (isset($options['next'])) {
122146
$title = $options['next'] ;
123147
$opts = [] ;
124-
if (is_array($title)) {
125-
$title = $title['title'];
126-
unset ($options['next']['title']);
127-
$opts = $options['next'];
148+
if (is_array($title)) {
149+
$title = $title['title'];
150+
unset ($options['next']['title']);
151+
$opts = $options['next'];
128152
}
129-
$options['after'] = $this->next($title, $opts).$options['after'] ;
153+
$next = $this->next($title, $opts);
154+
unset($options['next']);
155+
}
156+
157+
/* Custom First and Last. */
158+
159+
$ellipsis = $templater->format('ellipsis', []);
160+
list($start, $end) = $this->_getNumbersStartAndEnd($params, $options);
161+
162+
if (isset($options['last'])) {
163+
$last = $this->_lastNumber($ellipsis, $params, $end, $options);
130164
}
131-
132-
return parent::numbers ($options) ;
165+
166+
if (isset($options['last'])) {
167+
$first = $this->_firstNumber($ellipsis, $params, $start, $options);
168+
}
169+
170+
$options['before'] = $options['before'].$first.$prev;
171+
$options['after'] = $next.$last.$options['after'];
172+
$options['first'] = $options['last'] = false;
173+
174+
return parent::_modulusNumbers($templater, $params, $options) ;
133175
}
134176

135-
public function prev ($title = '<< Previous', array $options = []) {
136-
return $this->_easyIcon ('parent::prev', $title, $options);
177+
public function prev ($title = '<< Previous', array $options = []) {
178+
return $this->_easyIcon ('parent::prev', $title, $options);
137179
}
138180

139-
public function next ($title = 'Next >>', array $options = []) {
140-
return $this->_easyIcon ('parent::next', $title, $options);
181+
public function next ($title = 'Next >>', array $options = []) {
182+
return $this->_easyIcon ('parent::next', $title, $options);
141183
}
142184

143185

0 commit comments

Comments
 (0)