2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Pagination Helper class file.
|
|
|
|
*
|
|
|
|
* Generates pagination links
|
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-04 18:10:24 +00:00
|
|
|
App::uses('AppHelper', 'View/Helper');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Pagination Helper class for easy generation of pagination links.
|
|
|
|
*
|
|
|
|
* PaginationHelper encloses all methods needed when working with pagination.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2011-08-01 00:28:35 +00:00
|
|
|
* @property HtmlHelper $Html
|
2011-10-15 17:06:19 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class PaginatorHelper extends AppHelper {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Helper dependencies
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $helpers = array('Html');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-09 21:32:29 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* The class used for 'Ajax' pagination links. Defaults to JsHelper. You should make sure
|
2010-12-29 03:18:31 +00:00
|
|
|
* that JsHelper is defined as a helper before PaginatorHelper, if you want to customize the JsHelper.
|
2009-08-09 21:32:29 +00:00
|
|
|
*
|
|
|
|
* @var string
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_ajaxHelperClass = 'Js';
|
2009-08-09 21:32:29 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds the default options for pagination links
|
|
|
|
*
|
|
|
|
* The values that may be specified are:
|
2009-03-12 17:11:08 +00:00
|
|
|
*
|
2010-12-29 03:18:31 +00:00
|
|
|
* - `format` Format of the counter. Supported formats are 'range' and 'pages'
|
2009-11-03 02:37:20 +00:00
|
|
|
* and custom (default). In the default mode the supplied string is parsed and constants are replaced
|
|
|
|
* by their actual values.
|
2010-12-29 03:18:31 +00:00
|
|
|
* placeholders: %page%, %pages%, %current%, %count%, %start%, %end% .
|
|
|
|
* - `separator` The separator of the actual page and number of pages (default: ' of ').
|
|
|
|
* - `url` Url of the action. See Router::url()
|
|
|
|
* - `url['sort']` the key that the recordset is sorted.
|
|
|
|
* - `url['direction']` Direction of the sorting (default: 'asc').
|
|
|
|
* - `url['page']` Page number to use in links.
|
|
|
|
* - `model` The name of the model.
|
|
|
|
* - `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.
|
2009-11-03 02:37:20 +00:00
|
|
|
* If this key isn't specified Paginator will use plain HTML links.
|
2012-12-22 22:48:15 +00:00
|
|
|
* - `paging['paramType']` The type of parameters to use when creating links. Valid options are
|
|
|
|
* 'querystring' and 'named'. See PaginatorComponent::$settings for more information.
|
2013-10-08 03:17:58 +00:00
|
|
|
* - `convertKeys` - A list of keys in URL arrays that should be converted to querysting params
|
2010-12-26 18:01:20 +00:00
|
|
|
* if paramType == 'querystring'.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-12-26 18:01:20 +00:00
|
|
|
public $options = array(
|
|
|
|
'convertKeys' => array('page', 'limit', 'sort', 'direction')
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-09 21:32:29 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the helper. Sets up the helper that is used for creating 'AJAX' links.
|
|
|
|
*
|
2010-04-04 07:14:00 +00:00
|
|
|
* Use `public $helpers = array('Paginator' => array('ajax' => 'CustomHelper'));` to set a custom Helper
|
2012-12-22 22:48:15 +00:00
|
|
|
* or choose a non JsHelper Helper. If you want to use a specific library with JsHelper declare JsHelper and its
|
2009-08-09 21:32:29 +00:00
|
|
|
* adapter before including PaginatorHelper in your helpers array.
|
|
|
|
*
|
2009-08-09 23:51:11 +00:00
|
|
|
* The chosen custom helper must implement a `link()` method.
|
|
|
|
*
|
2010-07-03 05:07:50 +00:00
|
|
|
* @param View $View the view object the helper is attached to.
|
|
|
|
* @param array $settings Array of settings.
|
2010-12-12 00:01:07 +00:00
|
|
|
* @throws CakeException When the AjaxProvider helper does not implement a link method.
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-08-19 02:16:16 +00:00
|
|
|
public function __construct(View $View, $settings = array()) {
|
2010-07-03 05:07:50 +00:00
|
|
|
$ajaxProvider = isset($settings['ajax']) ? $settings['ajax'] : 'Js';
|
2009-08-09 21:32:29 +00:00
|
|
|
$this->helpers[] = $ajaxProvider;
|
|
|
|
$this->_ajaxHelperClass = $ajaxProvider;
|
2010-12-05 02:36:53 +00:00
|
|
|
App::uses($ajaxProvider . 'Helper', 'View/Helper');
|
2009-08-31 15:38:31 +00:00
|
|
|
$classname = $ajaxProvider . 'Helper';
|
2012-01-07 22:06:03 +00:00
|
|
|
if (!class_exists($classname) || !method_exists($classname, 'link')) {
|
2013-08-16 09:39:38 +00:00
|
|
|
throw new CakeException(
|
2013-08-20 22:05:53 +00:00
|
|
|
__d('cake_dev', '%s does not implement a %s method, it is incompatible with %s', $classname, 'link()', 'PaginatorHelper')
|
2013-08-16 09:39:38 +00:00
|
|
|
);
|
2009-08-09 23:51:11 +00:00
|
|
|
}
|
2011-01-14 22:17:53 +00:00
|
|
|
parent::__construct($View, $settings);
|
2009-08-09 21:32:29 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 20:36:46 +00:00
|
|
|
/**
|
2013-10-08 03:17:58 +00:00
|
|
|
* Before render callback. Overridden to merge passed args with URL options.
|
2010-01-25 22:59:05 +00:00
|
|
|
*
|
2014-05-29 19:01:20 +00:00
|
|
|
* @param string $viewFile View file name.
|
2010-01-25 22:59:05 +00:00
|
|
|
* @return void
|
2009-10-31 20:36:46 +00:00
|
|
|
*/
|
2010-11-05 02:53:00 +00:00
|
|
|
public function beforeRender($viewFile) {
|
2010-05-14 04:32:56 +00:00
|
|
|
$this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']);
|
2012-03-03 04:46:15 +00:00
|
|
|
if (!empty($this->request->query)) {
|
|
|
|
$this->options['url']['?'] = $this->request->query;
|
|
|
|
}
|
2010-11-05 02:53:00 +00:00
|
|
|
parent::beforeRender($viewFile);
|
2009-10-31 20:36:46 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-08-02 18:55:37 +00:00
|
|
|
* Gets the current paging parameters from the resultset for the given model
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2015-03-18 02:18:50 +00:00
|
|
|
* @return array The array of paging parameters for the paginated resultset.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::params
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function params($model = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (empty($model)) {
|
|
|
|
$model = $this->defaultModel();
|
|
|
|
}
|
2010-05-14 04:32:56 +00:00
|
|
|
if (!isset($this->request->params['paging']) || empty($this->request->params['paging'][$model])) {
|
2015-03-18 02:18:50 +00:00
|
|
|
return array(
|
|
|
|
'prevPage' => false,
|
|
|
|
'nextPage' => true,
|
|
|
|
'paramType' => 'named',
|
|
|
|
'pageCount' => 1,
|
|
|
|
'options' => array(),
|
|
|
|
'page' => 1
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-05-14 04:32:56 +00:00
|
|
|
return $this->request->params['paging'][$model];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-06-23 22:03:08 +00:00
|
|
|
/**
|
|
|
|
* Convenience access to any of the paginator params.
|
|
|
|
*
|
2013-10-31 03:13:07 +00:00
|
|
|
* @param string $key Key of the paginator params array to retrieve.
|
2013-06-23 22:03:08 +00:00
|
|
|
* @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];
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Sets default options for all pagination links
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array|string $options Default options for pagination links. If a string is supplied - it
|
2010-01-25 22:59:05 +00:00
|
|
|
* is used as the DOM id element to update. See PaginatorHelper::$options for list of keys.
|
|
|
|
* @return void
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::options
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function options($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_string($options)) {
|
|
|
|
$options = array('update' => $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($options['paging'])) {
|
2010-05-14 04:32:56 +00:00
|
|
|
if (!isset($this->request->params['paging'])) {
|
|
|
|
$this->request->params['paging'] = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-05-14 04:32:56 +00:00
|
|
|
$this->request->params['paging'] = array_merge($this->request->params['paging'], $options['paging']);
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($options['paging']);
|
|
|
|
}
|
|
|
|
$model = $this->defaultModel();
|
|
|
|
|
|
|
|
if (!empty($options[$model])) {
|
2010-05-14 04:32:56 +00:00
|
|
|
if (!isset($this->request->params['paging'][$model])) {
|
|
|
|
$this->request->params['paging'][$model] = array();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-05-14 04:32:56 +00:00
|
|
|
$this->request->params['paging'][$model] = array_merge(
|
|
|
|
$this->request->params['paging'][$model], $options[$model]
|
2009-05-01 21:05:46 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($options[$model]);
|
|
|
|
}
|
2010-12-26 18:24:05 +00:00
|
|
|
if (!empty($options['convertKeys'])) {
|
|
|
|
$options['convertKeys'] = array_merge($this->options['convertKeys'], $options['convertKeys']);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->options = array_filter(array_merge($this->options, $options));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the current page of the recordset for the given model
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string The current page number of the recordset.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::current
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function current($model = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = $this->params($model);
|
|
|
|
|
|
|
|
if (isset($params['page'])) {
|
|
|
|
return $params['page'];
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the current key by which the recordset is sorted
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options Options for pagination links. See #options for list of keys.
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return string|null The name of the key by which the recordset is being sorted, or
|
2009-02-03 18:48:28 +00:00
|
|
|
* null if the results are not currently sorted.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sortKey
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function sortKey($model = null, $options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (empty($options)) {
|
|
|
|
$params = $this->params($model);
|
2010-12-19 17:26:28 +00:00
|
|
|
$options = $params['options'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if (isset($options['sort']) && !empty($options['sort'])) {
|
|
|
|
return $options['sort'];
|
2012-03-04 04:06:45 +00:00
|
|
|
}
|
|
|
|
if (isset($options['order'])) {
|
|
|
|
return is_array($options['order']) ? key($options['order']) : $options['order'];
|
|
|
|
}
|
|
|
|
if (isset($params['order'])) {
|
|
|
|
return is_array($params['order']) ? key($params['order']) : $params['order'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the current direction the recordset is sorted
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options Options for pagination links. See #options for list of keys.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string The direction by which the recordset is being sorted, or
|
2009-02-03 18:48:28 +00:00
|
|
|
* null if the results are not currently sorted.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sortDir
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function sortDir($model = null, $options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$dir = null;
|
|
|
|
|
|
|
|
if (empty($options)) {
|
|
|
|
$params = $this->params($model);
|
2010-12-19 17:26:28 +00:00
|
|
|
$options = $params['options'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($options['direction'])) {
|
|
|
|
$dir = strtolower($options['direction']);
|
|
|
|
} elseif (isset($options['order']) && is_array($options['order'])) {
|
|
|
|
$dir = strtolower(current($options['order']));
|
2012-03-04 04:19:50 +00:00
|
|
|
} elseif (isset($params['order']) && is_array($params['order'])) {
|
|
|
|
$dir = strtolower(current($params['order']));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 02:38:08 +00:00
|
|
|
if ($dir === 'desc') {
|
2008-05-30 11:40:08 +00:00
|
|
|
return 'desc';
|
|
|
|
}
|
|
|
|
return 'asc';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a "previous" link for a set of paged records
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options:
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2014-01-26 10:38:11 +00:00
|
|
|
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
2012-11-16 23:57:02 +00:00
|
|
|
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
2009-11-03 02:37:20 +00:00
|
|
|
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
|
|
|
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
2012-12-23 13:45:41 +00:00
|
|
|
* - `disabledTag` Tag to use instead of A tag when there is no previous page
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2011-07-29 02:45:47 +00:00
|
|
|
* @param string $title Title for the link. Defaults to '<< Previous'.
|
|
|
|
* @param array $options Options for pagination link. See #options for list of keys.
|
|
|
|
* @param string $disabledTitle Title when the link is disabled.
|
|
|
|
* @param array $disabledOptions Options for the disabled pagination link. See #options for list of keys.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string A "previous" link or $disabledTitle text if the link is disabled.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::prev
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function prev($title = '<< Previous', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
2010-02-19 09:27:16 +00:00
|
|
|
$defaults = array(
|
|
|
|
'rel' => 'prev'
|
|
|
|
);
|
2014-04-07 23:25:14 +00:00
|
|
|
$options = (array)$options + $defaults;
|
2011-08-20 05:39:30 +00:00
|
|
|
return $this->_pagingLink('Prev', $title, $options, $disabledTitle, $disabledOptions);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a "next" link for a set of paged records
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options:
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2014-01-26 10:38:11 +00:00
|
|
|
* - `url` Allows sending routing parameters such as controllers, actions or passed arguments.
|
2012-11-16 23:57:02 +00:00
|
|
|
* - `tag` The tag wrapping tag you want to use, defaults to 'span'. Set this to false to disable this option
|
2009-11-03 02:37:20 +00:00
|
|
|
* - `escape` Whether you want the contents html entity encoded, defaults to true
|
|
|
|
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
|
2012-12-23 13:45:41 +00:00
|
|
|
* - `disabledTag` Tag to use instead of A tag when there is no next page
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
|
|
|
* @param string $title Title for the link. Defaults to 'Next >>'.
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options Options for pagination link. See above for list of keys.
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param string $disabledTitle Title when the link is disabled.
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $disabledOptions Options for the disabled pagination link. See above for list of keys.
|
2012-12-23 13:45:41 +00:00
|
|
|
* @return string A "next" link or $disabledTitle text if the link is disabled.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::next
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function next($title = 'Next >>', $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
2010-02-19 09:27:16 +00:00
|
|
|
$defaults = array(
|
|
|
|
'rel' => 'next'
|
|
|
|
);
|
2014-04-07 23:25:14 +00:00
|
|
|
$options = (array)$options + $defaults;
|
2011-08-20 05:39:30 +00:00
|
|
|
return $this->_pagingLink('Next', $title, $options, $disabledTitle, $disabledOptions);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Generates a sorting link. Sets named parameters for the sort and direction. Handles
|
2009-10-27 17:28:43 +00:00
|
|
|
* direction switching automatically.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options:
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2013-10-19 10:44:50 +00:00
|
|
|
* - `escape` Whether you want the contents html entity encoded, defaults to true.
|
|
|
|
* - `model` The model to use, defaults to PaginatorHelper::defaultModel().
|
2011-12-02 05:58:09 +00:00
|
|
|
* - `direction` The default direction to use when this link isn't active.
|
2013-10-19 10:44:50 +00:00
|
|
|
* - `lock` Lock direction. Will only use the default direction then, defaults to false.
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2010-09-03 21:41:26 +00:00
|
|
|
* @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
|
|
|
|
* for the title and will be generated by inflection.
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param array $options Options for sorting link. See above for list of keys.
|
2009-03-12 17:11:08 +00:00
|
|
|
* @return string A link sorting default by 'asc'. If the resultset is sorted 'asc' by the specified
|
2009-02-03 18:48:28 +00:00
|
|
|
* key the returned link will sort by 'desc'.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::sort
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-09-03 21:41:26 +00:00
|
|
|
public function sort($key, $title = null, $options = array()) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$options += array('url' => array(), 'model' => null);
|
2008-05-30 11:40:08 +00:00
|
|
|
$url = $options['url'];
|
|
|
|
unset($options['url']);
|
|
|
|
|
2010-09-03 21:41:26 +00:00
|
|
|
if (empty($title)) {
|
|
|
|
$title = $key;
|
2012-12-17 03:55:03 +00:00
|
|
|
|
|
|
|
if (strpos($title, '.') !== false) {
|
|
|
|
$title = str_replace('.', ' ', $title);
|
|
|
|
}
|
|
|
|
|
2011-03-19 17:29:31 +00:00
|
|
|
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2015-10-26 22:20:30 +00:00
|
|
|
$defaultDir = isset($options['direction']) ? strtolower($options['direction']) : 'asc';
|
2009-08-27 03:55:19 +00:00
|
|
|
unset($options['direction']);
|
|
|
|
|
2013-10-19 10:44:50 +00:00
|
|
|
$locked = isset($options['lock']) ? $options['lock'] : false;
|
|
|
|
unset($options['lock']);
|
|
|
|
|
2009-03-22 18:59:53 +00:00
|
|
|
$sortKey = $this->sortKey($options['model']);
|
2010-05-17 03:42:14 +00:00
|
|
|
$defaultModel = $this->defaultModel();
|
|
|
|
$isSorted = (
|
2011-03-19 17:29:31 +00:00
|
|
|
$sortKey === $key ||
|
2010-05-17 03:42:14 +00:00
|
|
|
$sortKey === $defaultModel . '.' . $key ||
|
|
|
|
$key === $defaultModel . '.' . $sortKey
|
|
|
|
);
|
2009-03-22 18:59:53 +00:00
|
|
|
|
2013-10-19 10:44:50 +00:00
|
|
|
$dir = $defaultDir;
|
2009-08-27 03:33:13 +00:00
|
|
|
if ($isSorted) {
|
2009-11-17 01:11:23 +00:00
|
|
|
$dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc';
|
2009-08-27 03:33:13 +00:00
|
|
|
$class = $dir === 'asc' ? 'desc' : 'asc';
|
|
|
|
if (!empty($options['class'])) {
|
2010-05-11 19:12:02 +00:00
|
|
|
$options['class'] .= ' ' . $class;
|
2009-08-27 03:33:13 +00:00
|
|
|
} else {
|
|
|
|
$options['class'] = $class;
|
|
|
|
}
|
2013-10-19 10:44:50 +00:00
|
|
|
if ($locked) {
|
|
|
|
$dir = $defaultDir;
|
|
|
|
$options['class'] .= ' locked';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if (is_array($title) && array_key_exists($dir, $title)) {
|
|
|
|
$title = $title[$dir];
|
|
|
|
}
|
2009-03-12 17:11:08 +00:00
|
|
|
|
|
|
|
$url = array_merge(array('sort' => $key, 'direction' => $dir), $url, array('order' => null));
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->link($title, $url, $options);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a plain or Ajax link with pagination parameters
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* - `update` The Id of the DOM element you wish to update. Creates Ajax enabled links
|
2009-11-03 02:37:20 +00:00
|
|
|
* 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.
|
2013-10-08 03:17:58 +00:00
|
|
|
* @param string|array $url URL for the action. See Router::url()
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param array $options Options for the link. See #options for list of keys.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string A link with pagination parameters.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::link
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function link($title, $url = array(), $options = array()) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$options += array('model' => null, 'escape' => true);
|
2008-05-30 11:40:08 +00:00
|
|
|
$model = $options['model'];
|
|
|
|
unset($options['model']);
|
|
|
|
|
|
|
|
if (!empty($this->options)) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$options += $this->options;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if (isset($options['url'])) {
|
|
|
|
$url = array_merge((array)$options['url'], (array)$url);
|
|
|
|
unset($options['url']);
|
|
|
|
}
|
2010-12-26 18:01:20 +00:00
|
|
|
unset($options['convertKeys']);
|
2010-12-20 18:59:09 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$url = $this->url($url, true, $model);
|
|
|
|
|
2009-08-09 21:32:29 +00:00
|
|
|
$obj = isset($options['update']) ? $this->_ajaxHelperClass : 'Html';
|
2009-03-11 19:24:06 +00:00
|
|
|
return $this->{$obj}->link($title, $url, $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Merges passed URL options with current pagination state to generate a pagination URL.
|
|
|
|
*
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param array $options Pagination/URL options array
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $asArray Return the URL as an array, or a URI string
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param string $model Which model to paginate on
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return mixed By default, returns a full pagination URL string for use in non-standard contexts (i.e. JavaScript)
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::url
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function url($options = array(), $asArray = false, $model = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$paging = $this->params($model);
|
2010-12-19 17:43:29 +00:00
|
|
|
$url = array_merge(array_filter($paging['options']), $options);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if (isset($url['order'])) {
|
|
|
|
$sort = $direction = null;
|
|
|
|
if (is_array($url['order'])) {
|
|
|
|
list($sort, $direction) = array($this->sortKey($model, $url), current($url['order']));
|
|
|
|
}
|
|
|
|
unset($url['order']);
|
|
|
|
$url = array_merge($url, compact('sort', 'direction'));
|
|
|
|
}
|
2010-12-19 21:47:22 +00:00
|
|
|
$url = $this->_convertUrlKeys($url, $paging['paramType']);
|
2013-07-16 22:45:27 +00:00
|
|
|
if (!empty($url['page']) && $url['page'] == 1) {
|
2013-07-18 14:48:34 +00:00
|
|
|
$url['page'] = null;
|
2013-07-16 22:45:27 +00:00
|
|
|
}
|
|
|
|
if (!empty($url['?']['page']) && $url['?']['page'] == 1) {
|
|
|
|
unset($url['?']['page']);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($asArray) {
|
|
|
|
return $url;
|
|
|
|
}
|
2008-06-11 12:18:54 +00:00
|
|
|
return parent::url($url);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-19 21:47:22 +00:00
|
|
|
/**
|
|
|
|
* Converts the keys being used into the format set by options.paramType
|
|
|
|
*
|
2013-10-08 03:17:58 +00:00
|
|
|
* @param array $url Array of URL params to convert
|
2014-05-29 19:01:20 +00:00
|
|
|
* @param string $type Keys type.
|
2013-10-08 03:17:58 +00:00
|
|
|
* @return array converted URL params.
|
2010-12-19 21:47:22 +00:00
|
|
|
*/
|
|
|
|
protected function _convertUrlKeys($url, $type) {
|
2013-02-12 02:38:08 +00:00
|
|
|
if ($type === 'named') {
|
2010-12-20 04:11:02 +00:00
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
if (!isset($url['?'])) {
|
|
|
|
$url['?'] = array();
|
2010-12-19 21:47:22 +00:00
|
|
|
}
|
2010-12-26 18:01:20 +00:00
|
|
|
foreach ($this->options['convertKeys'] as $key) {
|
2010-12-19 21:47:22 +00:00
|
|
|
if (isset($url[$key])) {
|
2010-12-20 04:11:02 +00:00
|
|
|
$url['?'][$key] = $url[$key];
|
2010-12-19 21:47:22 +00:00
|
|
|
unset($url[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Protected method for generating prev/next links
|
|
|
|
*
|
2014-05-29 19:01:20 +00:00
|
|
|
* @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.
|
2014-11-08 19:07:47 +00:00
|
|
|
* @return string
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _pagingLink($which, $title = null, $options = array(), $disabledTitle = null, $disabledOptions = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$check = 'has' . $which;
|
2009-08-27 02:55:24 +00:00
|
|
|
$_defaults = array(
|
2012-12-23 13:45:41 +00:00
|
|
|
'url' => array(), 'step' => 1, 'escape' => true, 'model' => null,
|
|
|
|
'tag' => 'span', 'class' => strtolower($which), 'disabledTag' => null
|
2009-08-27 02:55:24 +00:00
|
|
|
);
|
2014-04-07 23:25:14 +00:00
|
|
|
$options = (array)$options + $_defaults;
|
2008-05-30 11:40:08 +00:00
|
|
|
$paging = $this->params($options['model']);
|
2009-09-15 03:06:24 +00:00
|
|
|
if (empty($disabledOptions)) {
|
|
|
|
$disabledOptions = $options;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-01-14 22:08:11 +00:00
|
|
|
if (!$this->{$check}($options['model']) && (!empty($disabledTitle) || !empty($disabledOptions))) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!empty($disabledTitle) && $disabledTitle !== true) {
|
|
|
|
$title = $disabledTitle;
|
|
|
|
}
|
2014-11-05 02:15:43 +00:00
|
|
|
$options = (array)$disabledOptions + array_intersect_key($options, $_defaults) + $_defaults;
|
2008-07-24 04:04:21 +00:00
|
|
|
} elseif (!$this->{$check}($options['model'])) {
|
2014-11-08 19:07:47 +00:00
|
|
|
return '';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (array_keys($_defaults) as $key) {
|
|
|
|
${$key} = $options[$key];
|
|
|
|
unset($options[$key]);
|
|
|
|
}
|
|
|
|
|
2008-07-24 04:04:21 +00:00
|
|
|
if ($this->{$check}($model)) {
|
2012-12-23 13:45:41 +00:00
|
|
|
$url = array_merge(
|
2013-02-12 02:38:08 +00:00
|
|
|
array('page' => $paging['page'] + ($which === 'Prev' ? $step * -1 : $step)),
|
2012-12-23 13:45:41 +00:00
|
|
|
$url
|
|
|
|
);
|
2012-11-16 23:57:02 +00:00
|
|
|
if ($tag === false) {
|
2012-12-23 13:45:41 +00:00
|
|
|
return $this->link(
|
|
|
|
$title,
|
|
|
|
$url,
|
|
|
|
compact('escape', 'model', 'class') + $options
|
|
|
|
);
|
2012-11-16 23:57:02 +00:00
|
|
|
}
|
2012-12-23 13:45:41 +00:00
|
|
|
$link = $this->link($title, $url, compact('escape', 'model') + $options);
|
|
|
|
return $this->Html->tag($tag, $link, compact('class'));
|
2013-07-02 23:14:41 +00:00
|
|
|
}
|
|
|
|
unset($options['rel']);
|
|
|
|
if (!$tag) {
|
2012-12-23 13:45:41 +00:00
|
|
|
if ($disabledTag) {
|
2013-07-02 23:14:41 +00:00
|
|
|
$tag = $disabledTag;
|
|
|
|
$disabledTag = null;
|
|
|
|
} else {
|
|
|
|
$tag = $_defaults['tag'];
|
2012-12-23 13:45:41 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2013-07-02 23:14:41 +00:00
|
|
|
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);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given result set is not at the first page
|
|
|
|
*
|
2009-11-03 02:37:20 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if the result set is not at the first page.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPrev
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function hasPrev($model = null) {
|
2011-08-20 05:39:30 +00:00
|
|
|
return $this->_hasPage($model, 'prev');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given result set is not at the last page
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if the result set is not at the last page.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasNext
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function hasNext($model = null) {
|
2011-08-20 05:39:30 +00:00
|
|
|
return $this->_hasPage($model, 'next');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given result set has the page number given by $page
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* @param string $model Optional model name. Uses the default if none is specified.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @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.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::hasPage
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function hasPage($model = null, $page = 1) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_numeric($model)) {
|
|
|
|
$page = $model;
|
|
|
|
$model = null;
|
|
|
|
}
|
|
|
|
$paging = $this->params($model);
|
|
|
|
return $page <= $paging['pageCount'];
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 22:59:05 +00:00
|
|
|
* Does $model have $page in its range?
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* @param string $model Model name to get parameters for.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int $page Page number you are checking.
|
|
|
|
* @return bool Whether model has $page
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-08-20 05:39:30 +00:00
|
|
|
protected function _hasPage($model, $page) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$params = $this->params($model);
|
2012-09-14 17:54:29 +00:00
|
|
|
return !empty($params) && $params[$page . 'Page'];
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Gets the default model of the paged sets
|
|
|
|
*
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return string|null Model name or null if the pagination isn't initialized.
|
2011-11-30 05:23:02 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::defaultModel
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function defaultModel() {
|
2012-09-21 22:30:43 +00:00
|
|
|
if ($this->_defaultModel) {
|
2011-08-20 04:43:34 +00:00
|
|
|
return $this->_defaultModel;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-05-14 04:32:56 +00:00
|
|
|
if (empty($this->request->params['paging'])) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return null;
|
|
|
|
}
|
2011-08-20 04:43:34 +00:00
|
|
|
list($this->_defaultModel) = array_keys($this->request->params['paging']);
|
|
|
|
return $this->_defaultModel;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a counter string for the paged result set
|
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
|
|
|
* - `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'
|
2012-12-22 22:48:15 +00:00
|
|
|
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
|
2011-09-05 17:33:21 +00:00
|
|
|
* the following placeholders `{:page}`, `{:pages}`, `{:current}`, `{:count}`, `{:model}`, `{:start}`, `{:end}` and any
|
2009-11-03 02:37:20 +00:00
|
|
|
* custom content you would like.
|
|
|
|
* - `separator` The separator string to use, default to ' of '
|
|
|
|
*
|
2011-09-05 17:33:21 +00:00
|
|
|
* The `%page%` style placeholders also work, but are deprecated and will be removed in a future version.
|
2014-05-29 19:01:20 +00:00
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options Options for the counter string. See #options for list of keys.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Counter string.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::counter
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function counter($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_string($options)) {
|
|
|
|
$options = array('format' => $options);
|
|
|
|
}
|
|
|
|
|
2014-04-07 23:25:14 +00:00
|
|
|
$options += array(
|
|
|
|
'model' => $this->defaultModel(),
|
|
|
|
'format' => 'pages',
|
|
|
|
'separator' => __d('cake', ' of ')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$paging = $this->params($options['model']);
|
2012-09-14 17:42:25 +00:00
|
|
|
if (!$paging['pageCount']) {
|
2008-07-30 20:34:01 +00:00
|
|
|
$paging['pageCount'] = 1;
|
|
|
|
}
|
|
|
|
$start = 0;
|
|
|
|
if ($paging['count'] >= 1) {
|
2010-12-19 18:15:04 +00:00
|
|
|
$start = (($paging['page'] - 1) * $paging['limit']) + 1;
|
2008-07-30 20:34:01 +00:00
|
|
|
}
|
2010-12-19 18:15:04 +00:00
|
|
|
$end = $start + $paging['limit'] - 1;
|
2008-07-30 20:34:01 +00:00
|
|
|
if ($paging['count'] < $end) {
|
|
|
|
$end = $paging['count'];
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
switch ($options['format']) {
|
|
|
|
case 'range':
|
|
|
|
if (!is_array($options['separator'])) {
|
|
|
|
$options['separator'] = array(' - ', $options['separator']);
|
|
|
|
}
|
2009-05-01 21:05:46 +00:00
|
|
|
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
|
|
|
|
$out .= $paging['count'];
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
case 'pages':
|
|
|
|
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
default:
|
2009-02-07 13:41:15 +00:00
|
|
|
$map = array(
|
2008-05-30 11:40:08 +00:00
|
|
|
'%page%' => $paging['page'],
|
|
|
|
'%pages%' => $paging['pageCount'],
|
|
|
|
'%current%' => $paging['current'],
|
|
|
|
'%count%' => $paging['count'],
|
|
|
|
'%start%' => $start,
|
2011-06-19 21:05:28 +00:00
|
|
|
'%end%' => $end,
|
|
|
|
'%model%' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))
|
2008-05-30 11:40:08 +00:00
|
|
|
);
|
2009-02-07 13:41:15 +00:00
|
|
|
$out = str_replace(array_keys($map), array_values($map), $options['format']);
|
|
|
|
|
|
|
|
$newKeys = array(
|
2011-06-19 21:05:28 +00:00
|
|
|
'{:page}', '{:pages}', '{:current}', '{:count}', '{:start}', '{:end}', '{:model}'
|
2009-02-07 13:41:15 +00:00
|
|
|
);
|
|
|
|
$out = str_replace($newKeys, array_values($map), $out);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-21 21:43:54 +00:00
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a set of numbers for the paged result set
|
2011-03-19 17:29:31 +00:00
|
|
|
* uses a modulus to decide how many numbers to show on each side of the current page (default: 8).
|
2010-12-28 05:09:47 +00:00
|
|
|
*
|
|
|
|
* `$this->Paginator->numbers(array('first' => 2, 'last' => 2));`
|
|
|
|
*
|
|
|
|
* Using the first and last options you can create links to the beginning and end of the page set.
|
2011-03-19 17:29:31 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
|
|
|
* - `before` Content to be inserted before the numbers
|
|
|
|
* - `after` Content to be inserted after the numbers
|
|
|
|
* - `model` Model to create numbers for, defaults to PaginatorHelper::defaultModel()
|
|
|
|
* - `modulus` how many numbers to include on either side of the current page, defaults to 8.
|
|
|
|
* - `separator` Separator content defaults to ' | '
|
|
|
|
* - `tag` The tag to wrap links in, defaults to 'span'
|
2010-02-07 18:26:50 +00:00
|
|
|
* - `first` Whether you want first links generated, set to an integer to define the number of 'first'
|
2015-12-27 03:52:17 +00:00
|
|
|
* links to generate. If a string is set a link to the first page will be generated with the value
|
|
|
|
* as the title.
|
2010-02-07 18:26:50 +00:00
|
|
|
* - `last` Whether you want last links generated, set to an integer to define the number of 'last'
|
2015-12-27 03:52:17 +00:00
|
|
|
* links to generate. If a string is set a link to the last page will be generated with the value
|
|
|
|
* as the title.
|
2010-11-08 01:08:01 +00:00
|
|
|
* - `ellipsis` Ellipsis content, defaults to '...'
|
2012-01-28 17:24:28 +00:00
|
|
|
* - `class` Class for wrapper tag
|
|
|
|
* - `currentClass` Class for wrapper tag on current active page, defaults to 'current'
|
2012-10-12 14:43:45 +00:00
|
|
|
* - `currentTag` Tag to use for current page number, defaults to null
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2015-01-16 13:11:32 +00:00
|
|
|
* @param array|bool $options Options for the numbers, (before, after, model, modulus, separator)
|
2014-11-08 19:07:47 +00:00
|
|
|
* @return string Numbers string.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::numbers
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function numbers($options = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($options === true) {
|
|
|
|
$options = array(
|
2009-02-07 13:41:15 +00:00
|
|
|
'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 13:41:15 +00:00
|
|
|
$defaults = array(
|
2011-08-13 23:39:57 +00:00
|
|
|
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
|
2012-10-12 14:43:45 +00:00
|
|
|
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
|
|
|
|
'currentClass' => 'current', 'currentTag' => null
|
2009-02-07 13:41:15 +00:00
|
|
|
);
|
|
|
|
$options += $defaults;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$params = (array)$this->params($options['model']) + array('page' => 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($options['model']);
|
|
|
|
|
2015-01-16 13:11:32 +00:00
|
|
|
if (empty($params['pageCount']) || $params['pageCount'] <= 1) {
|
2014-11-08 19:07:47 +00:00
|
|
|
return '';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract($options);
|
2008-07-31 16:58:57 +00:00
|
|
|
unset($options['tag'], $options['before'], $options['after'], $options['model'],
|
2010-11-08 01:08:01 +00:00
|
|
|
$options['modulus'], $options['separator'], $options['first'], $options['last'],
|
2012-10-12 14:43:45 +00:00
|
|
|
$options['ellipsis'], $options['class'], $options['currentClass'], $options['currentTag']
|
2010-11-08 01:08:01 +00:00
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out = '';
|
|
|
|
|
|
|
|
if ($modulus && $params['pageCount'] > $modulus) {
|
2014-09-10 14:29:23 +00:00
|
|
|
$half = (int)($modulus / 2);
|
2008-05-30 11:40:08 +00:00
|
|
|
$end = $params['page'] + $half;
|
|
|
|
|
|
|
|
if ($end > $params['pageCount']) {
|
|
|
|
$end = $params['pageCount'];
|
|
|
|
}
|
|
|
|
$start = $params['page'] - ($modulus - ($end - $params['page']));
|
|
|
|
if ($start <= 1) {
|
|
|
|
$start = 1;
|
2012-03-03 22:10:12 +00:00
|
|
|
$end = $params['page'] + ($modulus - $params['page']) + 1;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-27 03:52:17 +00:00
|
|
|
$firstPage = is_int($first) ? $first : 0;
|
2009-07-28 12:40:31 +00:00
|
|
|
if ($first && $start > 1) {
|
2015-12-27 03:52:17 +00:00
|
|
|
$offset = ($start <= $firstPage) ? $start - 1 : $first;
|
|
|
|
if ($firstPage < $start - 1) {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->first($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
2009-07-28 12:40:31 +00:00
|
|
|
} else {
|
2012-07-11 01:16:56 +00:00
|
|
|
$out .= $this->first($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('after' => $separator));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$out .= $before;
|
|
|
|
|
|
|
|
for ($i = $start; $i < $params['page']; $i++) {
|
2012-03-03 22:10:12 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) . $separator;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2011-08-13 23:39:57 +00:00
|
|
|
if ($class) {
|
|
|
|
$currentClass .= ' ' . $class;
|
|
|
|
}
|
2012-10-12 14:43:45 +00:00
|
|
|
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));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($i != $params['pageCount']) {
|
|
|
|
$out .= $separator;
|
|
|
|
}
|
|
|
|
|
|
|
|
$start = $params['page'] + 1;
|
|
|
|
for ($i = $start; $i < $end; $i++) {
|
2012-03-03 22:10:12 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class')) . $separator;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($end != $params['page']) {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $end), $options), compact('class'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$out .= $after;
|
|
|
|
|
2009-07-28 12:40:31 +00:00
|
|
|
if ($last && $end < $params['pageCount']) {
|
2015-12-27 03:52:17 +00:00
|
|
|
$lastPage = is_int($last) ? $last : 0;
|
|
|
|
$offset = ($params['pageCount'] < $end + $lastPage) ? $params['pageCount'] - $end : $last;
|
|
|
|
if ($offset <= $lastPage && $params['pageCount'] - $end > $lastPage) {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->last($offset, compact('tag', 'separator', 'ellipsis', 'class'));
|
2009-07-28 12:40:31 +00:00
|
|
|
} else {
|
2012-07-11 01:16:56 +00:00
|
|
|
$out .= $this->last($offset, compact('tag', 'separator', 'class', 'ellipsis') + array('before' => $separator));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$out .= $before;
|
|
|
|
|
|
|
|
for ($i = 1; $i <= $params['pageCount']; $i++) {
|
|
|
|
if ($i == $params['page']) {
|
2011-08-13 23:39:57 +00:00
|
|
|
if ($class) {
|
|
|
|
$currentClass .= ' ' . $class;
|
|
|
|
}
|
2012-10-14 13:14:10 +00:00
|
|
|
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));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
if ($i != $params['pageCount']) {
|
|
|
|
$out .= $separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$out .= $after;
|
|
|
|
}
|
|
|
|
|
2009-11-21 21:43:54 +00:00
|
|
|
return $out;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-12-28 04:30:10 +00:00
|
|
|
* Returns a first or set of numbers for the first pages.
|
|
|
|
*
|
|
|
|
* `echo $this->Paginator->first('< first');`
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* Creates a single link for the first page. Will output nothing if you are on the first page.
|
2010-12-28 04:30:10 +00:00
|
|
|
*
|
|
|
|
* `echo $this->Paginator->first(3);`
|
|
|
|
*
|
|
|
|
* Will create links for the first 3 pages, once you get to the third or greater page. Prior to that
|
|
|
|
* nothing will be output.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options:
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
|
|
|
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
2010-12-27 15:40:21 +00:00
|
|
|
* - `after` Content to insert after the link/tag
|
2009-11-03 02:37:20 +00:00
|
|
|
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
|
|
|
* - `separator` Content between the generated links, defaults to ' | '
|
2010-11-08 01:08:01 +00:00
|
|
|
* - `ellipsis` Content for ellipsis, defaults to '...'
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param string|int $first if string use as label for the link. If numeric, the number of page links
|
2010-12-28 04:30:10 +00:00
|
|
|
* you want at the beginning of the range.
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options An array of options.
|
2014-11-08 19:07:47 +00:00
|
|
|
* @return string Numbers string.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::first
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function first($first = '<< first', $options = array()) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$options = (array)$options + array(
|
|
|
|
'tag' => 'span',
|
|
|
|
'after' => null,
|
|
|
|
'model' => $this->defaultModel(),
|
|
|
|
'separator' => ' | ',
|
|
|
|
'ellipsis' => '...',
|
|
|
|
'class' => null
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-12-27 15:48:38 +00:00
|
|
|
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($options['model']);
|
|
|
|
|
|
|
|
if ($params['pageCount'] <= 1) {
|
2014-11-08 19:07:47 +00:00
|
|
|
return '';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
extract($options);
|
2011-08-13 23:39:57 +00:00
|
|
|
unset($options['tag'], $options['after'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$out = '';
|
|
|
|
|
2015-12-27 03:52:17 +00:00
|
|
|
if ((is_int($first) || ctype_digit($first)) && $params['page'] >= $first) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($after === null) {
|
2010-11-08 01:08:01 +00:00
|
|
|
$after = $ellipsis;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
for ($i = 1; $i <= $first; $i++) {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($i != $first) {
|
|
|
|
$out .= $separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out .= $after;
|
2010-12-28 04:40:10 +00:00
|
|
|
} elseif ($params['page'] > 1 && is_string($first)) {
|
2010-12-27 15:48:38 +00:00
|
|
|
$options += array('rel' => 'first');
|
2012-03-03 22:10:12 +00:00
|
|
|
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options), compact('class')) . $after;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-12-28 04:30:10 +00:00
|
|
|
* Returns a last or set of numbers for the last pages.
|
|
|
|
*
|
|
|
|
* `echo $this->Paginator->last('last >');`
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* Creates a single link for the last page. Will output nothing if you are on the last page.
|
2010-12-28 04:30:10 +00:00
|
|
|
*
|
|
|
|
* `echo $this->Paginator->last(3);`
|
|
|
|
*
|
2012-12-22 22:48:15 +00:00
|
|
|
* Will create links for the last 3 pages. Once you enter the page range, no output will be created.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 22:59:05 +00:00
|
|
|
* ### Options:
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
|
|
|
* - `tag` The tag wrapping tag you want to use, defaults to 'span'
|
|
|
|
* - `before` Content to insert before the link/tag
|
|
|
|
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
|
|
|
* - `separator` Content between the generated links, defaults to ' | '
|
2010-11-08 01:08:01 +00:00
|
|
|
* - `ellipsis` Content for ellipsis, defaults to '...'
|
2009-11-03 02:37:20 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param string|int $last if string use as label for the link, if numeric print page numbers
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param array $options Array of options
|
2014-11-08 19:07:47 +00:00
|
|
|
* @return string Numbers string.
|
2011-11-14 06:08:20 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html#PaginatorHelper::last
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function last($last = 'last >>', $options = array()) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$options = (array)$options + array(
|
|
|
|
'tag' => 'span',
|
|
|
|
'before' => null,
|
|
|
|
'model' => $this->defaultModel(),
|
|
|
|
'separator' => ' | ',
|
|
|
|
'ellipsis' => '...',
|
|
|
|
'class' => null
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$params = array_merge(array('page' => 1), (array)$this->params($options['model']));
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($options['model']);
|
|
|
|
|
|
|
|
if ($params['pageCount'] <= 1) {
|
2014-11-08 19:07:47 +00:00
|
|
|
return '';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract($options);
|
2011-08-13 23:39:57 +00:00
|
|
|
unset($options['tag'], $options['before'], $options['model'], $options['separator'], $options['ellipsis'], $options['class']);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$out = '';
|
|
|
|
$lower = $params['pageCount'] - $last + 1;
|
|
|
|
|
2015-12-27 03:52:17 +00:00
|
|
|
if ((is_int($last) || ctype_digit($last)) && $params['page'] <= $lower) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($before === null) {
|
2010-11-08 01:08:01 +00:00
|
|
|
$before = $ellipsis;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
for ($i = $lower; $i <= $params['pageCount']; $i++) {
|
2011-08-13 23:39:57 +00:00
|
|
|
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options), compact('class'));
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($i != $params['pageCount']) {
|
|
|
|
$out .= $separator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$out = $before . $out;
|
2010-12-28 04:40:10 +00:00
|
|
|
} elseif ($params['page'] < $params['pageCount'] && is_string($last)) {
|
2010-12-27 15:48:38 +00:00
|
|
|
$options += array('rel' => 'last');
|
2009-05-01 21:05:46 +00:00
|
|
|
$out = $before . $this->Html->tag(
|
2011-08-13 23:39:57 +00:00
|
|
|
$tag, $this->link($last, array('page' => $params['pageCount']), $options), compact('class')
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $out;
|
|
|
|
}
|
2012-03-03 22:10:12 +00:00
|
|
|
|
2014-11-02 21:29:02 +00:00
|
|
|
/**
|
2014-11-02 21:41:17 +00:00
|
|
|
* Returns the meta-links for a paginated result set.
|
2014-11-02 21:29:02 +00:00
|
|
|
*
|
|
|
|
* `echo $this->Paginator->meta();`
|
|
|
|
*
|
2014-11-02 21:41:17 +00:00
|
|
|
* Echos the links directly, will output nothing if there is neither a previous nor next page.
|
2014-11-02 21:29:02 +00:00
|
|
|
*
|
|
|
|
* `$this->Paginator->meta(array('block' => true));`
|
|
|
|
*
|
|
|
|
* Will append the output of the meta function to the named block - if true is passed the "meta"
|
2014-11-02 21:41:17 +00:00
|
|
|
* block is used.
|
2014-11-02 21:29:02 +00:00
|
|
|
*
|
|
|
|
* ### Options:
|
|
|
|
*
|
|
|
|
* - `model` The model to use defaults to PaginatorHelper::defaultModel()
|
2015-10-10 13:49:00 +00:00
|
|
|
* - `block` The block name to append the output to, or false/absent to return as a string
|
2014-11-02 21:29:02 +00:00
|
|
|
*
|
2015-10-10 13:49:00 +00:00
|
|
|
* @param array $options Array of options.
|
|
|
|
* @return string|null Meta links.
|
2014-11-02 21:29:02 +00:00
|
|
|
*/
|
|
|
|
public function meta($options = array()) {
|
|
|
|
$model = isset($options['model']) ? $options['model'] : null;
|
|
|
|
$params = $this->params($model);
|
2015-10-07 11:37:37 +00:00
|
|
|
$urlOptions = isset($this->options['url']) ? $this->options['url'] : array();
|
2014-11-02 21:29:02 +00:00
|
|
|
$links = array();
|
|
|
|
if ($this->hasPrev()) {
|
|
|
|
$links[] = $this->Html->meta(array(
|
|
|
|
'rel' => 'prev',
|
2015-10-07 11:37:37 +00:00
|
|
|
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] - 1)), true)
|
2014-11-02 21:29:02 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
if ($this->hasNext()) {
|
|
|
|
$links[] = $this->Html->meta(array(
|
|
|
|
'rel' => 'next',
|
2015-10-07 11:37:37 +00:00
|
|
|
'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] + 1)), true)
|
2014-11-02 21:29:02 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
$out = implode($links);
|
|
|
|
if (empty($options['block'])) {
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
if ($options['block'] === true) {
|
|
|
|
$options['block'] = __FUNCTION__;
|
|
|
|
}
|
|
|
|
$this->_View->append($options['block'], $out);
|
|
|
|
}
|
|
|
|
|
2011-06-19 21:05:28 +00:00
|
|
|
}
|