Improved default sort bevahior

This commit is contained in:
Thomas Gelf 2013-08-21 00:21:36 +02:00 committed by Eric Lippmann
parent 2ff5455018
commit ecaa12b0f4
1 changed files with 26 additions and 1 deletions

View File

@ -100,6 +100,12 @@ class AbstractView extends AbstractQuery
return in_array($column, $this->availableColumns); return in_array($column, $this->availableColumns);
} }
// TODO: Not sure about this yet
public function getDefaultColumns()
{
return $this->availableColumns;
}
/** /**
* Get a list of all available column names * Get a list of all available column names
* *
@ -139,7 +145,7 @@ class AbstractView extends AbstractQuery
return $this->order( return $this->order(
// TODO: Use first sortDefaults entry if available, fall back to // TODO: Use first sortDefaults entry if available, fall back to
// column if not // column if not
$request->getParam('sort', $this->availableColumns[0]), $request->getParam('sort', $this->getDefaultSortColumn()),
$request->getParam('dir') $request->getParam('dir')
); );
} }
@ -209,6 +215,25 @@ class AbstractView extends AbstractQuery
return new Filter($this->filters); return new Filter($this->filters);
} }
public function hasSingleSortColumn()
{
return count($this->order_columns) === 1;
}
public function getFirstSortColumn()
{
return $this->order_columns[0];
}
protected function getDefaultSortColumn()
{
if (empty($this->sortDefaults)) {
return $this->availableColumns[0];
} else {
return array_shift(array_keys($this->sortDefaults));
}
}
/** /**
* Default sort direction for given column, ASCending if not defined * Default sort direction for given column, ASCending if not defined
* *