MDL-35375: Ensure the assignment grading table is always sorted by at least one unique column

Conflicts:

	mod/assign/gradingtable.php
This commit is contained in:
Damyon Wiese
2012-09-24 12:38:24 +08:00
parent daccc92d9e
commit b666bddae2
2 changed files with 16 additions and 10 deletions
+7 -3
View File
@@ -451,9 +451,13 @@ class flexible_table {
$this->sess->sortby = array_slice($this->sess->sortby, 0, $this->maxsortkeys);
}
// If we didn't sort just now, then use the default sort order if one is defined and the column exists
if (empty($this->sess->sortby) && !empty($this->sort_default_column)) {
$this->sess->sortby = array ($this->sort_default_column => ($this->sort_default_order == SORT_DESC ? SORT_DESC : SORT_ASC));
// MDL-35375 - If a default order is defined and it is not in the current list of order by columns, add it at the end.
// This prevents results from being returned in a random order if the only order by column contains equal values.
if (!empty($this->sort_default_column)) {
if (!array_key_exists($this->sort_default_column, $this->sess->sortby)) {
$defaultsort = array($this->sort_default_column => $this->sort_default_order);
$this->sess->sortby = array_merge($this->sess->sortby, $defaultsort);
}
}
$ilast = optional_param($this->request[TABLE_VAR_ILAST], null, PARAM_RAW);
+9 -7
View File
@@ -118,12 +118,12 @@ class assign_grading_table extends table_sql implements renderable {
$headers = array();
// Select
$columns[] = 'select';
$headers[] = get_string('select') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
// Edit links
if (!$this->is_downloading()) {
$columns[] = 'edit';
$columns[] = 'select';
$headers[] = get_string('select') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
// We have to call this column userid so we can use userid as a default sortable column.
$columns[] = 'userid';
$headers[] = get_string('edit');
}
@@ -187,8 +187,10 @@ class assign_grading_table extends table_sql implements renderable {
// set the columns
$this->define_columns($columns);
$this->define_headers($headers);
// We require at least one unique column for the sort.
$this->sortable(true, 'userid');
$this->no_sorting('finalgrade');
$this->no_sorting('edit');
$this->no_sorting('userid');
$this->no_sorting('select');
$this->no_sorting('outcomes');
@@ -430,7 +432,7 @@ class assign_grading_table extends table_sql implements renderable {
* @param stdClass $row
* @return string
*/
function col_edit(stdClass $row) {
function col_userid(stdClass $row) {
$edit = '';
if ($this->rownum < 0) {
$this->rownum = $this->currpage * $this->pagesize;