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:
nate 2006-10-12 20:03:58 +00:00
parent e2ffad5a65
commit 8a64ba93fc

View file

@ -47,7 +47,7 @@ class PaginatorHelper extends Helper {
*/ */
var $__defaultModel = null; var $__defaultModel = null;
function __params($model = null) { function params($model = null) {
if ($model == null) { if ($model == null) {
$model = $this->defaultModel(); $model = $this->defaultModel();
} }
@ -66,7 +66,7 @@ class PaginatorHelper extends Helper {
if ($model == null) { if ($model == null) {
$model = $this->defaultModel(); $model = $this->defaultModel();
} }
$params = $this->__params[$model]; $params = $this->params[$model];
if (isset($params['options']['page'])) { if (isset($params['options']['page'])) {
return $params['options']['page']; return $params['options']['page'];
} }
@ -111,7 +111,7 @@ class PaginatorHelper extends Helper {
), ),
$options $options
); );
$paging = $this->__params($options['model']); $paging = $this->params($options['model']);
if ($this->{$check}() || $disabledTitle !== null || !empty($disabledOptions)) { if ($this->{$check}() || $disabledTitle !== null || !empty($disabledOptions)) {
if (!$this->{$check}()) { if (!$this->{$check}()) {
@ -120,6 +120,9 @@ class PaginatorHelper extends Helper {
$title = $disabledTitle; $title = $disabledTitle;
} }
} }
} else {
return null;
}
$keys = array('url', 'model', 'escape'); $keys = array('url', 'model', 'escape');
foreach ($keys as $key) { foreach ($keys as $key) {
@ -129,9 +132,6 @@ class PaginatorHelper extends Helper {
unset($options[$key]); unset($options[$key]);
} }
} }
} else {
return null;
}
if (is_array($url)) { if (is_array($url)) {
if ($which == 'Prev') { if ($which == 'Prev') {
@ -160,7 +160,7 @@ class PaginatorHelper extends Helper {
* Returns true if the given result set is not at the first page * Returns true if the given result set is not at the first page
* *
* @param string $model * @param string $model
* @return return boolean * @return boolean
*/ */
function hasPrev($model = null) { function hasPrev($model = null) {
return $this->__hasPage($model, 'prev'); 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 * Returns true if the given result set is not at the last page
* *
* @param string $model * @param string $model
* @return return boolean * @return boolean
*/ */
function hasNext($model = null) { function hasNext($model = null) {
return $this->__hasPage($model, 'next'); 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 * Protected method
* *
@ -218,7 +237,7 @@ class PaginatorHelper extends Helper {
$options $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'; $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); $end = ($paging['count'] < ($start + $paging['options']['limit'] - 1)) ? $paging['count'] : ($start + $paging['options']['limit'] - 1);