mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring Paginator helper
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3631 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e2ffad5a65
commit
8a64ba93fc
1 changed files with 34 additions and 15 deletions
|
@ -47,7 +47,7 @@ class PaginatorHelper extends Helper {
|
|||
*/
|
||||
var $__defaultModel = null;
|
||||
|
||||
function __params($model = null) {
|
||||
function params($model = null) {
|
||||
if ($model == null) {
|
||||
$model = $this->defaultModel();
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class PaginatorHelper extends Helper {
|
|||
if ($model == null) {
|
||||
$model = $this->defaultModel();
|
||||
}
|
||||
$params = $this->__params[$model];
|
||||
$params = $this->params[$model];
|
||||
if (isset($params['options']['page'])) {
|
||||
return $params['options']['page'];
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class PaginatorHelper extends Helper {
|
|||
),
|
||||
$options
|
||||
);
|
||||
$paging = $this->__params($options['model']);
|
||||
$paging = $this->params($options['model']);
|
||||
|
||||
if ($this->{$check}() || $disabledTitle !== null || !empty($disabledOptions)) {
|
||||
if (!$this->{$check}()) {
|
||||
|
@ -120,6 +120,9 @@ class PaginatorHelper extends Helper {
|
|||
$title = $disabledTitle;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$keys = array('url', 'model', 'escape');
|
||||
foreach ($keys as $key) {
|
||||
|
@ -129,9 +132,6 @@ class PaginatorHelper extends Helper {
|
|||
unset($options[$key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array($url)) {
|
||||
if ($which == 'Prev') {
|
||||
|
@ -160,7 +160,7 @@ class PaginatorHelper extends Helper {
|
|||
* Returns true if the given result set is not at the first page
|
||||
*
|
||||
* @param string $model
|
||||
* @return return boolean
|
||||
* @return boolean
|
||||
*/
|
||||
function hasPrev($model = null) {
|
||||
return $this->__hasPage($model, 'prev');
|
||||
|
@ -169,11 +169,30 @@ class PaginatorHelper extends Helper {
|
|||
* Returns true if the given result set is not at the last page
|
||||
*
|
||||
* @param string $model
|
||||
* @return return boolean
|
||||
* @return boolean
|
||||
*/
|
||||
function hasNext($model = null) {
|
||||
return $this->__hasPage($model, 'next');
|
||||
}
|
||||
/**
|
||||
* Returns true if the given result set has the page number given by $page
|
||||
*
|
||||
* @param string $model
|
||||
* @param int $page
|
||||
* @return boolean
|
||||
*/
|
||||
function hasPage($model = null, $page = 1) {
|
||||
if (is_numeric($model)) {
|
||||
$page = $model;
|
||||
$model = null;
|
||||
}
|
||||
if ($model == null) {
|
||||
$model = $this->defaultModel();
|
||||
}
|
||||
|
||||
$paging = $this->params($model);
|
||||
return $page <= $paging['pageCount'];
|
||||
}
|
||||
/**
|
||||
* Protected method
|
||||
*
|
||||
|
@ -218,7 +237,7 @@ class PaginatorHelper extends Helper {
|
|||
$options
|
||||
);
|
||||
|
||||
$paging = $this->__params($options['model']);
|
||||
$paging = $this->params($options['model']);
|
||||
$start = $paging['options']['page'] > 1 ? ($paging['options']['page'] - 1) * ($paging['options']['limit']) + 1 : '1';
|
||||
$end = ($paging['count'] < ($start + $paging['options']['limit'] - 1)) ? $paging['count'] : ($start + $paging['options']['limit'] - 1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue