protected function order($params)
{
$statusVariables = $this->statusVariables;
if (empty($params['order'])) {
throw new \Ip\Exception('Missing parameters');
}
if (empty($statusVariables['order']) || $statusVariables['order'] != $params['order']) {
//new field selected to order records. Use ascending order
$statusVariables['order'] = $params['order'];
unset($statusVariables['direction']);
} else {
//the same field has been clicked repeatedly.
if (empty($statusVariables['direction']) || $statusVariables['direction'] == 'asc') {
//the same field has been clicked twice. Change order direction to descending
$statusVariables['order'] = $params['order'];
$statusVariables['direction'] = 'desc';
} else {
//the same field has been clicked for the third time. Remove ordering
unset($statusVariables['order']);
unset($statusVariables['direction']);
}
}
$commands = array();
$commands[] = Commands::setHash(Status::build($statusVariables));
return $commands;
}