Merge branch 'MDL-42069' of https://github.com/appalachianstate/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 8 Oct 2013 19:25:46 +0000 (21:25 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 8 Oct 2013 19:25:46 +0000 (21:25 +0200)
mod/quiz/report/grading/gradingsettings_form.php
mod/quiz/report/grading/lang/en/quiz_grading.php
mod/quiz/report/grading/report.php

index e29dd72..be6bd3f 100644 (file)
@@ -79,7 +79,8 @@ class quiz_grading_settings_form extends moodleform {
             'date' => get_string('bydate', 'quiz_grading'),
         );
         if ($this->shownames) {
-            $orderoptions['student'] = get_string('bystudentname', 'quiz_grading');
+            $orderoptions['studentfirstname'] = get_string('bystudentfirstname', 'quiz_grading');
+            $orderoptions['studentlastname']  = get_string('bystudentlastname', 'quiz_grading');
         }
         if ($this->showidnumbers) {
             $orderoptions['idnumber'] = get_string('bystudentidnumber', 'quiz_grading');
index 01c38b8..2fda255 100644 (file)
@@ -30,7 +30,8 @@ $string['automaticallygraded'] = 'Automatically graded';
 $string['backtothelistofquestions'] = 'Back to the list of questions';
 $string['bydate'] = 'By date';
 $string['bystudentidnumber'] = 'By student id number';
-$string['bystudentname'] = 'By student name';
+$string['bystudentfirstname'] = 'By student first name';
+$string['bystudentlastname'] = 'By student last name';
 $string['cannotloadquestioninfo'] = 'Unable to load questiontype specific question information';
 $string['cannotgradethisattempt'] = 'Cannot grade this attempt.';
 $string['changeoptions'] = 'Change options';
index f7001c5..8b19857 100644 (file)
@@ -89,9 +89,9 @@ class quiz_grading_report extends quiz_default_report {
         $showidnumbers = has_capability('quiz/grading:viewidnumber', $this->context);
 
         // Validate order.
-        if (!in_array($order, array('random', 'date', 'student', 'idnumber'))) {
+        if (!in_array($order, array('random', 'date', 'studentfirstname', 'studentlastname', 'idnumber'))) {
             $order = self::DEFAULT_ORDER;
-        } else if (!$shownames && $order == 'student') {
+        } else if (!$shownames && ($order == 'studentfirstname' || $order == 'studentlastname')) {
             $order = self::DEFAULT_ORDER;
         } else if (!$showidnumbers && $order == 'idnumber') {
             $order = self::DEFAULT_ORDER;
@@ -546,10 +546,17 @@ class quiz_grading_report extends quiz_default_report {
                     WHERE sortqas.questionattemptid = qa.id
                         AND sortqas.state $statetest
                     )";
-        } else if ($orderby == 'student' || $orderby == 'idnumber') {
+        } else if ($orderby == 'studentfirstname' || $orderby == 'studentlastname' || $orderby == 'idnumber') {
             $qubaids->from .= " JOIN {user} u ON quiza.userid = u.id ";
-            if ($orderby == 'student') {
-                $orderby = $DB->sql_fullname('u.firstname', 'u.lastname');
+            // For name sorting, map orderby form value to
+            // actual column names; 'idnumber' maps naturally
+            switch ($orderby) {
+                case "studentlastname":
+                    $orderby = "u.lastname, u.firstname";
+                    break;
+                case "studentfirstname":
+                    $orderby = "u.firstname, u.lastname";
+                    break;
             }
         }