From b666bddae27ec46c5ea113c652b08c0d6ed2f188 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 19 Sep 2012 12:56:51 +0800 Subject: [PATCH] MDL-35375: Ensure the assignment grading table is always sorted by at least one unique column Conflicts: mod/assign/gradingtable.php --- lib/tablelib.php | 10 +++++++--- mod/assign/gradingtable.php | 16 +++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index 04daa06e6bd..6de22af776a 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -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); diff --git a/mod/assign/gradingtable.php b/mod/assign/gradingtable.php index 40bed663228..fce13ea0e7e 100644 --- a/mod/assign/gradingtable.php +++ b/mod/assign/gradingtable.php @@ -118,12 +118,12 @@ class assign_grading_table extends table_sql implements renderable { $headers = array(); // Select - $columns[] = 'select'; - $headers[] = get_string('select') . '
'; - - // Edit links if (!$this->is_downloading()) { - $columns[] = 'edit'; + $columns[] = 'select'; + $headers[] = get_string('select') . '
'; + + // 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; -- 2.11.4.GIT