2006-08-10 21:52:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This script lists student attempts
|
|
|
|
*
|
|
|
|
* @version $Id$
|
|
|
|
* @author Martin Dougiamas, Tim Hunt and others.
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package quiz
|
|
|
|
*//** */
|
|
|
|
|
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
2008-05-05 13:12:11 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/quiz/report/overview/overviewsettings_form.php');
|
2005-06-04 09:58:35 +00:00
|
|
|
|
|
|
|
class quiz_report extends quiz_default_report {
|
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
/**
|
|
|
|
* Display the report.
|
|
|
|
*/
|
|
|
|
function display($quiz, $cm, $course) {
|
2008-05-31 22:18:41 +00:00
|
|
|
global $CFG, $DB;
|
2006-08-10 21:52:07 +00:00
|
|
|
// Define some strings
|
2005-06-04 09:58:35 +00:00
|
|
|
$strreallydel = addslashes(get_string('deleteattemptcheck','quiz'));
|
|
|
|
$strtimeformat = get_string('strftimedatetime');
|
|
|
|
$strreviewquestion = get_string('reviewresponse', 'quiz');
|
|
|
|
|
2007-09-17 16:17:24 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Only print headers if not asked to download data
|
2005-07-22 09:43:23 +00:00
|
|
|
if (!$download = optional_param('download', NULL)) {
|
2008-05-05 13:12:11 +00:00
|
|
|
$this->print_header_and_tabs($cm, $course, $quiz, "overview");
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2005-06-04 09:58:35 +00:00
|
|
|
|
2008-05-07 16:00:56 +00:00
|
|
|
if($attemptids = optional_param('attemptid', array(), PARAM_INT)) {
|
|
|
|
//attempts need to be deleted
|
|
|
|
require_capability('mod/quiz:deleteattempts', $context);
|
|
|
|
$attemptids = optional_param('attemptid', array(), PARAM_INT);
|
|
|
|
foreach($attemptids as $attemptid) {
|
|
|
|
add_to_log($course->id, 'quiz', 'delete attempt', 'report.php?id=' . $cm->id,
|
|
|
|
$attemptid, $cm->id);
|
|
|
|
quiz_delete_attempt($attemptid, $quiz);
|
|
|
|
}
|
|
|
|
//No need for a redirect, any attemptids that do not exist are ignored.
|
|
|
|
//So no problem if the user refreshes and tries to delete the same attempts
|
|
|
|
//twice.
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2007-10-04 15:57:09 +00:00
|
|
|
// Work out some display options - whether there is feedback, and whether scores should be shown.
|
|
|
|
$hasfeedback = quiz_has_feedback($quiz->id) && $quiz->grade > 1.e-7 && $quiz->sumgrades > 1.e-7;
|
|
|
|
$fakeattempt = new stdClass();
|
|
|
|
$fakeattempt->preview = false;
|
|
|
|
$fakeattempt->timefinish = $quiz->timeopen;
|
|
|
|
$reviewoptions = quiz_get_reviewoptions($quiz, $fakeattempt, $context);
|
|
|
|
$showgrades = $quiz->grade && $quiz->sumgrades && $reviewoptions->scores;
|
|
|
|
|
2008-05-05 13:12:11 +00:00
|
|
|
$pageoptions = array();
|
|
|
|
$pageoptions['id'] = $cm->id;
|
|
|
|
$pageoptions['q'] = $quiz->id;
|
|
|
|
$pageoptions['mode'] = 'overview';
|
|
|
|
|
|
|
|
$reporturl = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions);
|
2008-05-08 09:35:08 +00:00
|
|
|
$qmsubselect = quiz_report_qm_filter_subselect($quiz);
|
2008-05-08 09:53:31 +00:00
|
|
|
$mform = new mod_quiz_report_overview_settings($reporturl, compact('qmsubselect', 'quiz'));
|
2008-05-05 13:12:11 +00:00
|
|
|
if ($fromform = $mform->get_data()){
|
|
|
|
$attemptsmode = $fromform->attemptsmode;
|
2008-05-06 17:34:39 +00:00
|
|
|
if ($qmsubselect){
|
|
|
|
//control is not on the form if
|
|
|
|
//the grading method is not set
|
|
|
|
//to grade one attempt per user eg. for average attempt grade.
|
|
|
|
$qmfilter = $fromform->qmfilter;
|
|
|
|
} else {
|
|
|
|
$qmfilter = 0;
|
|
|
|
}
|
2008-05-05 13:12:11 +00:00
|
|
|
set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
|
|
|
|
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
|
|
|
|
$detailedmarks = $fromform->detailedmarks;
|
|
|
|
$pagesize = $fromform->pagesize;
|
|
|
|
} else {
|
2008-05-06 17:34:39 +00:00
|
|
|
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
|
|
|
|
$attemptsmode = optional_param('attemptsmode', QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH, PARAM_INT);
|
2008-05-05 13:12:11 +00:00
|
|
|
$detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
|
|
|
|
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
|
|
|
|
}
|
2008-05-15 13:59:52 +00:00
|
|
|
if (!$reviewoptions->scores) {
|
|
|
|
$detailedmarks = 0;
|
|
|
|
}
|
2008-05-05 13:12:11 +00:00
|
|
|
if ($pagesize < 1) {
|
|
|
|
$pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE;
|
|
|
|
}
|
2008-05-07 16:00:56 +00:00
|
|
|
// We only want to show the checkbox to delete attempts
|
|
|
|
// if the user has permissions and if the report mode is showing attempts.
|
|
|
|
$candelete = has_capability('mod/quiz:deleteattempts', $context)
|
|
|
|
&& ($attemptsmode!= QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO);
|
|
|
|
|
2008-05-05 13:12:11 +00:00
|
|
|
|
|
|
|
$displayoptions = array();
|
|
|
|
$displayoptions['attemptsmode'] = $attemptsmode;
|
2008-05-06 17:34:39 +00:00
|
|
|
$displayoptions['qmfilter'] = $qmfilter;
|
2008-05-05 13:12:11 +00:00
|
|
|
$reporturlwithdisplayoptions = new moodle_url($CFG->wwwroot.'/mod/quiz/report.php', $pageoptions + $displayoptions);
|
2007-10-04 15:57:09 +00:00
|
|
|
|
2007-05-23 10:21:43 +00:00
|
|
|
/// find out current groups mode
|
2007-08-27 03:56:39 +00:00
|
|
|
$currentgroup = groups_get_activity_group($cm, true);
|
2007-10-04 15:57:09 +00:00
|
|
|
|
2007-08-27 03:56:39 +00:00
|
|
|
if ($groupmode = groups_get_activity_groupmode($cm)) { // Groups are being used
|
2005-07-22 09:43:23 +00:00
|
|
|
if (!$download) {
|
2008-05-05 13:12:11 +00:00
|
|
|
groups_print_activity_menu($cm, $reporturlwithdisplayoptions->out());
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2007-04-04 04:05:53 +00:00
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2007-12-12 17:23:55 +00:00
|
|
|
// Print information on the number of existing attempts
|
|
|
|
if (!$download) { //do not print notices when downloading
|
|
|
|
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, false, $currentgroup)) {
|
|
|
|
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-08 09:35:08 +00:00
|
|
|
// Print information on the grading method and whether we are displaying
|
|
|
|
//
|
|
|
|
if (!$download) { //do not print notices when downloading
|
|
|
|
if ($strattempthighlight = quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)) {
|
|
|
|
echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Now check if asked download of data
|
2005-07-22 09:43:23 +00:00
|
|
|
if ($download) {
|
|
|
|
$filename = clean_filename("$course->shortname ".format_string($quiz->name,true));
|
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Define table columns
|
2008-05-09 13:59:36 +00:00
|
|
|
$columns = array();
|
|
|
|
$headers = array();
|
|
|
|
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2008-05-09 13:59:36 +00:00
|
|
|
if (!$download && $candelete) {
|
|
|
|
$columns[]= 'checkbox';
|
|
|
|
$headers[]= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$download && $CFG->grade_report_showuserimage) {
|
|
|
|
$columns[]= 'picture';
|
|
|
|
$headers[]= '';
|
2007-12-12 19:13:09 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 13:59:36 +00:00
|
|
|
$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');
|
|
|
|
|
2007-10-04 15:57:09 +00:00
|
|
|
if ($showgrades) {
|
2008-05-09 13:59:36 +00:00
|
|
|
$columns[] = 'sumgrades';
|
|
|
|
$headers[] = get_string('grade', 'quiz').'/'.$quiz->grade;
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2007-12-12 19:13:09 +00:00
|
|
|
if ($detailedmarks) {
|
2005-06-04 09:58:35 +00:00
|
|
|
// we want to display marks for all questions
|
2008-05-03 13:06:49 +00:00
|
|
|
$questions = quiz_report_load_questions($quiz);
|
|
|
|
foreach ($questions as $id => $question) {
|
|
|
|
// Ignore questions of zero length
|
2008-05-15 13:59:52 +00:00
|
|
|
$columns[] = 'qsgrade'.$id;
|
2008-05-09 13:59:36 +00:00
|
|
|
$headers[] = '#'.$question->number;
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-15 13:59:52 +00:00
|
|
|
|
2006-08-22 17:31:26 +00:00
|
|
|
if ($hasfeedback) {
|
2008-05-09 13:59:36 +00:00
|
|
|
$columns[] = 'feedbacktext';
|
|
|
|
$headers[] = get_string('feedback', 'quiz');
|
2006-08-22 17:31:26 +00:00
|
|
|
}
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
if (!$download) {
|
|
|
|
// Set up the table
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table = new flexible_table('mod-quiz-report-overview-report');
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2008-05-09 13:59:36 +00:00
|
|
|
$table->define_columns($columns);
|
|
|
|
$table->define_headers($headers);
|
2008-05-05 13:12:11 +00:00
|
|
|
$table->define_baseurl($reporturlwithdisplayoptions->out());
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->sortable(true);
|
|
|
|
$table->collapsible(true);
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->column_suppress('picture');
|
|
|
|
$table->column_suppress('fullname');
|
2008-05-15 12:54:01 +00:00
|
|
|
|
|
|
|
$table->no_sorting('feedbacktext');
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->column_class('picture', 'picture');
|
2008-05-15 12:27:27 +00:00
|
|
|
$table->column_class('fullname', 'bold');
|
|
|
|
$table->column_class('sumgrades', 'bold');
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->set_attribute('cellspacing', '0');
|
|
|
|
$table->set_attribute('id', 'attempts');
|
|
|
|
$table->set_attribute('class', 'generaltable generalbox');
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
// Start working -- this is necessary as soon as the niceties are over
|
|
|
|
$table->setup();
|
2006-12-21 20:34:51 +00:00
|
|
|
} else if ($download =='ODS') {
|
|
|
|
require_once("$CFG->libdir/odslib.class.php");
|
|
|
|
|
|
|
|
$filename .= ".ods";
|
|
|
|
// Creating a workbook
|
|
|
|
$workbook = new MoodleODSWorkbook("-");
|
|
|
|
// Sending HTTP headers
|
|
|
|
$workbook->send($filename);
|
|
|
|
// Creating the first worksheet
|
|
|
|
$sheettitle = get_string('reportoverview','quiz');
|
|
|
|
$myxls =& $workbook->add_worksheet($sheettitle);
|
|
|
|
// format types
|
|
|
|
$format =& $workbook->add_format();
|
|
|
|
$format->set_bold(0);
|
|
|
|
$formatbc =& $workbook->add_format();
|
|
|
|
$formatbc->set_bold(1);
|
|
|
|
$formatbc->set_align('center');
|
|
|
|
$formatb =& $workbook->add_format();
|
|
|
|
$formatb->set_bold(1);
|
|
|
|
$formaty =& $workbook->add_format();
|
|
|
|
$formaty->set_bg_color('yellow');
|
|
|
|
$formatc =& $workbook->add_format();
|
|
|
|
$formatc->set_align('center');
|
|
|
|
$formatr =& $workbook->add_format();
|
|
|
|
$formatr->set_bold(1);
|
|
|
|
$formatr->set_color('red');
|
|
|
|
$formatr->set_align('center');
|
|
|
|
$formatg =& $workbook->add_format();
|
|
|
|
$formatg->set_bold(1);
|
|
|
|
$formatg->set_color('green');
|
|
|
|
$formatg->set_align('center');
|
|
|
|
// Here starts workshhet headers
|
|
|
|
|
|
|
|
$colnum = 0;
|
|
|
|
foreach ($headers as $item) {
|
|
|
|
$myxls->write(0,$colnum,$item,$formatbc);
|
|
|
|
$colnum++;
|
|
|
|
}
|
|
|
|
$rownum=1;
|
2006-08-10 21:52:07 +00:00
|
|
|
} else if ($download =='Excel') {
|
2006-01-05 16:43:05 +00:00
|
|
|
require_once("$CFG->libdir/excellib.class.php");
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$filename .= ".xls";
|
2006-08-10 21:52:07 +00:00
|
|
|
// Creating a workbook
|
2006-01-05 16:43:05 +00:00
|
|
|
$workbook = new MoodleExcelWorkbook("-");
|
2006-08-10 21:52:07 +00:00
|
|
|
// Sending HTTP headers
|
2006-01-05 16:43:05 +00:00
|
|
|
$workbook->send($filename);
|
2006-08-10 21:52:07 +00:00
|
|
|
// Creating the first worksheet
|
2006-06-05 14:24:13 +00:00
|
|
|
$sheettitle = get_string('reportoverview','quiz');
|
2005-07-22 09:43:23 +00:00
|
|
|
$myxls =& $workbook->add_worksheet($sheettitle);
|
2006-08-10 21:52:07 +00:00
|
|
|
// format types
|
2005-07-22 09:43:23 +00:00
|
|
|
$format =& $workbook->add_format();
|
|
|
|
$format->set_bold(0);
|
|
|
|
$formatbc =& $workbook->add_format();
|
|
|
|
$formatbc->set_bold(1);
|
|
|
|
$formatbc->set_align('center');
|
|
|
|
$formatb =& $workbook->add_format();
|
|
|
|
$formatb->set_bold(1);
|
|
|
|
$formaty =& $workbook->add_format();
|
|
|
|
$formaty->set_bg_color('yellow');
|
|
|
|
$formatc =& $workbook->add_format();
|
|
|
|
$formatc->set_align('center');
|
|
|
|
$formatr =& $workbook->add_format();
|
|
|
|
$formatr->set_bold(1);
|
|
|
|
$formatr->set_color('red');
|
|
|
|
$formatr->set_align('center');
|
|
|
|
$formatg =& $workbook->add_format();
|
|
|
|
$formatg->set_bold(1);
|
|
|
|
$formatg->set_color('green');
|
|
|
|
$formatg->set_align('center');
|
|
|
|
|
|
|
|
$colnum = 0;
|
|
|
|
foreach ($headers as $item) {
|
|
|
|
$myxls->write(0,$colnum,$item,$formatbc);
|
|
|
|
$colnum++;
|
|
|
|
}
|
|
|
|
$rownum=1;
|
2006-08-10 21:52:07 +00:00
|
|
|
} else if ($download=='CSV') {
|
2005-07-22 09:43:23 +00:00
|
|
|
$filename .= ".txt";
|
|
|
|
|
2005-09-17 13:09:43 +00:00
|
|
|
header("Content-Type: application/download\n");
|
2005-07-22 09:43:23 +00:00
|
|
|
header("Content-Disposition: attachment; filename=\"$filename\"");
|
|
|
|
header("Expires: 0");
|
|
|
|
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
|
|
|
|
header("Pragma: public");
|
|
|
|
|
2008-05-09 13:59:36 +00:00
|
|
|
echo implode("\t", $headers)." \n";
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2008-05-15 12:27:27 +00:00
|
|
|
$students = join(',',array_keys(get_users_by_capability($context, 'mod/quiz:attempt','','','','','','',false)));
|
|
|
|
if (empty($currentgroup)) {
|
|
|
|
// all users who can attempt quizzes
|
|
|
|
$groupstudents = '';
|
|
|
|
$allowed = $students;
|
|
|
|
} else {
|
|
|
|
// all users who can attempt quizzes and who are in the currently selected group
|
|
|
|
$groupstudents = join(',',array_keys(get_users_by_capability($context, 'mod/quiz:attempt','','','','',$currentgroup,'',false)));
|
|
|
|
$allowed = $groupstudents;
|
2008-04-30 04:47:39 +00:00
|
|
|
}
|
2005-07-22 09:43:23 +00:00
|
|
|
|
2005-06-04 09:58:35 +00:00
|
|
|
// Construct the SQL
|
2008-05-15 21:40:00 +00:00
|
|
|
$select = 'SELECT '.sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)').' AS uniqueid, '.
|
2008-05-06 17:34:39 +00:00
|
|
|
($qmsubselect?$qmsubselect.' AS gradedattempt, ':'').
|
2008-05-09 13:59:36 +00:00
|
|
|
'qa.uniqueid AS attemptuniqueid, qa.id AS attempt, u.id AS userid, u.idnumber, u.firstname, u.lastname, u.picture, '.
|
2005-11-18 21:03:05 +00:00
|
|
|
'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
|
2008-04-30 04:47:39 +00:00
|
|
|
|
|
|
|
// This part is the same for all cases - join users and quiz_attempts tables
|
|
|
|
$from = 'FROM '.$CFG->prefix.'user u ';
|
|
|
|
$from .= 'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON qa.userid = u.id AND qa.quiz = '.$quiz->id;
|
2008-05-06 17:34:39 +00:00
|
|
|
if ($qmsubselect && $qmfilter){
|
|
|
|
$from .= ' AND '.$qmsubselect;
|
|
|
|
}
|
|
|
|
switch ($attemptsmode){
|
|
|
|
case QUIZ_REPORT_ATTEMPTS_ALL:
|
|
|
|
// Show all attempts, including students who are no longer in the course
|
|
|
|
$where = ' WHERE qa.id IS NOT NULL AND qa.preview = 0';
|
|
|
|
break;
|
|
|
|
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH:
|
|
|
|
// Show only students with attempts
|
|
|
|
$where = ' WHERE u.id IN (' .$allowed. ') AND qa.preview = 0 AND qa.id IS NOT NULL';
|
|
|
|
break;
|
|
|
|
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
|
|
|
|
// Show only students without attempts
|
|
|
|
$where = ' WHERE u.id IN (' .$allowed. ') AND qa.id IS NULL';
|
|
|
|
break;
|
|
|
|
case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS:
|
|
|
|
// Show all students with or without attempts
|
|
|
|
$where = ' WHERE u.id IN (' .$allowed. ') AND (qa.preview = 0 OR qa.preview IS NULL)';
|
|
|
|
break;
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2008-05-15 12:27:27 +00:00
|
|
|
|
2008-05-15 13:59:52 +00:00
|
|
|
// Add extra limits due to sorting by question grade
|
|
|
|
if ($detailedmarks) {
|
|
|
|
$from .= ' ';
|
|
|
|
// we want to display marks for all questions
|
|
|
|
foreach (array_keys($questions) as $qid) {
|
|
|
|
$select .= ", qs$qid.grade AS qsgrade$qid, qs$qid.event AS qsevent$qid, qs$qid.id AS qsid$qid";
|
|
|
|
$from .= "LEFT JOIN {$CFG->prefix}question_sessions qns$qid ON qns$qid.attemptid = qa.uniqueid AND qns$qid.questionid = $qid ";
|
|
|
|
$from .= "LEFT JOIN {$CFG->prefix}question_states qs$qid ON qs$qid.id = qns$qid.newgraded ";
|
|
|
|
}
|
|
|
|
$select .= ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-30 04:47:39 +00:00
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', 'COALESCE(qa.attempt, 0)').')) '.$from.$where;
|
2008-04-30 04:47:39 +00:00
|
|
|
|
2008-05-30 12:23:10 +00:00
|
|
|
if (!$download){
|
|
|
|
$sort = $table->get_sql_sort();
|
|
|
|
} else {
|
|
|
|
$sort = '';
|
|
|
|
}
|
2008-05-15 13:59:52 +00:00
|
|
|
// Fix some wired sorting
|
|
|
|
if (empty($sort)) {
|
|
|
|
$sort = ' ORDER BY uniqueid';
|
|
|
|
} else {
|
|
|
|
$sort = ' ORDER BY '.$sort;
|
|
|
|
}
|
|
|
|
if (!$download) {
|
2005-07-22 09:43:23 +00:00
|
|
|
// Add extra limits due to initials bar
|
|
|
|
if($table->get_sql_where()) {
|
2005-11-15 22:23:43 +00:00
|
|
|
$where .= ' AND '.$table->get_sql_where();
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
// Count the records NOW, before funky question grade sorting messes up $from
|
2005-11-15 22:23:43 +00:00
|
|
|
if (!empty($countsql)) {
|
|
|
|
$totalinitials = count_records_sql($countsql);
|
|
|
|
if ($table->get_sql_where()) {
|
|
|
|
$countsql .= ' AND '.$table->get_sql_where();
|
|
|
|
}
|
|
|
|
$total = count_records_sql($countsql);
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2005-11-15 22:23:43 +00:00
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->pagesize($pagesize, $total);
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2005-07-22 09:43:23 +00:00
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Fetch the attempts
|
2008-05-09 13:59:36 +00:00
|
|
|
if (!$download) {
|
|
|
|
$attempts = get_records_sql($select.$from.$where.$sort,
|
|
|
|
$table->get_page_start(), $table->get_page_size());
|
2005-11-15 22:23:43 +00:00
|
|
|
} else {
|
2008-05-09 13:59:36 +00:00
|
|
|
$attempts = get_records_sql($select.$from.$where.$sort);
|
2005-11-15 22:23:43 +00:00
|
|
|
}
|
2008-05-15 13:59:52 +00:00
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Build table rows
|
2005-11-15 22:23:43 +00:00
|
|
|
if (!$download) {
|
|
|
|
$table->initialbars($totalinitials>20);
|
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
if ($attempts) {
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2008-05-15 13:59:52 +00:00
|
|
|
foreach ($attempts as $attempt) {
|
2007-10-04 15:57:09 +00:00
|
|
|
|
2008-05-06 17:34:39 +00:00
|
|
|
// Username columns.
|
|
|
|
$row = array();
|
2008-05-09 13:59:36 +00:00
|
|
|
if (in_array('checkbox', $columns)){
|
|
|
|
if ($attempt->attempt){
|
|
|
|
$row[] = '<input type="checkbox" name="attemptid[]" value="'.$attempt->attempt.'" />';
|
|
|
|
} else {
|
|
|
|
$row[] = '';
|
2008-05-06 17:34:39 +00:00
|
|
|
}
|
2008-05-09 13:59:36 +00:00
|
|
|
}
|
|
|
|
if (in_array('picture', $columns)){
|
2008-05-15 13:59:52 +00:00
|
|
|
$picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $picture;
|
2008-05-09 13:59:36 +00:00
|
|
|
}
|
|
|
|
if (!$download){
|
2008-05-15 13:59:52 +00:00
|
|
|
$userlink = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.
|
|
|
|
'&course='.$course->id.'">'.fullname($attempt).'</a>';
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $userlink;
|
|
|
|
} else {
|
|
|
|
$row[] = fullname($attempt);
|
|
|
|
}
|
2008-05-09 13:59:36 +00:00
|
|
|
|
|
|
|
if (in_array('idnumber', $columns)){
|
|
|
|
$row[] = $attempt->idnumber;
|
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
|
|
|
|
// Timing columns.
|
|
|
|
if ($attempt->attempt) {
|
|
|
|
$startdate = userdate($attempt->timestart, $strtimeformat);
|
2005-07-22 09:43:23 +00:00
|
|
|
if (!$download) {
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = '<a href="review.php?q='.$quiz->id.'&attempt='.$attempt->attempt.'">'.$startdate.'</a>';
|
2006-08-10 21:52:07 +00:00
|
|
|
} else {
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $startdate;
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
if ($attempt->timefinish) {
|
|
|
|
$timefinish = userdate($attempt->timefinish, $strtimeformat);
|
|
|
|
$duration = format_time($attempt->duration);
|
2006-02-14 23:24:10 +00:00
|
|
|
if (!$download) {
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = '<a href="review.php?q='.$quiz->id.'&attempt='.$attempt->attempt.'">'.$timefinish.'</a>';
|
2006-08-10 21:52:07 +00:00
|
|
|
} else {
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $timefinish;
|
2007-10-04 15:57:09 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $duration;
|
2007-10-04 15:57:09 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '-';
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = get_string('unfinished', 'quiz');
|
2007-10-04 15:57:09 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '-';
|
|
|
|
$row[] = '-';
|
|
|
|
$row[] = '-';
|
|
|
|
}
|
2007-10-04 15:57:09 +00:00
|
|
|
|
2008-05-06 17:34:39 +00:00
|
|
|
// Grades columns.
|
|
|
|
if ($showgrades) {
|
|
|
|
if ($attempt->timefinish) {
|
|
|
|
$grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
|
|
|
|
if (!$download) {
|
|
|
|
$gradehtml = '<a href="review.php?q='.$quiz->id.'&attempt='.$attempt->attempt.'">'.$grade.'</a>';
|
|
|
|
if ($qmsubselect && $attempt->gradedattempt){
|
|
|
|
$gradehtml = '<div class="highlight">'.$gradehtml.'</div>';
|
2007-12-11 16:55:54 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $gradehtml;
|
2007-10-04 15:57:09 +00:00
|
|
|
} else {
|
2008-05-06 17:34:39 +00:00
|
|
|
$row[] = $grade;
|
2007-10-04 15:57:09 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '-';
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2008-05-15 13:59:52 +00:00
|
|
|
|
2008-05-06 17:34:39 +00:00
|
|
|
}
|
2007-12-11 16:55:54 +00:00
|
|
|
|
2008-05-06 17:34:39 +00:00
|
|
|
if($detailedmarks) {
|
|
|
|
if(empty($attempt->attempt)) {
|
|
|
|
foreach($questions as $question) {
|
|
|
|
$row[] = '-';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach($questions as $questionid => $question) {
|
2008-05-15 13:59:52 +00:00
|
|
|
$state = new object();
|
|
|
|
$state->event = $attempt->{'qsevent'.$questionid};
|
|
|
|
if (question_state_is_graded($state)) {
|
|
|
|
$grade = quiz_rescale_grade($attempt->{'qsgrade'.$questionid}, $quiz);
|
2008-05-06 17:34:39 +00:00
|
|
|
} else {
|
|
|
|
$grade = '--';
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
if (!$download) {
|
|
|
|
$grade = $grade.'/'.quiz_rescale_grade($question->grade, $quiz);
|
|
|
|
$row[] = link_to_popup_window('/mod/quiz/reviewquestion.php?state='.
|
2008-05-15 13:59:52 +00:00
|
|
|
$attempt->{'qsid'.$questionid}.'&number='.$question->number,
|
2008-05-06 17:34:39 +00:00
|
|
|
'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
|
|
|
|
} else {
|
|
|
|
$row[] = $grade;
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
}
|
2007-10-04 15:57:09 +00:00
|
|
|
|
2008-05-06 17:34:39 +00:00
|
|
|
// Feedback column.
|
|
|
|
if ($hasfeedback) {
|
|
|
|
if ($attempt->timefinish) {
|
2008-05-15 12:27:27 +00:00
|
|
|
$row[] = quiz_report_feedback_for_grade(quiz_rescale_grade($attempt->sumgrades, $quiz), $quiz->id);
|
2008-05-06 17:34:39 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '-';
|
2006-08-22 17:31:26 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
}
|
|
|
|
if (!$download) {
|
|
|
|
$table->add_data($row);
|
|
|
|
} else if ($download == 'Excel' or $download == 'ODS') {
|
|
|
|
$colnum = 0;
|
|
|
|
foreach($row as $item){
|
|
|
|
$myxls->write($rownum,$colnum,$item,$format);
|
|
|
|
$colnum++;
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2008-05-06 17:34:39 +00:00
|
|
|
$rownum++;
|
|
|
|
} else if ($download=='CSV') {
|
|
|
|
$text = implode("\t", $row);
|
|
|
|
echo $text." \n";
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2008-05-15 12:27:27 +00:00
|
|
|
//end of adding data from attempts data to table / download
|
|
|
|
//now add averages :
|
|
|
|
if (!$download && $attempts){
|
|
|
|
|
|
|
|
$averagesql = "SELECT AVG(qg.grade) AS grade " .
|
|
|
|
"FROM {$CFG->prefix}quiz_grades qg " .
|
|
|
|
"WHERE quiz=".$quiz->id;
|
|
|
|
|
|
|
|
$table->add_separator();
|
|
|
|
if ($groupstudents){
|
|
|
|
$groupaveragesql = $averagesql." AND qg.userid IN ($groupstudents)";
|
|
|
|
$groupaverage = get_record_sql($groupaveragesql);
|
|
|
|
$groupaveragerow = array('fullname' => get_string('groupavg', 'grades'),
|
|
|
|
'sumgrades' => round($groupaverage->grade, $quiz->decimalpoints),
|
|
|
|
'feedbacktext'=> quiz_report_feedback_for_grade($groupaverage->grade, $quiz->id));
|
2008-05-15 13:59:52 +00:00
|
|
|
if($detailedmarks && $qmsubselect) {
|
2008-05-15 12:27:27 +00:00
|
|
|
$avggradebyq = quiz_get_average_grade_for_questions($quiz, $groupstudents);
|
|
|
|
$groupaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
|
|
|
|
}
|
|
|
|
$table->add_data_keyed($groupaveragerow);
|
|
|
|
}
|
|
|
|
$overallaverage = get_record_sql($averagesql." AND qg.userid IN ($students)");
|
|
|
|
$overallaveragerow = array('fullname' => get_string('overallaverage', 'grades'),
|
|
|
|
'sumgrades' => round($overallaverage->grade, $quiz->decimalpoints),
|
|
|
|
'feedbacktext'=> quiz_report_feedback_for_grade($overallaverage->grade, $quiz->id));
|
2008-05-15 13:59:52 +00:00
|
|
|
if($detailedmarks && $qmsubselect) {
|
2008-05-15 12:27:27 +00:00
|
|
|
$avggradebyq = quiz_get_average_grade_for_questions($quiz, $students);
|
|
|
|
$overallaveragerow += quiz_format_average_grade_for_questions($avggradebyq, $questions, $quiz, $download);
|
|
|
|
}
|
|
|
|
$table->add_data_keyed($overallaveragerow);
|
|
|
|
}
|
2005-09-17 13:09:43 +00:00
|
|
|
if (!$download) {
|
2006-08-10 21:52:07 +00:00
|
|
|
// Start form
|
2005-07-22 09:43:23 +00:00
|
|
|
echo '<div id="tablecontainer">';
|
2008-05-05 13:12:11 +00:00
|
|
|
echo '<form id="attemptsform" method="post" action="' . $reporturlwithdisplayoptions->out(true) .
|
2008-05-07 16:00:56 +00:00
|
|
|
'" onsubmit="confirm(\''.$strreallydel.'\');">';
|
2008-05-05 13:12:11 +00:00
|
|
|
echo $reporturlwithdisplayoptions->hidden_params_out();
|
2007-02-28 07:11:58 +00:00
|
|
|
echo '<div>';
|
2005-09-17 13:09:43 +00:00
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Print table
|
2005-07-22 09:43:23 +00:00
|
|
|
$table->print_html();
|
|
|
|
|
2006-08-10 21:52:07 +00:00
|
|
|
// Print "Select all" etc.
|
2008-05-07 16:00:56 +00:00
|
|
|
if (!empty($attempts) && $candelete) {
|
2005-11-15 22:23:43 +00:00
|
|
|
echo '<table id="commands">';
|
|
|
|
echo '<tr><td>';
|
2007-10-04 15:57:09 +00:00
|
|
|
echo '<a href="javascript:select_all_in(\'DIV\',null,\'tablecontainer\');">'.
|
|
|
|
get_string('selectall', 'quiz').'</a> / ';
|
|
|
|
echo '<a href="javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');">'.
|
|
|
|
get_string('selectnone', 'quiz').'</a> ';
|
2005-11-15 22:23:43 +00:00
|
|
|
echo ' ';
|
2008-05-07 16:00:56 +00:00
|
|
|
echo '<input type="submit" value="'.get_string('deleteselected', 'quiz_overview').'"/>';
|
2005-11-15 22:23:43 +00:00
|
|
|
echo '</td></tr></table>';
|
|
|
|
}
|
2006-08-10 21:52:07 +00:00
|
|
|
// Close form
|
2007-02-28 07:11:58 +00:00
|
|
|
echo '</div>';
|
2005-07-22 09:43:23 +00:00
|
|
|
echo '</form></div>';
|
2007-06-05 14:56:12 +00:00
|
|
|
|
2005-11-15 22:23:43 +00:00
|
|
|
if (!empty($attempts)) {
|
2007-01-09 09:07:16 +00:00
|
|
|
echo '<table class="boxaligncenter"><tr>';
|
2005-11-15 22:23:43 +00:00
|
|
|
echo '<td>';
|
2008-05-05 13:12:11 +00:00
|
|
|
print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'ODS'),
|
|
|
|
get_string('downloadods'));
|
2006-12-21 20:34:51 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
echo '<td>';
|
2008-05-05 13:12:11 +00:00
|
|
|
print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'Excel'),
|
|
|
|
get_string('downloadexcel'));
|
2005-11-15 22:23:43 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
echo '<td>';
|
2008-05-05 13:12:11 +00:00
|
|
|
print_single_button($reporturl->out(true), $pageoptions + $displayoptions + array('download' => 'CSV'),
|
|
|
|
get_string('downloadtext'));
|
2005-11-15 22:23:43 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
echo "<td>";
|
2006-06-30 10:31:44 +00:00
|
|
|
helpbutton('overviewdownload', get_string('overviewdownload', 'quiz_overview'), 'quiz');
|
2005-11-15 22:23:43 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
echo '</tr></table>';
|
|
|
|
}
|
2005-07-22 09:43:23 +00:00
|
|
|
}
|
2006-08-10 21:52:07 +00:00
|
|
|
} else {
|
2005-07-22 09:43:23 +00:00
|
|
|
if (!$download) {
|
|
|
|
$table->print_html();
|
|
|
|
}
|
2005-06-04 09:58:35 +00:00
|
|
|
}
|
2008-05-06 18:04:03 +00:00
|
|
|
if ($download == 'Excel' or $download == 'ODS') {
|
|
|
|
$workbook->close();
|
|
|
|
exit;
|
|
|
|
} else if ($download == 'CSV') {
|
|
|
|
exit;
|
|
|
|
}
|
2008-05-05 13:12:11 +00:00
|
|
|
if (!$download) {
|
|
|
|
// Print display options
|
|
|
|
$mform->set_data($displayoptions +compact('detailedmarks', 'pagesize'));
|
|
|
|
$mform->display();
|
2008-05-15 12:27:27 +00:00
|
|
|
if ($attempts){
|
|
|
|
$imageurl = $CFG->wwwroot.'/mod/quiz/report/overview/overviewgraph.php?id='.$quiz->id;
|
|
|
|
print_heading(get_string('overviewreportgraph', 'quiz_overview'));
|
|
|
|
echo '<div class="mdl-align"><img src="'.$imageurl.'" alt="'.get_string('overviewreportgraph', 'quiz_overview').'" /></div>';
|
|
|
|
}
|
2006-04-12 22:48:58 +00:00
|
|
|
}
|
2005-06-04 09:58:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-27 01:28:25 +00:00
|
|
|
?>
|