MDL-26647 (6) Support showuseridentity on grader report, quiz report, SCORM report
authorsam marshall <s.marshall@open.ac.uk>
Wed, 2 Nov 2011 17:47:25 +0000 (17:47 +0000)
committersam marshall <s.marshall@open.ac.uk>
Fri, 4 Nov 2011 13:57:17 +0000 (13:57 +0000)
grade/report/grader/lib.php
grade/report/grader/preferences_form.php
grade/report/grader/settings.php
grade/report/grader/styles.css
lang/en/grades.php
lib/db/upgrade.php
mod/quiz/report/attemptsreport.php
mod/scorm/report/basic/report.php

index 1d6fa93..e9590d2 100644 (file)
@@ -340,7 +340,8 @@ class grade_report_grader extends grade_report {
         list($enrolledsql, $enrolledparams) = get_enrolled_sql($this->context);
 
         //fields we need from the user table
-        $userfields = user_picture::fields('u', array('idnumber'));
+        $userfields = user_picture::fields('u');
+        $userfields .= get_extra_user_fields_sql($this->context);
 
         $sortjoin = $sort = $params = null;
 
@@ -556,23 +557,20 @@ class grade_report_grader extends grade_report {
         $rows = array();
 
         $showuserimage = $this->get_pref('showuserimage');
-        $showuseridnumber = $this->get_pref('showuseridnumber');
         $fixedstudents = $this->is_fixed_students();
 
         $strfeedback  = $this->get_lang_string("feedback");
         $strgrade     = $this->get_lang_string('grade');
 
-        $arrows = $this->get_sort_arrows();
+        $extrafields = get_extra_user_fields($this->context);
 
-        $colspan = 1;
+        $arrows = $this->get_sort_arrows($extrafields);
 
+        $colspan = 1;
         if (has_capability('gradereport/'.$CFG->grade_profilereport.':view', $this->context)) {
             $colspan++;
         }
-
-        if ($showuseridnumber) {
-            $colspan++;
-        }
+        $colspan += count($extrafields);
 
         $levels = count($this->gtree->levels) - 1;
 
@@ -600,17 +598,14 @@ class grade_report_grader extends grade_report {
 
         $headerrow->cells[] = $studentheader;
 
-        if ($showuseridnumber) {
-            // TODO: weird, this is not used anywhere
-            $sortidnumberlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'idnumber')), get_string('idnumber'));
+        foreach ($extrafields as $field) {
+            $fieldheader = new html_table_cell();
+            $fieldheader->attributes['class'] = 'header userfield user' . $field;
+            $fieldheader->scope = 'col';
+            $fieldheader->header = true;
+            $fieldheader->text = $arrows[$field];
 
-            $idnumberheader = new html_table_cell();
-            $idnumberheader->attributes['class'] = 'header useridnumber';
-            $idnumberheader->scope = 'col';
-            $idnumberheader->header = true;
-            $idnumberheader->text = $arrows['idnumber'];
-
-            $headerrow->cells[] = $idnumberheader;
+            $headerrow->cells[] = $fieldheader;
         }
 
         $rows[] = $headerrow;
@@ -661,13 +656,13 @@ class grade_report_grader extends grade_report {
                 $userrow->cells[] = $userreportcell;
             }
 
-            if ($showuseridnumber) {
-                $idnumbercell = new html_table_cell();
-                $idnumbercell->attributes['class'] = 'header useridnumber';
-                $idnumbercell->header = true;
-                $idnumbercell->scope = 'row';
-                $idnumbercell->text = $user->idnumber;
-                $userrow->cells[] = $idnumbercell;
+            foreach ($extrafields as $field) {
+                $fieldcell = new html_table_cell();
+                $fieldcell->attributes['class'] = 'header userfield user' . $field;
+                $fieldcell->header = true;
+                $fieldcell->scope = 'row';
+                $fieldcell->text = $user->{$field};
+                $userrow->cells[] = $fieldcell;
             }
 
             $rows[] = $userrow;
@@ -1205,8 +1200,6 @@ class grade_report_grader extends grade_report {
             $iconsrow = new html_table_row();
             $iconsrow->attributes['class'] = 'controls';
 
-            $showuseridnumber = $this->get_pref('showuseridnumber');
-
             foreach ($this->gtree->items as $itemid=>$unused) {
                 // emulate grade element
                 $item =& $this->gtree->get_item($itemid);
@@ -1588,9 +1581,11 @@ class grade_report_grader extends grade_report {
      * Refactored function for generating HTML of sorting links with matching arrows.
      * Returns an array with 'studentname' and 'idnumber' as keys, with HTML ready
      * to inject into a table header cell.
+     * @param array $extrafields Array of extra fields being displayed, such as
+     *   user idnumber
      * @return array An associative array of HTML sorting links+arrows
      */
-    public function get_sort_arrows() {
+    public function get_sort_arrows(array $extrafields = array()) {
         global $OUTPUT;
         $arrows = array();
 
@@ -1601,7 +1596,6 @@ class grade_report_grader extends grade_report {
 
         $firstlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'firstname')), $strfirstname);
         $lastlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'lastname')), $strlastname);
-        $idnumberlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'idnumber')), get_string('idnumber'));
 
         $arrows['studentname'] = $lastlink;
 
@@ -1623,13 +1617,17 @@ class grade_report_grader extends grade_report {
             }
         }
 
-        $arrows['idnumber'] = $idnumberlink;
+        foreach ($extrafields as $field) {
+            $fieldlink = html_writer::link(new moodle_url($this->baseurl,
+                    array('sortitemid'=>$field)), get_user_field_name($field));
+            $arrows[$field] = $fieldlink;
 
-        if ('idnumber' == $this->sortitemid) {
-            if ($this->sortorder == 'ASC') {
-                $arrows['idnumber'] .= print_arrow('up', $strsortasc, true);
-            } else {
-                $arrows['idnumber'] .= print_arrow('down', $strsortdesc, true);
+            if ($field == $this->sortitemid) {
+                if ($this->sortorder == 'ASC') {
+                    $arrows[$field] .= print_arrow('up', $strsortasc, true);
+                } else {
+                    $arrows[$field] .= print_arrow('down', $strsortdesc, true);
+                }
             }
         }
 
index 37ed17e..535c7aa 100644 (file)
@@ -109,7 +109,6 @@ class grader_report_preferences_form extends moodleform {
             $preferences['prefgeneral']['enableajax'] = $checkbox_default;
 
             $preferences['prefshow']['showuserimage'] = $checkbox_default;
-            $preferences['prefshow']['showuseridnumber'] = $checkbox_default;
             $preferences['prefshow']['showactivityicons'] = $checkbox_default;
             $preferences['prefshow']['showranges'] = $checkbox_default;
 
index a2acaaf..f357e2d 100644 (file)
@@ -63,9 +63,6 @@ if ($ADMIN->fulltree) {
     $settings->add(new admin_setting_configcheckbox('grade_report_showuserimage', get_string('showuserimage', 'grades'),
                                                 get_string('showuserimage_help', 'grades'), 1));
 
-    $settings->add(new admin_setting_configcheckbox('grade_report_showuseridnumber', get_string('showuseridnumber', 'grades'),
-                                                get_string('showuseridnumber_help', 'grades'), 0));
-
     $settings->add(new admin_setting_configcheckbox('grade_report_showactivityicons', get_string('showactivityicons', 'grades'),
                                                 get_string('showactivityicons_help', 'grades'), 1));
 
index e897aa4..39ffc6b 100644 (file)
@@ -127,7 +127,7 @@ border-style:solid;
 border-width:0 0 1px;
 }
 
-table#user-grades th.useridnumber {
+table#user-grades th.userfield {
 border-style:solid;
 border-width:0 0 1px 1px;
 }
@@ -529,7 +529,7 @@ border-style:solid;
 border-width:0;
 }
 
-table#user-grades td.useridnumber,
+table#user-grades td.userfield,
 table#user-grades th,
 .path-grade-report-grader div.gradeparent,
 .path-grade-report-grader .ie6 form,
@@ -560,7 +560,7 @@ background-color:#f3ead8;
 }
 
 .path-grade-report-grader table th.user,
-.path-grade-report-grader table td.useridnumber {
+.path-grade-report-grader table td.userfield {
     text-align:left;
     vertical-align:middle;
 }
index 94d132c..0b271bb 100644 (file)
@@ -581,8 +581,6 @@ $string['showranges'] = 'Show ranges';
 $string['showranges_help'] = 'If enabled, the grader report will contain an additional row displaying the range for each category and grade item.';
 $string['showrank'] = 'Show rank';
 $string['showrank_help'] = 'Show the position of the student in relation to the rest of the class for each grade item?';
-$string['showuseridnumber'] = 'Show user ID numbers';
-$string['showuseridnumber_help'] = 'If enabled, user ID numbers are shown in an additional column.';
 $string['showuserimage'] = 'Show user profile images';
 $string['showuserimage_help'] = 'Whether to show the user\'s profile image next to the name in the grader report.';
 $string['showverbose'] = 'Show {$a->category} {$a->itemmodule} {$a->itemname}';
index 1803a0f..a0c2541 100644 (file)
@@ -6815,6 +6815,7 @@ FROM
             set_config('showuseridentity', $CFG->extrauserselectorfields);
             unset_config('extrauserselectorfields');
         }
+        unset_config('grade_report_showuseridnumber');
         upgrade_main_savepoint(true, 2011102700.01);
     }
 
index 4a4698f..89bfefc 100644 (file)
@@ -152,6 +152,9 @@ abstract class quiz_attempt_report extends quiz_default_report {
             $fields .= "\n(CASE WHEN $qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,";
         }
 
+        $extrafields = get_extra_user_fields_sql($this->context, 'u', '',
+                array('id', 'idnumber', 'firstname', 'lastname', 'picture',
+                'imagealt', 'institution', 'department', 'email'));
         $fields .= '
                 quiza.uniqueid AS usageid,
                 quiza.id AS attempt,
@@ -163,7 +166,7 @@ abstract class quiz_attempt_report extends quiz_default_report {
                 u.imagealt,
                 u.institution,
                 u.department,
-                u.email,
+                u.email' . $extrafields . ',
                 quiza.sumgrades,
                 quiza.timefinish,
                 quiza.timestart,
@@ -239,9 +242,13 @@ abstract class quiz_attempt_report extends quiz_default_report {
             $headers[] = get_string('firstname');
         }
 
-        if ($CFG->grade_report_showuseridnumber) {
-            $columns[] = 'idnumber';
-            $headers[] = get_string('idnumber');
+        // When downloading, some extra fields are always displayed (because
+        // there's no space constraint) so do not include in extra-field list
+        $extrafields = get_extra_user_fields($this->context,
+                $table->is_downloading() ? array('institution', 'department', 'email') : array());
+        foreach ($extrafields as $field) {
+            $columns[] = $field;
+            $headers[] = get_user_field_name($field);
         }
 
         if ($table->is_downloading()) {
index 18c9759..b9fabc4 100644 (file)
@@ -98,8 +98,8 @@ class scorm_basic_report extends scorm_default_report {
 
         if ( !$nostudents ) {
             // Now check if asked download of data
+            $coursecontext = context_course::instance($course->id);
             if ($download) {
-                $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
                 $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
                 $filename = clean_filename("$shortname ".format_string($scorm->name, true));
             }
@@ -117,10 +117,12 @@ class scorm_basic_report extends scorm_default_report {
             }
             $columns[]= 'fullname';
             $headers[]= get_string('name');
-            if ($CFG->grade_report_showuseridnumber) {
-                $columns[]= 'idnumber';
-                $headers[]= get_string('idnumber');
+            $extrafields = get_extra_user_fields($coursecontext);
+            foreach ($extrafields as $field) {
+                $columns[] = $field;
+                $headers[] = get_user_field_name($field);
             }
+
             $columns[]= 'attempt';
             $headers[]= get_string('attempt', 'scorm');
             $columns[]= 'start';
@@ -153,7 +155,12 @@ class scorm_basic_report extends scorm_default_report {
 
                 $table->column_suppress('picture');
                 $table->column_suppress('fullname');
-                $table->column_suppress('idnumber');
+                // I wonder why it is doing all this suppress malarkey?
+                // However, if it was suppressing idnumber field before, I guess
+                // it needs to suppress all the user identity fields now
+                foreach ($extrafields as $field) {
+                    $table->column_suppress($field);
+                }
 
                 $table->no_sorting('start');
                 $table->no_sorting('finish');
@@ -266,7 +273,8 @@ class scorm_basic_report extends scorm_default_report {
                             // Construct the SQL
             $select = 'SELECT DISTINCT '.$DB->sql_concat('u.id', '\'#\'', 'COALESCE(st.attempt, 0)').' AS uniqueid, ';
             $select .= 'st.scormid AS scormid, st.attempt AS attempt, ' .
-                    'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email ';
+                    'u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, u.imagealt, u.email' .
+                    get_extra_user_fields_sql($coursecontext, 'u', '', array('idnumber')) . ' ';
 
             // This part is the same for all cases - join users and scorm_scoes_track tables
             $from = 'FROM {user} u ';
@@ -385,8 +393,8 @@ class scorm_basic_report extends scorm_default_report {
                     } else {
                         $row[] = fullname($scouser);
                     }
-                    if (in_array('idnumber', $columns)) {
-                        $row[] = $scouser->idnumber;
+                    foreach ($extrafields as $field) {
+                        $row[] = s($scouser->{$field});
                     }
                     if (empty($timetracks->start)) {
                         $row[] = '-';