From c5fedf065c395d0aec8c46deb0b76989a5890689 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Fri, 9 May 2008 13:59:36 +0000 Subject: [PATCH] MDL-14223 "Add a column for the user's idnumber, controllable by a site-wide setting" and MDL-14224 "Add a site-wide setting to hide the user profile image from quiz reports" The quiz overview report now respect the settings for the gradebook - whether to display idnumbers and user pictures. Also re-factored the code to build table / download content a little to reduce code duplication. --- mod/quiz/report/overview/report.php | 137 ++++++++++++---------------- 1 file changed, 60 insertions(+), 77 deletions(-) diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index 3ff3e3f83ea..285b7da03cd 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -128,22 +128,43 @@ class quiz_report extends quiz_default_report { // Now check if asked download of data if ($download) { $filename = clean_filename("$course->shortname ".format_string($quiz->name,true)); - $sort = ''; } // Define table columns - $tablecolumns = array('picture', 'fullname', 'timestart', 'timefinish', 'duration'); - $tableheaders = array('', get_string('name'), get_string('startedon', 'quiz'), - get_string('timecompleted','quiz'), get_string('attemptduration', 'quiz')); + $columns = array(); + $headers = array(); + - if ($candelete) { - array_unshift($tablecolumns, 'checkbox'); - array_unshift($tableheaders, NULL); + if (!$download && $candelete) { + $columns[]= 'checkbox'; + $headers[]= NULL; + } + + if (!$download && $CFG->grade_report_showuserimage) { + $columns[]= 'picture'; + $headers[]= ''; } + $columns[]= 'fullname'; + $headers[]= get_string('name'); + + if ($CFG->grade_report_showuseridnumber) { + $columns[]= 'idnumber'; + $headers[]= get_string('idnumber'); + } + + $columns[]= 'timestart'; + $headers[]= get_string('startedon', 'quiz'); + + $columns[]= 'timefinish'; + $headers[]= get_string('timecompleted','quiz'); + + $columns[]= 'duration'; + $headers[]= get_string('attemptduration', 'quiz'); + if ($showgrades) { - $tablecolumns[] = 'sumgrades'; - $tableheaders[] = get_string('grade', 'quiz').'/'.$quiz->grade; + $columns[] = 'sumgrades'; + $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade; } if ($detailedmarks) { @@ -151,13 +172,13 @@ class quiz_report extends quiz_default_report { $questions = quiz_report_load_questions($quiz); foreach ($questions as $id => $question) { // Ignore questions of zero length - $tablecolumns[] = '$'.$id; - $tableheaders[] = '#'.$question->number; + $columns[] = '$'.$id; + $headers[] = '#'.$question->number; } } if ($hasfeedback) { - $tablecolumns[] = 'feedbacktext'; - $tableheaders[] = get_string('feedback', 'quiz'); + $columns[] = 'feedbacktext'; + $headers[] = get_string('feedback', 'quiz'); } if (!$download) { @@ -165,8 +186,8 @@ class quiz_report extends quiz_default_report { $table = new flexible_table('mod-quiz-report-overview-report'); - $table->define_columns($tablecolumns); - $table->define_headers($tableheaders); + $table->define_columns($columns); + $table->define_headers($headers); $table->define_baseurl($reporturlwithdisplayoptions->out()); $table->sortable(true); @@ -216,20 +237,6 @@ class quiz_report extends quiz_default_report { $formatg->set_align('center'); // Here starts workshhet headers - $headers = array(get_string('name'), get_string('startedon', 'quiz'), - get_string('timecompleted', 'quiz'), get_string('attemptduration', 'quiz')); - - if ($showgrades) { - $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade; - } - if($detailedmarks) { - foreach ($questions as $question) { - $headers[] = '#'.$question->number; - } - } - if ($hasfeedback) { - $headers[] = get_string('feedback', 'quiz'); - } $colnum = 0; foreach ($headers as $item) { $myxls->write(0,$colnum,$item,$formatbc); @@ -267,22 +274,7 @@ class quiz_report extends quiz_default_report { $formatg->set_bold(1); $formatg->set_color('green'); $formatg->set_align('center'); - // Here starts workshhet headers - $headers = array(get_string('name'), get_string('startedon', 'quiz'), - get_string('timecompleted', 'quiz'), get_string('attemptduration', 'quiz')); - - if ($showgrades) { - $headers[] = get_string('grade', 'quiz').'/'.$quiz->grade; - } - if($detailedmarks) { - foreach ($questions as $question) { - $headers[] = '#'.$question->number; - } - } - if ($hasfeedback) { - $headers[] = get_string('feedback', 'quiz'); - } $colnum = 0; foreach ($headers as $item) { $myxls->write(0,$colnum,$item,$formatbc); @@ -298,21 +290,7 @@ class quiz_report extends quiz_default_report { header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Pragma: public"); - $headers = get_string('name')."\t".get_string('startedon', 'quiz')."\t". - get_string('timecompleted', 'quiz')."\t".get_string('attemptduration', 'quiz'); - - if ($showgrades) { - $headers .= "\t".get_string('grade', 'quiz')."/".$quiz->grade; - } - if($detailedmarks) { - foreach ($questions as $question) { - $headers .= "\t#".$question->number; - } - } - if ($hasfeedback) { - $headers .= "\t" . get_string('feedback', 'quiz'); - } - echo $headers." \n"; + echo implode("\t", $headers)." \n"; } // Get users with quiz attempt capability 'students'. @@ -331,7 +309,7 @@ class quiz_report extends quiz_default_report { // Construct the SQL $select = 'SELECT '.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '. ($qmsubselect?$qmsubselect.' AS gradedattempt, ':''). - 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '. + 'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, '. 'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration '; // This part is the same for all cases - join users and quiz_attempts tables @@ -361,7 +339,9 @@ class quiz_report extends quiz_default_report { $countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where; - if (!$download) { + if ($download) { + $sort = ''; + } else { // Add extra limits due to initials bar if($table->get_sql_where()) { $where .= ' AND '.$table->get_sql_where(); @@ -419,15 +399,11 @@ class quiz_report extends quiz_default_report { } // Fetch the attempts - if (!empty($from)) { // if we're in the site course and displaying no attempts, it makes no sense to do the query. - if (!$download) { - $attempts = get_records_sql($select.$from.$where.$sort, - $table->get_page_start(), $table->get_page_size()); - } else { - $attempts = get_records_sql($select.$from.$where.$sort); - } + if (!$download) { + $attempts = get_records_sql($select.$from.$where.$sort, + $table->get_page_start(), $table->get_page_size()); } else { - $attempts = array(); + $attempts = get_records_sql($select.$from.$where.$sort); } // Build table rows if (!$download) { @@ -453,19 +429,25 @@ class quiz_report extends quiz_default_report { // Username columns. $row = array(); - if (!$download) { - if ($candelete) { - if ($attempt->attempt){ - $row[] = ''; - } else { - $row[] = ''; - } + if (in_array('checkbox', $columns)){ + if ($attempt->attempt){ + $row[] = ''; + } else { + $row[] = ''; } + } + if (in_array('picture', $columns)){ $row[] = $picture; + } + if (!$download){ $row[] = $userlink; } else { $row[] = fullname($attempt); } + + if (in_array('idnumber', $columns)){ + $row[] = $attempt->idnumber; + } // Timing columns. if ($attempt->attempt) { @@ -513,6 +495,7 @@ class quiz_report extends quiz_default_report { } if($detailedmarks) { + //get the detailled grade data for this attempt if(empty($attempt->attempt)) { foreach($questions as $question) { $row[] = '-'; @@ -623,7 +606,7 @@ class quiz_report extends quiz_default_report { $mform->display(); $imageurl = $CFG->wwwroot.'/mod/quiz/report/overview/overviewgraph.php?id='.$quiz->id; print_heading(get_string('overviewreportgraph', 'quiz_overview')); - echo '
'.get_string('overviewreportgraph', 'quiz_overview').''.get_string('overviewreportgraph', 'quiz_overview').'
'; } return true; }