MDL-28015 workshop - fixed unique list of columns in ORDER BY clause
authorDavid Mudrak <david@moodle.com>
Thu, 7 Jul 2011 13:02:34 +0000 (15:02 +0200)
committerDavid Mudrak <david@moodle.com>
Thu, 7 Jul 2011 13:17:27 +0000 (15:17 +0200)
MSSQL requires that the columns in the ORDER BY clause list must be
unique. The patch populates the list of fields by combining an array of
explicit sort definition with an array of implicit (default) sort
definition.

mod/workshop/locallib.php

index 2df5d37..8f772e2 100644 (file)
@@ -1342,7 +1342,12 @@ class workshop {
             list($participantids, $params) = $DB->get_in_or_equal(array_keys($participants), SQL_PARAMS_NAMED);
             $params['workshopid1'] = $this->id;
             $params['workshopid2'] = $this->id;
-            $sqlsort = $sortby . ' ' . $sorthow . ',u.lastname,u.firstname,u.id';
+            $sqlsort = array();
+            $sqlsortfields = array($sortby => $sorthow) + array('lastname' => 'ASC', 'firstname' => 'ASC', 'u.id' => 'ASC');
+            foreach ($sqlsortfields as $sqlsortfieldname => $sqlsortfieldhow) {
+                $sqlsort[] = $sqlsortfieldname . ' ' . $sqlsortfieldhow;
+            }
+            $sqlsort = implode(',', $sqlsort);
             $sql = "SELECT u.id AS userid,u.firstname,u.lastname,u.picture,u.imagealt,u.email,
                            s.title AS submissiontitle, s.grade AS submissiongrade, ag.gradinggrade
                       FROM {user} u