protected function applySorting()
{
$sort = [];
$this->sort = $this->sort ? $this->sort : $this->defaultSort;
foreach ($this->sort as $column => $dir) {
$component = $this->getColumn($column, FALSE);
if (!$component) {
if (!isset($this->defaultSort[$column])) {
$this->__triggerUserNotice("Column with name '{$column}' does not exist.");
break;
}
} elseif (!$component->isSortable()) {
if (isset($this->defaultSort[$column])) {
$component->setSortable();
} else {
$this->__triggerUserNotice("Column with name '{$column}' is not sortable.");
break;
}
}
if (!in_array($dir, [Column::ORDER_ASC, Column::ORDER_DESC])) {
if ($dir == '' && isset($this->defaultSort[$column])) {
unset($this->sort[$column]);
break;
}
$this->__triggerUserNotice("Dir '{$dir}' is not allowed.");
break;
}
$sort[$component ? $component->column : $column] = $dir == Column::ORDER_ASC ? 'ASC' : 'DESC';
}
if (!empty($sort)) {
$this->getModel()->sort($sort);
}
}