Permalink
Browse files

MDL-26647 (6) Support showuseridentity on grader report, quiz report,…

… SCORM report
  • Loading branch information...
1 parent 24e14bc commit e4aec5bed31290bac2a288e948041a2e80d46e12 @sammarshallou sammarshallou committed Nov 2, 2011
@@ -340,7 +340,8 @@ public function load_users() {
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 @@ public function get_left_rows() {
$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 @@ public function get_left_rows() {
$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 @@ public function get_left_rows() {
$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 @@ public function get_right_icons_row($rows=array()) {
$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 @@ public function is_fixed_students() {
* 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 @@ public function get_sort_arrows() {
$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 @@ public function get_sort_arrows() {
}
}
- $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);
+ }
}
}
@@ -109,7 +109,6 @@ function definition() {
$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;
@@ -63,9 +63,6 @@
$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));
@@ -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;
}
View
@@ -581,8 +581,6 @@
$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}';
View
@@ -6815,6 +6815,7 @@ function xmldb_main_upgrade($oldversion) {
set_config('showuseridentity', $CFG->extrauserselectorfields);
unset_config('extrauserselectorfields');
}
+ unset_config('grade_report_showuseridnumber');
upgrade_main_savepoint(true, 2011102700.01);
}
@@ -152,6 +152,9 @@ protected function base_sql($quiz, $qmsubselect, $qmfilter, $attemptsmode, $repo
$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 @@ protected function base_sql($quiz, $qmsubselect, $qmfilter, $attemptsmode, $repo
u.imagealt,
u.institution,
u.department,
- u.email,
+ u.email' . $extrafields . ',
quiza.sumgrades,
quiza.timefinish,
quiza.timestart,
@@ -239,9 +242,13 @@ protected function add_user_columns($table, &$columns, &$headers) {
$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()) {
@@ -98,8 +98,8 @@ function display($scorm, $cm, $course, $download) {
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 @@ function display($scorm, $cm, $course, $download) {
}
$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 @@ function display($scorm, $cm, $course, $download) {
$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 @@ function display($scorm, $cm, $course, $download) {
// 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 @@ function display($scorm, $cm, $course, $download) {
} 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[] = '-';

0 comments on commit e4aec5b

Please sign in to comment.