mirror of
https://github.com/brmlab/brmsklad.git
synced 2025-08-04 07:03:41 +02:00
Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
parent
5a580df460
commit
235a541597
793 changed files with 60746 additions and 23753 deletions
|
@ -5,16 +5,17 @@
|
|||
* Generates pagination links
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org CakePHP(tm) Project
|
||||
* @package Cake.View.Helper
|
||||
* @since CakePHP(tm) v 1.2.0
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
App::uses('AppHelper', 'View/Helper');
|
||||
|
@ -38,7 +39,7 @@ class PaginatorHelper extends AppHelper {
|
|||
public $helpers = array('Html');
|
||||
|
||||
/**
|
||||
* The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure
|
||||
* The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure
|
||||
* that JsHelper is defined as a helper before PaginatorHelper, if you want to customize the JsHelper.
|
||||
*
|
||||
* @var string
|
||||
|
@ -63,9 +64,9 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `escape` Defines if the title field for the link should be escaped (default: true).
|
||||
* - `update` DOM id of the element updated with the results of the AJAX call.
|
||||
* If this key isn't specified Paginator will use plain HTML links.
|
||||
* - `paging['paramType']` The type of parameters to use when creating links. Valid options are
|
||||
* 'querystring' and 'named'. See PaginatorComponent::$settings for more information.
|
||||
* - `convertKeys` - A list of keys in url arrays that should be converted to querysting params
|
||||
* - `paging['paramType']` The type of parameters to use when creating links. Valid options are
|
||||
* 'querystring' and 'named'. See PaginatorComponent::$settings for more information.
|
||||
* - `convertKeys` - A list of keys in URL arrays that should be converted to querysting params
|
||||
* if paramType == 'querystring'.
|
||||
*
|
||||
* @var array
|
||||
|
@ -78,7 +79,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
|
||||
*
|
||||
* Use `public $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
|
||||
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
||||
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
||||
* adapter before including PaginatorHelper in your helpers array.
|
||||
*
|
||||
* The chosen custom helper must implement a `link()` method.
|
||||
|
@ -94,17 +95,17 @@ class PaginatorHelper extends AppHelper {
|
|||
App::uses($ajaxProvider . 'Helper', 'View/Helper');
|
||||
$classname = $ajaxProvider . 'Helper';
|
||||
if (!class_exists($classname) || !method_exists($classname, 'link')) {
|
||||
throw new CakeException(sprintf(
|
||||
__d('cake_dev', '%s does not implement a link() method, it is incompatible with PaginatorHelper'), $classname
|
||||
));
|
||||
throw new CakeException(
|
||||
__d('cake_dev', '%s does not implement a %s method, it is incompatible with %s', $classname, 'link()', 'PaginatorHelper')
|
||||
);
|
||||
}
|
||||
parent::__construct($View, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Before render callback. Overridden to merge passed args with url options.
|
||||
* Before render callback. Overridden to merge passed args with URL options.
|
||||
*
|
||||
* @param string $viewFile
|
||||
* @param string $viewFile View file name.
|
||||
* @return void
|
||||
*/
|
||||
public function beforeRender($viewFile) {
|
||||
|
@ -118,7 +119,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current paging parameters from the resultset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return array The array of paging parameters for the paginated resultset.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
||||
*/
|
||||
|
@ -127,11 +128,34 @@ class PaginatorHelper extends AppHelper {
|
|||
$model = $this->defaultModel();
|
||||
}
|
||||
if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) {
|
||||
return null;
|
||||
return array(
|
||||
'prevPage' => false,
|
||||
'nextPage' => true,
|
||||
'paramType' => 'named',
|
||||
'pageCount' => 1,
|
||||
'options' => array(),
|
||||
'page' => 1
|
||||
);
|
||||
}
|
||||
return $this->request->params['paging'][$model];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience access to any of the paginator params.
|
||||
*
|
||||
* @param string $key Key of the paginator params array to retrieve.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return mixed Content of the requested param.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
||||
*/
|
||||
public function param($key, $model = null) {
|
||||
$params = $this->params($model);
|
||||
if (!isset($params[$key])) {
|
||||
return null;
|
||||
}
|
||||
return $params[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets default options for all pagination links
|
||||
*
|
||||
|
@ -172,7 +196,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current page of the recordset for the given model
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return string The current page number of the recordset.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::current
|
||||
*/
|
||||
|
@ -188,9 +212,9 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current key by which the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param array $options Options for pagination links. See #options for list of keys.
|
||||
* @return string The name of the key by which the recordset is being sorted, or
|
||||
* @return string|null The name of the key by which the recordset is being sorted, or
|
||||
* null if the results are not currently sorted.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sortKey
|
||||
*/
|
||||
|
@ -214,7 +238,7 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Gets the current direction the recordset is sorted
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param array $options Options for pagination links. See #options for list of keys.
|
||||
* @return string The direction by which the recordset is being sorted, or
|
||||
* null if the results are not currently sorted.
|
||||
|
@ -236,7 +260,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$dir = strtolower(current($params['order']));
|
||||
}
|
||||
|
||||
if ($dir == 'desc') {
|
||||
if ($dir === 'desc') {
|
||||
return 'desc';
|
||||
}
|
||||
return 'asc';
|
||||
|
@ -247,9 +271,11 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `disabledTag` Tag to use instead of A tag when there is no previous page
|
||||
*
|
||||
* @param string $title Title for the link. Defaults to '<< Previous'.
|
||||
* @param array $options Options for pagination link. See #options for list of keys.
|
||||
|
@ -262,7 +288,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$defaults = array(
|
||||
'rel' => 'prev'
|
||||
);
|
||||
$options = array_merge($defaults, (array)$options);
|
||||
$options = (array)$options + $defaults;
|
||||
return $this->_pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
|
@ -271,34 +297,37 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
||||
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
||||
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `disabledTag` Tag to use instead of A tag when there is no next page
|
||||
*
|
||||
* @param string $title Title for the link. Defaults to 'Next >>'.
|
||||
* @param array $options Options for pagination link. See above for list of keys.
|
||||
* @param string $disabledTitle Title when the link is disabled.
|
||||
* @param array $disabledOptions Options for the disabled pagination link. See above for list of keys.
|
||||
* @return string A "next" link or or $disabledTitle text if the link is disabled.
|
||||
* @return string A "next" link or $disabledTitle text if the link is disabled.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::next
|
||||
*/
|
||||
public function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
$defaults = array(
|
||||
'rel' => 'next'
|
||||
);
|
||||
$options = array_merge($defaults, (array)$options);
|
||||
$options = (array)$options + $defaults;
|
||||
return $this->_pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
|
||||
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
|
||||
* direction switching automatically.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true.
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel().
|
||||
* - `direction` The default direction to use when this link isn't active.
|
||||
* - `lock` Lock direction. Will only use the default direction then, defaults to false.
|
||||
*
|
||||
* @param string $key The name of the key that the recordset should be sorted.
|
||||
* @param string $title Title for the link. If $title is null $key will be used
|
||||
|
@ -309,17 +338,25 @@ class PaginatorHelper extends AppHelper {
|
|||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sort
|
||||
*/
|
||||
public function sort($key, $title = null, $options = array()) {
|
||||
$options = array_merge(array('url' => array(), 'model' => null), $options);
|
||||
$options += array('url' => array(), 'model' => null);
|
||||
$url = $options['url'];
|
||||
unset($options['url']);
|
||||
|
||||
if (empty($title)) {
|
||||
$title = $key;
|
||||
|
||||
if (strpos($title, '.') !== false) {
|
||||
$title = str_replace('.', ' ', $title);
|
||||
}
|
||||
|
||||
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
|
||||
}
|
||||
$dir = isset($options['direction']) ? $options['direction'] : 'asc';
|
||||
$defaultDir = isset($options['direction']) ? strtolower($options['direction']) : 'asc';
|
||||
unset($options['direction']);
|
||||
|
||||
$locked = isset($options['lock']) ? $options['lock'] : false;
|
||||
unset($options['lock']);
|
||||
|
||||
$sortKey = $this->sortKey($options['model']);
|
||||
$defaultModel = $this->defaultModel();
|
||||
$isSorted = (
|
||||
|
@ -328,6 +365,7 @@ class PaginatorHelper extends AppHelper {
|
|||
$key === $defaultModel . '.' . $sortKey
|
||||
);
|
||||
|
||||
$dir = $defaultDir;
|
||||
if ($isSorted) {
|
||||
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
|
||||
$class = $dir === 'asc' ? 'desc' : 'asc';
|
||||
|
@ -336,6 +374,10 @@ class PaginatorHelper extends AppHelper {
|
|||
} else {
|
||||
$options['class'] = $class;
|
||||
}
|
||||
if ($locked) {
|
||||
$dir = $defaultDir;
|
||||
$options['class'] .= ' locked';
|
||||
}
|
||||
}
|
||||
if (is_array($title) && array_key_exists($dir, $title)) {
|
||||
$title = $title[$dir];
|
||||
|
@ -350,24 +392,24 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* ### Options
|
||||
*
|
||||
* - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
|
||||
* - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
|
||||
* with the AjaxHelper.
|
||||
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
||||
*
|
||||
* @param string $title Title for the link.
|
||||
* @param string|array $url Url for the action. See Router::url()
|
||||
* @param string|array $url URL for the action. See Router::url()
|
||||
* @param array $options Options for the link. See #options for list of keys.
|
||||
* @return string A link with pagination parameters.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link
|
||||
*/
|
||||
public function link($title, $url = array(), $options = array()) {
|
||||
$options = array_merge(array('model' => null, 'escape' => true), $options);
|
||||
$options += array('model' => null, 'escape' => true);
|
||||
$model = $options['model'];
|
||||
unset($options['model']);
|
||||
|
||||
if (!empty($this->options)) {
|
||||
$options = array_merge($this->options, $options);
|
||||
$options += $this->options;
|
||||
}
|
||||
if (isset($options['url'])) {
|
||||
$url = array_merge((array)$options['url'], (array)$url);
|
||||
|
@ -385,7 +427,7 @@ class PaginatorHelper extends AppHelper {
|
|||
* Merges passed URL options with current pagination state to generate a pagination URL.
|
||||
*
|
||||
* @param array $options Pagination/URL options array
|
||||
* @param boolean $asArray Return the url as an array, or a URI string
|
||||
* @param bool $asArray Return the URL as an array, or a URI string
|
||||
* @param string $model Which model to paginate on
|
||||
* @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::url
|
||||
|
@ -403,7 +445,12 @@ class PaginatorHelper extends AppHelper {
|
|||
$url = array_merge($url, compact('sort', 'direction'));
|
||||
}
|
||||
$url = $this->_convertUrlKeys($url, $paging['paramType']);
|
||||
|
||||
if (!empty($url['page']) && $url['page'] == 1) {
|
||||
$url['page'] = null;
|
||||
}
|
||||
if (!empty($url['?']['page']) && $url['?']['page'] == 1) {
|
||||
unset($url['?']['page']);
|
||||
}
|
||||
if ($asArray) {
|
||||
return $url;
|
||||
}
|
||||
|
@ -413,12 +460,12 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Converts the keys being used into the format set by options.paramType
|
||||
*
|
||||
* @param array $url Array of url params to convert
|
||||
* @param string $type
|
||||
* @return array converted url params.
|
||||
* @param array $url Array of URL params to convert
|
||||
* @param string $type Keys type.
|
||||
* @return array converted URL params.
|
||||
*/
|
||||
protected function _convertUrlKeys($url, $type) {
|
||||
if ($type == 'named') {
|
||||
if ($type === 'named') {
|
||||
return $url;
|
||||
}
|
||||
if (!isset($url['?'])) {
|
||||
|
@ -436,20 +483,20 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Protected method for generating prev/next links
|
||||
*
|
||||
* @param string $which
|
||||
* @param string $title
|
||||
* @param array $options
|
||||
* @param string $disabledTitle
|
||||
* @param array $disabledOptions
|
||||
* @param string $which Link type: 'Prev', 'Next'.
|
||||
* @param string $title Link title.
|
||||
* @param array $options Options list.
|
||||
* @param string $disabledTitle Disabled link title.
|
||||
* @param array $disabledOptions Disabled link options.
|
||||
* @return string
|
||||
*/
|
||||
protected function _pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
||||
$check = 'has' . $which;
|
||||
$_defaults = array(
|
||||
'url' => array(), 'step' => 1, 'escape' => true,
|
||||
'model' => null, 'tag' => 'span', 'class' => strtolower($which)
|
||||
'url' => array(), 'step' => 1, 'escape' => true, 'model' => null,
|
||||
'tag' => 'span', 'class' => strtolower($which), 'disabledTag' => null
|
||||
);
|
||||
$options = array_merge($_defaults, (array)$options);
|
||||
$options = (array)$options + $_defaults;
|
||||
$paging = $this->params($options['model']);
|
||||
if (empty($disabledOptions)) {
|
||||
$disabledOptions = $options;
|
||||
|
@ -459,30 +506,52 @@ class PaginatorHelper extends AppHelper {
|
|||
if (!empty($disabledTitle) && $disabledTitle !== true) {
|
||||
$title = $disabledTitle;
|
||||
}
|
||||
$options = array_merge($_defaults, (array)$disabledOptions);
|
||||
$options = (array)$disabledOptions + array_intersect_key($options, $_defaults) + $_defaults;
|
||||
} elseif (!$this->{$check}($options['model'])) {
|
||||
return null;
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach (array_keys($_defaults) as $key) {
|
||||
${$key} = $options[$key];
|
||||
unset($options[$key]);
|
||||
}
|
||||
$url = array_merge(array('page' => $paging['page'] + ($which == 'Prev' ? $step * -1 : $step)), $url);
|
||||
|
||||
if ($this->{$check}($model)) {
|
||||
return $this->Html->tag($tag, $this->link($title, $url, array_merge($options, compact('escape', 'model'))), compact('class'));
|
||||
} else {
|
||||
unset($options['rel']);
|
||||
return $this->Html->tag($tag, $title, array_merge($options, compact('escape', 'class')));
|
||||
$url = array_merge(
|
||||
array('page' => $paging['page'] + ($which === 'Prev' ? $step * -1 : $step)),
|
||||
$url
|
||||
);
|
||||
if ($tag === false) {
|
||||
return $this->link(
|
||||
$title,
|
||||
$url,
|
||||
compact('escape', 'model', 'class') + $options
|
||||
);
|
||||
}
|
||||
$link = $this->link($title, $url, compact('escape', 'model') + $options);
|
||||
return $this->Html->tag($tag, $link, compact('class'));
|
||||
}
|
||||
unset($options['rel']);
|
||||
if (!$tag) {
|
||||
if ($disabledTag) {
|
||||
$tag = $disabledTag;
|
||||
$disabledTag = null;
|
||||
} else {
|
||||
$tag = $_defaults['tag'];
|
||||
}
|
||||
}
|
||||
if ($disabledTag) {
|
||||
$title = $this->Html->tag($disabledTag, $title, compact('escape') + $options);
|
||||
return $this->Html->tag($tag, $title, compact('class'));
|
||||
}
|
||||
return $this->Html->tag($tag, $title, compact('escape', 'class') + $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given result set is not at the first page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return boolean True if the result set is not at the first page.
|
||||
* @return bool True if the result set is not at the first page.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPrev
|
||||
*/
|
||||
public function hasPrev($model = null) {
|
||||
|
@ -492,8 +561,8 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Returns true if the given result set is not at the last page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return boolean True if the result set is not at the last page.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @return bool True if the result set is not at the last page.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasNext
|
||||
*/
|
||||
public function hasNext($model = null) {
|
||||
|
@ -503,9 +572,9 @@ class PaginatorHelper extends AppHelper {
|
|||
/**
|
||||
* Returns true if the given result set has the page number given by $page
|
||||
*
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param integer $page The page number - if not set defaults to 1.
|
||||
* @return boolean True if the given result set has the specified page number.
|
||||
* @param string $model Optional model name. Uses the default if none is specified.
|
||||
* @param int $page The page number - if not set defaults to 1.
|
||||
* @return bool True if the given result set has the specified page number.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPage
|
||||
*/
|
||||
public function hasPage($model = null, $page = 1) {
|
||||
|
@ -521,27 +590,22 @@ class PaginatorHelper extends AppHelper {
|
|||
* Does $model have $page in its range?
|
||||
*
|
||||
* @param string $model Model name to get parameters for.
|
||||
* @param integer $page Page number you are checking.
|
||||
* @return boolean Whether model has $page
|
||||
* @param int $page Page number you are checking.
|
||||
* @return bool Whether model has $page
|
||||
*/
|
||||
protected function _hasPage($model, $page) {
|
||||
$params = $this->params($model);
|
||||
if (!empty($params)) {
|
||||
if ($params["{$page}Page"] == true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return !empty($params) && $params[$page . 'Page'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default model of the paged sets
|
||||
*
|
||||
* @return string Model name or null if the pagination isn't initialized.
|
||||
* @return string|null Model name or null if the pagination isn't initialized.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
|
||||
*/
|
||||
public function defaultModel() {
|
||||
if ($this->_defaultModel != null) {
|
||||
if ($this->_defaultModel) {
|
||||
return $this->_defaultModel;
|
||||
}
|
||||
if (empty($this->request->params['paging'])) {
|
||||
|
@ -558,15 +622,15 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* - `model` The model to use, defaults to PaginatorHelper::defaultModel();
|
||||
* - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
|
||||
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
|
||||
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
|
||||
* the following placeholders `{:page}`, `{:pages}`, `{:current}`, `{:count}`, `{:model}`, `{:start}`, `{:end}` and any
|
||||
* custom content you would like.
|
||||
* - `separator` The separator string to use, default to ' of '
|
||||
*
|
||||
* The `%page%` style placeholders also work, but are deprecated and will be removed in a future version.
|
||||
*
|
||||
* @param array $options Options for the counter string. See #options for list of keys.
|
||||
* @return string Counter string.
|
||||
* @deprecated The %page% style placeholders are deprecated.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::counter
|
||||
*/
|
||||
public function counter($options = array()) {
|
||||
|
@ -574,16 +638,14 @@ class PaginatorHelper extends AppHelper {
|
|||
$options = array('format' => $options);
|
||||
}
|
||||
|
||||
$options = array_merge(
|
||||
array(
|
||||
'model' => $this->defaultModel(),
|
||||
'format' => 'pages',
|
||||
'separator' => __d('cake', ' of ')
|
||||
),
|
||||
$options);
|
||||
$options += array(
|
||||
'model' => $this->defaultModel(),
|
||||
'format' => 'pages',
|
||||
'separator' => __d('cake', ' of ')
|
||||
);
|
||||
|
||||
$paging = $this->params($options['model']);
|
||||
if ($paging['pageCount'] == 0) {
|
||||
if (!$paging['pageCount']) {
|
||||
$paging['pageCount'] = 1;
|
||||
}
|
||||
$start = 0;
|
||||
|
@ -602,10 +664,10 @@ class PaginatorHelper extends AppHelper {
|
|||
}
|
||||
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
|
||||
$out .= $paging['count'];
|
||||
break;
|
||||
break;
|
||||
case 'pages':
|
||||
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
$map = array(
|
||||
'%page%' => $paging['page'],
|
||||
|
@ -622,7 +684,6 @@ class PaginatorHelper extends AppHelper {
|
|||
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}', '{:model}'
|
||||
);
|
||||
$out = str_replace($newKeys, array_values($map), $out);
|
||||
break;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
@ -644,15 +705,18 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Separator content defaults to ' | '
|
||||
* - `tag` The tag to wrap links in, defaults to 'span'
|
||||
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
|
||||
* links to generate.
|
||||
* links to generate. If a string is set a link to the first page will be generated with the value
|
||||
* as the title.
|
||||
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
|
||||
* links to generate.
|
||||
* links to generate. If a string is set a link to the last page will be generated with the value
|
||||
* as the title.
|
||||
* - `ellipsis` Ellipsis content, defaults to '...'
|
||||
* - `class` Class for wrapper tag
|
||||
* - `currentClass` Class for wrapper tag on current active page, defaults to 'current'
|
||||
* - `currentTag` Tag to use for current page number, defaults to null
|
||||
*
|
||||
* @param array $options Options for the numbers, (before, after, model, modulus, separator)
|
||||
* @return string numbers string.
|
||||
* @param array|bool $options Options for the numbers, (before, after, model, modulus, separator)
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::numbers
|
||||
*/
|
||||
public function numbers($options = array()) {
|
||||
|
@ -664,27 +728,27 @@ class PaginatorHelper extends AppHelper {
|
|||
|
||||
$defaults = array(
|
||||
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...', 'currentClass' => 'current'
|
||||
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
|
||||
'currentClass' => 'current', 'currentTag' => null
|
||||
);
|
||||
$options += $defaults;
|
||||
|
||||
$params = (array)$this->params($options['model']) + array('page' => 1);
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
if (empty($params['pageCount']) || $params['pageCount'] <= 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['after'], $options['model'],
|
||||
$options['modulus'], $options['separator'], $options['first'], $options['last'],
|
||||
$options['ellipsis'], $options['class'], $options['currentClass']
|
||||
$options['ellipsis'], $options['class'], $options['currentClass'], $options['currentTag']
|
||||
);
|
||||
|
||||
$out = '';
|
||||
|
||||
if ($modulus && $params['pageCount'] > $modulus) {
|
||||
$half = intval($modulus / 2);
|
||||
$half = (int)($modulus / 2);
|
||||
$end = $params['page'] + $half;
|
||||
|
||||
if ($end > $params['pageCount']) {
|
||||
|
@ -696,9 +760,10 @@ class PaginatorHelper extends AppHelper {
|
|||
$end = $params['page'] + ($modulus - $params['page']) + 1;
|
||||
}
|
||||
|
||||
$firstPage = is_int($first) ? $first : 0;
|
||||
if ($first && $start > 1) {
|
||||
$offset = ($start <= (int)$first) ? $start - 1 : $first;
|
||||
if ($offset < $start - 1) {
|
||||
$offset = ($start <= $firstPage) ? $start - 1 : $first;
|
||||
if ($firstPage < $start - 1) {
|
||||
$out .= $this->first($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
||||
} else {
|
||||
$out .= $this->first($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('after' => $separator));
|
||||
|
@ -714,7 +779,11 @@ class PaginatorHelper extends AppHelper {
|
|||
if ($class) {
|
||||
$currentClass .= ' ' . $class;
|
||||
}
|
||||
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
|
||||
if ($currentTag) {
|
||||
$out .= $this->Html->tag($tag, $this->Html->tag($currentTag, $params['page']), array('class' => $currentClass));
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
|
||||
}
|
||||
if ($i != $params['pageCount']) {
|
||||
$out .= $separator;
|
||||
}
|
||||
|
@ -731,8 +800,9 @@ class PaginatorHelper extends AppHelper {
|
|||
$out .= $after;
|
||||
|
||||
if ($last && $end < $params['pageCount']) {
|
||||
$offset = ($params['pageCount'] < $end + (int)$last) ? $params['pageCount'] - $end : $last;
|
||||
if ($offset <= $last && $params['pageCount'] - $end > $offset) {
|
||||
$lastPage = is_int($last) ? $last : 0;
|
||||
$offset = ($params['pageCount'] < $end + $lastPage) ? $params['pageCount'] - $end : $last;
|
||||
if ($offset <= $lastPage && $params['pageCount'] - $end > $lastPage) {
|
||||
$out .= $this->last($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
||||
} else {
|
||||
$out .= $this->last($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('before' => $separator));
|
||||
|
@ -747,7 +817,11 @@ class PaginatorHelper extends AppHelper {
|
|||
if ($class) {
|
||||
$currentClass .= ' ' . $class;
|
||||
}
|
||||
$out .= $this->Html->tag($tag, $i, array('class' => $currentClass));
|
||||
if ($currentTag) {
|
||||
$out .= $this->Html->tag($tag, $this->Html->tag($currentTag, $i), array('class' => $currentClass));
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $i, array('class' => $currentClass));
|
||||
}
|
||||
} else {
|
||||
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
|
||||
}
|
||||
|
@ -767,7 +841,7 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* `echo $this->Paginator->first('< first');`
|
||||
*
|
||||
* Creates a single link for the first page. Will output nothing if you are on the first page.
|
||||
* Creates a single link for the first page. Will output nothing if you are on the first page.
|
||||
*
|
||||
* `echo $this->Paginator->first(3);`
|
||||
*
|
||||
|
@ -782,36 +856,34 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
* - `ellipsis` Content for ellipsis, defaults to '...'
|
||||
*
|
||||
* @param string|integer $first if string use as label for the link. If numeric, the number of page links
|
||||
* @param string|int $first if string use as label for the link. If numeric, the number of page links
|
||||
* you want at the beginning of the range.
|
||||
* @param array $options An array of options.
|
||||
* @return string numbers string.
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::first
|
||||
*/
|
||||
public function first($first = '<< first', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'after' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
),
|
||||
(array)$options);
|
||||
$options = (array)$options + array(
|
||||
'tag' => 'span',
|
||||
'after' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
);
|
||||
|
||||
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
extract($options);
|
||||
unset($options['tag'], $options['after'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
||||
|
||||
$out = '';
|
||||
|
||||
if (is_int($first) && $params['page'] >= $first) {
|
||||
if ((is_int($first) || ctype_digit($first)) && $params['page'] >= $first) {
|
||||
if ($after === null) {
|
||||
$after = $ellipsis;
|
||||
}
|
||||
|
@ -834,11 +906,11 @@ class PaginatorHelper extends AppHelper {
|
|||
*
|
||||
* `echo $this->Paginator->last('last >');`
|
||||
*
|
||||
* Creates a single link for the last page. Will output nothing if you are on the last page.
|
||||
* Creates a single link for the last page. Will output nothing if you are on the last page.
|
||||
*
|
||||
* `echo $this->Paginator->last(3);`
|
||||
*
|
||||
* Will create links for the last 3 pages. Once you enter the page range, no output will be created.
|
||||
* Will create links for the last 3 pages. Once you enter the page range, no output will be created.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
|
@ -848,37 +920,35 @@ class PaginatorHelper extends AppHelper {
|
|||
* - `separator` Content between the generated links, defaults to ' | '
|
||||
* - `ellipsis` Content for ellipsis, defaults to '...'
|
||||
*
|
||||
* @param string|integer $last if string use as label for the link, if numeric print page numbers
|
||||
* @param string|int $last if string use as label for the link, if numeric print page numbers
|
||||
* @param array $options Array of options
|
||||
* @return string numbers string.
|
||||
* @return string Numbers string.
|
||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
|
||||
*/
|
||||
public function last($last = 'last >>', $options = array()) {
|
||||
$options = array_merge(
|
||||
array(
|
||||
'tag' => 'span',
|
||||
'before' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
),
|
||||
(array)$options);
|
||||
$options = (array)$options + array(
|
||||
'tag' => 'span',
|
||||
'before' => null,
|
||||
'model' => $this->defaultModel(),
|
||||
'separator' => ' | ',
|
||||
'ellipsis' => '...',
|
||||
'class' => null
|
||||
);
|
||||
|
||||
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
||||
unset($options['model']);
|
||||
|
||||
if ($params['pageCount'] <= 1) {
|
||||
return false;
|
||||
return '';
|
||||
}
|
||||
|
||||
extract($options);
|
||||
unset($options['tag'], $options['before'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
||||
|
||||
$out = '';
|
||||
$lower = $params['pageCount'] - $last + 1;
|
||||
$lower = $params['pageCount'] - (int)$last + 1;
|
||||
|
||||
if (is_int($last) && $params['page'] <= $lower) {
|
||||
if ((is_int($last) || ctype_digit($last)) && $params['page'] <= $lower) {
|
||||
if ($before === null) {
|
||||
$before = $ellipsis;
|
||||
}
|
||||
|
@ -898,4 +968,51 @@ class PaginatorHelper extends AppHelper {
|
|||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the meta-links for a paginated result set.
|
||||
*
|
||||
* `echo $this->Paginator->meta();`
|
||||
*
|
||||
* Echos the links directly, will output nothing if there is neither a previous nor next page.
|
||||
*
|
||||
* `$this->Paginator->meta(array('block' => true));`
|
||||
*
|
||||
* Will append the output of the meta function to the named block - if true is passed the "meta"
|
||||
* block is used.
|
||||
*
|
||||
* ### Options:
|
||||
*
|
||||
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
||||
* - `block` The block name to append the output to, or false/absent to return as a string
|
||||
*
|
||||
* @param array $options Array of options.
|
||||
* @return string|null Meta links.
|
||||
*/
|
||||
public function meta($options = array()) {
|
||||
$model = isset($options['model']) ? $options['model'] : null;
|
||||
$params = $this->params($model);
|
||||
$urlOptions = isset($this->options['url']) ? $this->options['url'] : array();
|
||||
$links = array();
|
||||
if ($this->hasPrev()) {
|
||||
$links[] = $this->Html->meta(array(
|
||||
'rel' => 'prev',
|
||||
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] - 1)), true)
|
||||
));
|
||||
}
|
||||
if ($this->hasNext()) {
|
||||
$links[] = $this->Html->meta(array(
|
||||
'rel' => 'next',
|
||||
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] + 1)), true)
|
||||
));
|
||||
}
|
||||
$out = implode($links);
|
||||
if (empty($options['block'])) {
|
||||
return $out;
|
||||
}
|
||||
if ($options['block'] === true) {
|
||||
$options['block'] = __FUNCTION__;
|
||||
}
|
||||
$this->_View->append($options['block'], $out);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue