Skip to content
Browse files

MDL-35375: Ensure the assignment grading table is always sorted by at…

… least one unique column

Conflicts:

	mod/assign/gradingtable.php
  • Loading branch information...
1 parent daccc92 commit b666bddae27ec46c5ea113c652b08c0d6ed2f188 Damyon Wiese committed
Showing with 16 additions and 10 deletions.
  1. +7 −3 lib/tablelib.php
  2. +9 −7 mod/assign/gradingtable.php
View
10 lib/tablelib.php
@@ -451,9 +451,13 @@ function setup() {
$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);
View
16 mod/assign/gradingtable.php
@@ -118,12 +118,12 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgr
$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 @@ function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgr
// 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 @@ function col_status(stdClass $row) {
* @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;

0 comments on commit b666bdd

Please sign in to comment.
Something went wrong with that request. Please try again.