/** * Cleans up columns titles * @param string $key * @param null $title * @param array $options * @return string */ public function sort($key, $title = null, $options = array()) { if (!empty($this->request->params['admin'])) { if (empty($title)) { $title = $key; $title = __d('admin', Inflector::humanize(preg_replace('/_id$/', '', $title))); } } return parent::sort($key, $title, $options); }
/** * Adds and 'asc' or 'desc' class to the sort links * @see /cake/libs/view/helpers/PaginatorHelper#sort($title, $key, $options) */ public function sort($key, $title = null, $options = array()) { // get current sort key & direction $sortKey = $this->sortKey(); $sortDir = $this->sortDir(); // add $sortDir class if current column is sort column if ($sortKey == $key && $key !== null) { $options['class'] = $sortDir; } return parent::sort($key, $title, $options); }
/** * Prepara e retorna/imprime os controles de navegação * * O primeiro parâmetro corresponde a uma referência a classe PaginatorHelper * instanciada pelo controlador, enquanto o segundo parâmetro é um array com as opções * de saída. * * * @param PaginatorHelper $paginator * @param array $options Possui dois índices reconhecidos: * - 'return' do tipo bool, se true faz o método retornar o resultado ao invés de imprimir. * Valor padrão é false * - 'filters' do tipo array que contém as condições para a paginação, acrescido de todos * os parâmetros passados via url */ public function controls(&$paginator, $options = array()) { $this->_paginator =& $paginator; if (!empty($options['filters']) && is_array($options['filters'])) { $filters['url'] = array_merge($options['filters'], $this->params['pass']); } else { $filters['url'] = $this->params['pass']; } $options = Set::merge($filters, $this->_paginator->options); $this->_paginator->options($options); $out = $this->_paginator->first('<< ' . __d('r_search', 'first', true), array(), null, array('class' => 'disabled')) . $this->_paginator->prev(__d('r_search', 'previous', true), array(), null, array('class' => 'disabled')) . $this->_paginator->numbers(array('separator' => '')) . $this->_paginator->next(__d('r_search', 'next', true), array(), null, array('class' => 'disabled')) . $this->_paginator->last(__d('r_search', 'last', true) . ' >>', array(), null, array('class' => 'disabled')); if (isset($options['return']) && $options['return'] === true) { return $out; } else { echo $out; } }
/** * Adds and 'asc' or 'desc' class to the sort links * @see /cake/libs/view/helpers/PaginatorHelper#sort($title, $key, $options) */ function sort($title, $key = null, $options = array()) { // get current sort key & direction $sortKey = $this->sortKey(); $sortDir = $this->sortDir(); // multiple mode stuffs if (isset($key)) { // add $sortDir class if current column is sort column if ($sortKey == $key) { $options['class'] = $sortDir; } else { $options['class'] = "sortable"; } } return parent::sort($title, $key, $options); }
public function last($last = 'last >>', $options = array()) { $options = $this->_defaultOptions($options); return parent::last($last, $options); }
public function last($last = 'last >>', $options = array()) { $options['escape'] = isset($options['escape']) ? $options['escape'] : true; $options = $this->_defaultOptions($options); return parent::last($last, $options); }
/** * Returns a set of numbers for the paged result set - Different Defaults * @see /cake/libs/view/helpers/PaginatorHelper#numbers($options = array()) */ function numbers($options = array()) { $defaults = array('tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'modulus' => '8', 'separator' => '', 'first' => null, 'last' => null); $options += $defaults; return parent::numbers($options); }
/** * Taken from Cake PaginatorHelper, extended to apply active class automatically * * Generates a plain or Ajax link with pagination parameters * * ### Options * * - `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 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()) { $named = $this->params['named']; unset($named['sort'], $named['direction'], $named['page']); if (count($url)) { //add a null value to named array if it does not exists and is null in url foreach ($url as $key => $value) { if (is_null($value) && !isset($named[$key])) { $named[$key] = $url[$key]; } } //check if the url array is contained entirely within the named array $match = count($url) == count(array_intersect_assoc($url, $named)); if ($match) { if (isset($options['class']) && !empty($options['class'])) { $options['class'] .= ' active btn-success'; } else { $options['class'] = 'active btn-success'; } } } return parent::link($title, $url, $options); }
/** * test that mock classes injected into paginatorHelper are called when using link() * * @expectedException CakeException * @return void */ public function testMockAjaxProviderClassInjection() { $mock = $this->getMock('PaginatorHelper', array(), array($this->View), 'PaginatorMockJsHelper'); $Paginator = new PaginatorHelper($this->View, array('ajax' => 'PaginatorMockJs')); $Paginator->request->params['paging'] = array('Article' => array('current' => 9, 'count' => 62, 'prevPage' => false, 'nextPage' => true, 'pageCount' => 7, 'defaults' => array(), 'options' => array(), 'paramType' => 'named')); $Paginator->PaginatorMockJs = $mock; $Paginator->PaginatorMockJs->expects($this->once())->method('link'); $Paginator->link('Page 2', array('page' => 2), array('update' => '#content')); new PaginatorHelper($this->View, array('ajax' => 'Form')); }
/** * Get a complete pagination with counter, all navigation button and number. * This is a wrapper around all other individual option with some defaults params. * Inspired by Paginator::counter() function. * * @param $options Options for pagination. * * Extra options: * - counterOptions: Counter options array to override defaults one. (default: empty array) * - firstTitle: First button title. (default: "<<") * - firstOptions: First button options array to override defaults one. * - prevTitle: Prev button title. (default: "<") * - prevOptions: Prev button options array to override defaults one. * - numbersOptions: Numbers buttons options array to override defaults one. * - nextTitle: Next button title. (default: ">") * - nextOptions: Next button options array to override defaults one. * - lastTitle: Last button title. (default: ">>") * - lastOptions: Last button options array to override defaults one. * - wrapOpen: Wrapper opening tag. (default: "<div class="pagination">") * - wrapClose: Wrapper closing tag. (default: "</div>") * - type: How we display buttons. In list or plain. values: list, plain (default: list). This options has precedent on format option. * - format: String that give control on what to display and the order to display element. * Default: "{:wrapOpen} {:counter} {:ulOpen} {:first} {:prev} {:numbers} {:next} {:last} {:ulClose} {:wrapClose}" * Options: * - {:wrapOpen} Display wrap open tag. Use with {:wrapClose}. * - {:counter} Display counter. * - {:ulOpen} Display ul open tag. Use with {:ulClose}. * - {:first} Display first button. * - {:prev} Display prev button. * - {:numbers} Display numbers button. * - {:next} Display next button. * - {:last} Display last button. * - {:ulClose} Display ul close tag. User with {:ulOpen}. * - {:wrapClose} Display wrap close tag. Use with {:wrapOpen}. */ public function pagination($options = []) { $default = ['counterOptions' => [], 'firstTitle' => '<<', 'firstOptions' => [], 'prevTitle' => '<', 'prevOptions' => [], 'prevDisabledTitle' => '<', 'prevDisabledOptions' => [], 'numbersOptions' => [], 'nextTitle' => '>', 'nextOptions' => [], 'nextDisabledTitle' => '>', 'nextDisabledOptions' => [], 'lastTitle' => '>>', 'lastOptions' => [], 'wrapOpen' => '<div class="' . GA_PAGINATION . '">', 'wrapClose' => '</div>', 'type' => 'list', 'format' => '{:wrapOpen} {:counter} {:ulOpen} {:first} {:prev} {:numbers} {:next} {:last} {:ulClose} {:wrapClose}']; $options = array_merge($default, $options); if ($options['type'] === 'plain') { $substitutions = ['{:ulOpen}' => '', '{:ulClose}' => '']; $options['format'] = str_replace(array_keys($substitutions), array_values($substitutions), $options['format']); $options['numbersOptions']['tag'] = ''; $options['firstOptions']['tag'] = ''; $options['prevOptions']['tag'] = ''; $options['nextOptions']['tag'] = ''; $options['lastOptions']['tag'] = ''; } extract($options); $map = ['{:wrapOpen}' => $options['wrapOpen'], '{:counter}' => parent::counter($counterOptions), '{:ulOpen}' => $this->Html->tag('ul'), '{:first}' => $this->first($firstTitle, $firstOptions), '{:prev}' => $this->prev($prevTitle, $prevOptions, $prevDisabledTitle, $prevDisabledOptions), '{:numbers}' => $this->numbers($numbersOptions), '{:next}' => $this->next($nextTitle, $nextOptions, $nextDisabledTitle, $nextDisabledOptions), '{:last}' => $this->last($lastTitle, $lastOptions), '{:ulClose}' => $this->Html->useTag('tagend', 'ul'), '{:wrapClose}' => $options['wrapClose']]; return str_replace(array_keys($map), array_values($map), $options['format']); }
/** * * Get pagination link list. * * @param $options Options for link element * * Extra options: * - size small/normal/large (default normal) * **/ public function numbers($options = array()) { $default = array('tag' => 'li', 'currentTag' => 'a', 'separator' => '', 'currentClass' => 'active', 'disabledTag' => 'a', 'size' => 'normal'); $options = array_merge($default, $options); $size = $options['size']; unset($options['size']); $class = 'pagination'; if (isset($options['ulClass'])) { $class .= ' ' . $options['ulClass']; unset($options['ulClass']); } switch ($size) { case 'small': $class .= ' pagination-sm'; break; case 'large': $class .= ' pagination-lg'; break; } $options['before'] = '<ul class="' . $class . '">'; $options['after'] = '</ul>'; if (isset($options['prev'])) { $options['before'] .= $this->prev($options['prev']); } if (isset($options['next'])) { $options['after'] = $this->next($options['next']) . $options['after']; } return parent::numbers($options); }
public function last($last = '»', $options = []) { $defaults = ['class' => 'last', 'tag' => 'li']; $options = Hash::merge($defaults, $options); return parent::last($last, $options); }
/** * 次へリンク * @param PaginatorHelper $paginator * @return string */ private static function getPaginatorLinkNext(PaginatorHelper $paginator) { $title = __('次へ') . ' >'; $options = array(); $disabledTitle = null; $disabledOptions = array('class' => 'next disabled'); return $paginator->next($title, $options, $disabledTitle, $disabledOptions); }
/** * url method * * Change applied to "if (is_array($url['order'])) {" block * It trips the alias if sorting by OtherModel.field * I.e. * /index/page:1/sort:Supplier.name/direction:asc * links to * I.e. /index/page:2/sort:name/direction:asc * * @TODO ticket, test case, patch, delete * @param array $options array() * @param bool $asArray false * @param mixed $model null * @return void * @access public */ public function url($options = array(), $asArray = false, $model = null) { $paging = $this->params($model); $url = array_merge(array_filter(Set::diff(array_merge($paging['defaults'], $paging['options']), $paging['defaults'])), $options); if (isset($url['order'])) { $sort = $direction = null; if (is_array($url['order'])) { // @TODO list($sort, $direction) = array($this->sortKey($model, $url), current($url['order'])); $direction = current($url['order']); $sort = current(array_keys($url['order'])); } unset($url['order']); $url = array_merge($url, compact('sort', 'direction')); } if ($asArray) { return $url; } return parent::url($url); }
public function last($title = null, $options = array()) { $default = array('title' => '>>', 'tag' => 'li', 'after' => null, 'model' => $this->defaultModel(), 'separator' => null, 'ellipsis' => null, 'class' => null); $options += $default; if (empty($title)) { $title = $options['title']; } unset($options['title']); $params = (array) $this->params($options['model']); return parent::last($title, $options) ? parent::last($title, $options) : $this->Html->tag($options['tag'], $this->link($title, array(), $options), array('class' => 'disabled')); }
public function last($last = 'last >>', $options = array()) { $options = array_merge(array('tag' => 'li'), $options); return parent::last($last, $options); }
/** * @param array $options * @return string */ public function counter($options = array()) { if (!isset($options['format'])) { $options['format'] = __('Page {:page} of {:pages}, showing {:current} of {:count} total.'); } return parent::counter($options); }
function next($title = 'Next »', $options = array(), $disabledTitle = null, $disabledOptions = array()) { $disabledOptions = array_merge($options, $disabledOptions); return parent::next($title, $options, $disabledTitle, $disabledOptions); }
/** * 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 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 */ public function url($options = array(), $asArray = false, $model = null) { $paging = $this->params($model); $url = array_merge(array_filter($paging['options']), $options); 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')); } $url = $this->_convertUrlKeys($url, $paging['paramType']); if ($asArray) { return $url; } return parent::url($url); }