/** * Generates a sorting link with an automatically translated name taken from field_names.po * Also force it to be page 1 of the results * * @param mixed $title * @param mixed $key null * @param array $options array() * @return void * @access public */ public function sort($title, $key = null, $options = array()) { if (!$key) { $key = $title; if (strpos($title, '.')) { $title = str_replace('.', ' ', $title); } else { $view = ClassRegistry::getObject('view'); if (isset($view->viewVars['modelClass'])) { $alias = $view->viewVars['modelClass']; } else { $alias = $view->association ? $view->association : $view->model; } $title = $alias . ' ' . $title; } if (substr($title, -3) == '_id') { $title = substr($title, 0, strlen($title) - 3); } $title = Inflector::humanize(Inflector::underscore($title)); if (!empty($this->params['plugin'])) { $pluginDomain = Inflector::underscore($this->params['plugin']) . '_'; } else { $pluginDomain = ''; } $_title = $title; $title = __d($pluginDomain . 'field_names', $title, true); if ($title === $_title && !empty($alias)) { $alias = Inflector::humanize(Inflector::underscore($alias)); $title = str_replace($alias . ' ', '', $title); } } $options['url']['page'] = 1; return parent::sort($title, $key, $options); }
/** * 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); }
/** * Make table headers sortable * * @param string $key * @param mixed $title * @param array $options * * @return string */ public function sortTableHeader($key, $title = null, $options = array()) { $content = parent::sort($key, $title, $options + array('block' => 'script')); $options = array_merge(array('url' => array(), 'model' => null), $options); $class = ""; $sortKey = $this->sortKey($options['model']); $defaultModel = $this->defaultModel(); $isSorted = $sortKey === $key || $sortKey === $defaultModel . '.' . $key || $key === $defaultModel . '.' . $sortKey; if ($isSorted) { $dir = $this->sortDir($options['model']) === 'asc' ? 'desc' : 'asc'; $class = $dir === 'asc' ? 'headerSortDown' : 'headerSortUp'; } return sprintf('<th class="blue header %s">%s</th>', $class, $content); }
/** * 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); }