/** * Render a sorting header * * @param array $config An optional array with configuration options * @return string Html */ public function sort($config = array()) { $config = new ObjectConfigJson($config); $config->append(array('title' => '', 'column' => '', 'direction' => 'asc', 'sort' => '', 'url' => null)); $translator = $this->getObject('translator'); //Set the title if (empty($config->title)) { $config->title = ucfirst($config->column); } //Set the direction $direction = strtolower($config->direction); $direction = in_array($direction, array('asc', 'desc')) ? $direction : 'asc'; //Set the class $class = ''; if ($config->column == $config->sort) { $direction = $direction == 'desc' ? 'asc' : 'desc'; // toggle $class = 'class="-koowa-' . $direction . '"'; } //Set the query in the route if (!$config->url instanceof HttpUrlInterface) { $config->url = HttpUrl::fromString($config->url); } $config->url->query['sort'] = $config->column; $config->url->query['direction'] = $direction; $html = '<a href="' . $config->url . '" title="' . $translator->translate('Click to sort by this column') . '" ' . $class . '>'; $html .= $translator->translate($config->title); // Mark the current column if ($config->column == $config->sort) { if (strtolower($config->direction) === 'asc') { $html .= ' <span class="koowa_icon--sort_up koowa_icon--12"></span>'; } else { $html .= ' <span class="koowa_icon--sort_down koowa_icon--12"></span>'; } } else { $html .= ' <span class="koowa_icon--sort koowa_icon--12"></span>'; } $html .= '</a>'; return $html; }