@ -1,4 +1,19 @@
<?php
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see < http: / / www . gnu . org / licenses / > .
/**
/**
* This script lists student attempts
* This script lists student attempts
*
*
@ -15,38 +30,38 @@ class game_report extends game_default_report {
/**
/**
* Display the report.
* Display the report.
*/
*/
function display($game, $cm, $course) {
public function display($game, $cm, $course) {
global $CFG, $SESSION, $db, $QTYPES;
global $CFG, $SESSION, $db, $QTYPES;
// Define some strings
// Define some strings.
$strreallydel = addslashes(get_string('deleteattemptcheck','game'));
$strreallydel = addslashes(get_string('deleteattemptcheck', 'game'));
$strtimeformat = get_string('strftimedatetime');
$strtimeformat = get_string('strftimedatetime');
$strreviewquestion = get_string('reviewresponse', 'quiz');
$strreviewquestion = get_string('reviewresponse', 'quiz');
// Only print headers if not asked to download data
// Only print headers if not asked to download data.
if (!$download = optional_param('download', NULL )) {
if (!$download = optional_param('download', null )) {
$this->print_header_and_tabs($cm, $course, $game, $reportmode="overview");
$this->print_header_and_tabs($cm, $course, $game, $reportmode = "overview");
}
}
// Deal with actions
// Deal with actions.
$action = optional_param('action', '', PARAM_ACTION);
$action = optional_param('action', '', PARAM_ACTION);
switch($action) {
switch ($action) {
case 'delete': // Some attempts need to be deleted
case 'delete': // Some attempts need to be deleted.
$attemptids = optional_param('attemptid', array(), PARAM_INT);
$attemptids = optional_param('attemptid', array(), PARAM_INT);
foreach($attemptids as $attemptid) {
foreach ($attemptids as $attemptid) {
if ($attemptid & & $todelete = get_record('game_attempts', 'id', $attemptid)) {
if ($attemptid & & $todelete = get_record('game_attempts', 'id', $attemptid)) {
delete_records('game_attempts', 'id', $attemptid);
delete_records('game_attempts', 'id', $attemptid);
delete_records('game_queries', 'attemptid', $attemptid);
delete_records('game_queries', 'attemptid', $attemptid);
// Search game_attempts for other instances by this user.
// Search game_attempts for other instances by this user.
// If none, then delete record for this game, this user from game_grades
// If none, then delete record for this game, this user from game_grades.
// else recalculate best grade
// else recalculate best grade.
$userid = $todelete->userid;
$userid = $todelete->userid;
if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
if (!record_exists('game_attempts', 'userid', $userid, 'gameid', $game->id)) {
delete_records('game_grades', 'userid', $userid,'gameid', $game->id);
delete_records('game_grades', 'userid', $userid, 'gameid', $game->id);
} else {
} else {
game_save_best_score( $game, $userid);
game_save_best_score( $game, $userid);
}
}
@ -55,12 +70,14 @@ class game_report extends game_default_report {
break;
break;
}
}
// Print information on the number of existing attempts
// Print information on the number of existing attempts.
if (!$download) { //do not print notices when downloading
if (!$download) {
// Do not print notices when downloading.
if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
if ($attemptnum = count_records('game_attempts', 'gameid', $game->id)) {
$a = new stdClass;
$a = new stdClass;
$a->attemptnum = $attemptnum;
$a->attemptnum = $attemptnum;
$a->studentnum = count_records_select('game_attempts', "gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentnum = count_records_select('game_attempts',
"gameid = '$game->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
$a->studentstring = $course->students;
$a->studentstring = $course->students;
notify( get_string('numattempts', 'game', $a));
notify( get_string('numattempts', 'game', $a));
@ -68,8 +85,8 @@ class game_report extends game_default_report {
}
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// find out current groups mode
// Find out current groups mode.
if ($groupmode = groupmode($course, $cm)) { // Groups are being used
if ($groupmode = groupmode($course, $cm)) { // Groups are being used.
if (!$download) {
if (!$download) {
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id& mode=overview");
$currentgroup = setup_and_print_groups($course, $groupmode, "report.php?id=$cm->id& mode=overview");
} else {
} else {
@ -79,7 +96,7 @@ class game_report extends game_default_report {
$currentgroup = get_and_set_current_group($course, $groupmode);
$currentgroup = get_and_set_current_group($course, $groupmode);
}
}
// Set table options
// Set table options.
$noattempts = optional_param('noattempts', 0, PARAM_INT);
$noattempts = optional_param('noattempts', 0, PARAM_INT);
$detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
$detailedmarks = optional_param('detailedmarks', 0, PARAM_INT);
$pagesize = optional_param('pagesize', 10, PARAM_INT);
$pagesize = optional_param('pagesize', 10, PARAM_INT);
@ -88,24 +105,25 @@ class game_report extends game_default_report {
$pagesize = 10;
$pagesize = 10;
}
}
// Now check if asked download of data
// Now check if asked download of data.
if ($download) {
if ($download) {
$filename = clean_filename("$course->shortname ".format_string($game->name,true));
$filename = clean_filename("$course->shortname ".format_string($game->name, true));
$sort = '';
$sort = '';
}
}
// Define table columns
// Define table columns.
$tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
$tablecolumns = array('checkbox', 'picture', 'fullname', 'timestart', 'timefinish', 'duration');
$tableheaders = array(NULL, '', get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted','game'), get_string('attemptduration', 'game'));
$tableheaders = array(null, '', get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
if ($game->grade) {
$tablecolumns[] = 'grade';
$tablecolumns[] = 'grade';
$tableheaders[] = get_string('grade', 'game').'/'.$game->grade;
$tableheaders[] = get_string('grade', 'game').'/'.$game->grade;
}
}
if($detailedmarks) {
if ($detailedmarks) {
// we want to display marks for all questions
// We want to display marks for all questions.
// Start by getting all questions
// Start by getting all questions.
$questionlist = game_questions_in_game( $game->questions);
$questionlist = game_questions_in_game( $game->questions);
$questionids = explode(',', $questionlist);
$questionids = explode(',', $questionlist);
$sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance".
$sql = "SELECT q.*, i.score AS maxgrade, i.id AS instance".
@ -114,18 +132,18 @@ class game_report extends game_default_report {
" WHERE i.gameid = '$game->id' AND q.id = i.questionid".
" WHERE i.gameid = '$game->id' AND q.id = i.questionid".
" AND q.id IN ($questionlist)";
" AND q.id IN ($questionlist)";
if (!$questions = get_records_sql($sql)) {
if (!$questions = get_records_sql($sql)) {
print_error('No questions found');
print_error('No questions found');
}
}
$number = 1;
$number = 1;
foreach($questionids as $key => $id) {
foreach ($questionids as $key => $id) {
if ($questions[$id]->length) {
if ($questions[$id]->length) {
// Only print questions of non-zero length
// Only print questions of non-zero length.
$tablecolumns[] = '$'.$id;
$tablecolumns[] = '$'.$id;
$tableheaders[] = '#'.$number;
$tableheaders[] = '#'.$number;
$questions[$id]->number = $number;
$questions[$id]->number = $number;
$number += $questions[$id]->length;
$number += $questions[$id]->length;
} else {
} else {
// get rid of zero length questions
// Get rid of zero length questions.
unset($questions[$id]);
unset($questions[$id]);
unset($questionids[$key]);
unset($questionids[$key]);
}
}
@ -138,7 +156,7 @@ class game_report extends game_default_report {
}
}
if (!$download) {
if (!$download) {
// Set up the table
// Set up the table.
$table = new flexible_table('mod-game-report-overview-report');
$table = new flexible_table('mod-game-report-overview-report');
@ -160,20 +178,20 @@ class game_report extends game_default_report {
$table->set_attribute('id', 'attempts');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
$table->setup();
} else if ($download =='ODS') {
} else if ($download == 'ODS') {
require_once("$CFG->libdir/odslib.class.php");
require_once("$CFG->libdir/odslib.class.php");
$filename .= ".ods";
$filename .= ".ods";
// Creating a workbook
// Creating a workbook.
$workbook = new MoodleODSWorkbook("-");
$workbook = new MoodleODSWorkbook("-");
// Sending HTTP headers
// Sending HTTP headers.
$workbook->send($filename);
$workbook->send($filename);
// Creating the first worksheet
// Creating the first worksheet.
$sheettitle = get_string('reportoverview','game');
$sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle);
$myxls =& $workbook->add_worksheet($sheettitle);
// format types
// Format types.
$format =& $workbook->add_format();
$format =& $workbook->add_format();
$format->set_bold(0);
$format->set_bold(0);
$formatbc =& $workbook->add_format();
$formatbc =& $workbook->add_format();
@ -193,8 +211,8 @@ class game_report extends game_default_report {
$formatg->set_bold(1);
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_color('green');
$formatg->set_align('center');
$formatg->set_align('center');
// Here starts workshhet headers
// Here starts workshhet headers.
$headers = array(get_string('fullname'),
$headers = array(get_string('fullname'),
get_string('startedon', 'game'),
get_string('startedon', 'game'),
get_string('timecompleted', 'game'),
get_string('timecompleted', 'game'),
@ -204,7 +222,7 @@ class game_report extends game_default_report {
if ($game->grade) {
if ($game->grade) {
$headers[] = get_string('grade', 'game').'/'.$game->grade;
$headers[] = get_string('grade', 'game').'/'.$game->grade;
}
}
if($detailedmarks) {
if ($detailedmarks) {
foreach ($questionids as $id) {
foreach ($questionids as $id) {
$headers[] = '#'.$questions[$id]->number;
$headers[] = '#'.$questions[$id]->number;
}
}
@ -214,22 +232,22 @@ class game_report extends game_default_report {
}
}
$colnum = 0;
$colnum = 0;
foreach ($headers as $item) {
foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc);
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
$colnum++;
}
}
$rownum=1;
$rownum = 1;
} else if ($download =='Excel') {
} else if ($download == 'Excel') {
require_once("$CFG->libdir/excellib.class.php");
require_once("$CFG->libdir/excellib.class.php");
$filename .= ".xls";
$filename .= ".xls";
// Creating a workbook
// Creating a workbook.
$workbook = new MoodleExcelWorkbook("-");
$workbook = new MoodleExcelWorkbook("-");
// Sending HTTP headers
// Sending HTTP headers.
$workbook->send($filename);
$workbook->send($filename);
// Creating the first worksheet
// Creating the first worksheet.
$sheettitle = get_string('reportoverview','game');
$sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle);
$myxls =& $workbook->add_worksheet($sheettitle);
// format types
// Format types.
$format =& $workbook->add_format();
$format =& $workbook->add_format();
$format->set_bold(0);
$format->set_bold(0);
$formatbc =& $workbook->add_format();
$formatbc =& $workbook->add_format();
@ -249,14 +267,15 @@ class game_report extends game_default_report {
$formatg->set_bold(1);
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_color('green');
$formatg->set_align('center');
$formatg->set_align('center');
// Here starts workshhet headers
$headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
// Here starts workshhet headers.
$headers = array(get_string('fullname'), get_string('startedon', 'game'),
get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
if ($game->grade) {
$headers[] = get_string('grade', 'game').'/'.$game->grade;
$headers[] = get_string('grade', 'game').'/'.$game->grade;
}
}
if($detailedmarks) {
if ($detailedmarks) {
foreach ($questionids as $id) {
foreach ($questionids as $id) {
$headers[] = '#'.$questions[$id]->number;
$headers[] = '#'.$questions[$id]->number;
}
}
@ -266,11 +285,11 @@ class game_report extends game_default_report {
}
}
$colnum = 0;
$colnum = 0;
foreach ($headers as $item) {
foreach ($headers as $item) {
$myxls->write(0,$colnum,$item,$formatbc);
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
$colnum++;
}
}
$rownum=1;
$rownum = 1;
} else if ($download=='CSV') {
} else if ($download == 'CSV') {
$filename .= ".txt";
$filename .= ".txt";
header("Content-Type: application/download\n");
header("Content-Type: application/download\n");
@ -279,12 +298,13 @@ class game_report extends game_default_report {
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
header("Pragma: public");
header("Pragma: public");
$headers = get_string('fullname')."\t".get_string('startedon', 'game')."\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game');
$headers = get_string('fullname')."\t".get_string('startedon', 'game').
"\t".get_string('timecompleted', 'game')."\t".get_string('attemptduration', 'game');
if ($game->grade) {
if ($game->grade) {
$headers .= "\t".get_string('grade', 'game')."/".$game->grade;
$headers .= "\t".get_string('grade', 'game')."/".$game->grade;
}
}
if($detailedmarks) {
if ($detailedmarks) {
foreach ($questionids as $id) {
foreach ($questionids as $id) {
$headers .= "\t#".$questions[$id]->number;
$headers .= "\t#".$questions[$id]->number;
}
}
@ -297,48 +317,54 @@ class game_report extends game_default_report {
$contextlists = get_related_contexts_string( get_context_instance( CONTEXT_COURSE, $course->id));
$contextlists = get_related_contexts_string( get_context_instance( CONTEXT_COURSE, $course->id));
// Construct the SQL
// Construct the SQL.
$select = 'SELECT qa.id,'.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
$select = 'SELECT qa.id,'.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
'qa.id as attemptuniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
'qa.id 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.firstname, u.lastname, u.picture, '.
'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
'qa.score, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
if ($course->id != SITEID) { // this is too complicated, so just do it for each of the four cases.
if ($course->id != SITEID) {
// This is too complicated, so just do it for each of the four cases.
if (!empty($currentgroup) & & empty($noattempts)) {
if (!empty($currentgroup) & & empty($noattempts)) {
// w e want a particular group and we only want to see students WITH attempts.
// W e want a particular group and we only want to see students WITH attempts.
// So join on groups_members and do an inner join on attempts.
// So join on groups_members and do an inner join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql().
groups_members_join_sql().
'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
'JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' . $contextlists . ' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0';
$where = ' WHERE ra.contextid ' . $contextlists .
' AND '. groups_members_where_sql($currentgroup) .' AND qa.preview = 0';
} else if (!empty($currentgroup) & & !empty($noattempts)) {
} else if (!empty($currentgroup) & & !empty($noattempts)) {
// We want a particular group and we want to do something funky with attempts
// We want a particular group and we want to do something funky with attempts.
// So join on groups_members and left join on attempts...
// So join on groups_members and left join on attempts...
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
groups_members_join_sql().
groups_members_join_sql().
'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
'LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = ' WHERE ra.contextid ' .$contextlists . ' AND '.groups_members_where_sql($currentgroup);
$where = ' WHERE ra.contextid ' .$contextlists . ' AND '.groups_members_where_sql($currentgroup);
if ($noattempts == 1) {
if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
// Noattempts = 1 means only no attempts, so make the left join ask.
$where .= ' AND qa.userid IS NULL'; // show ONLY no attempts;
// For only records where the right is null (no attempts).
$where .= ' AND qa.userid IS NULL'; // Show ONLY no attempts.
} else {
} else {
// We are including attempts, so exclude previews.
// We are including attempts, so exclude previews.
$where .= ' AND qa.preview = 0';
$where .= ' AND qa.preview = 0';
}
}
} else if (empty($currentgroup)) {
} else if (empty($currentgroup)) {
// We don't care about group, and we to do something funky with attempts
// We don't care about group, and we to do something funky with attempts.
// So do a left join on attempts
// So do a left join on attempts.
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$from = 'FROM {user} u JOIN {role_assignments} ra ON ra.userid = u.id '.
' LEFT JOIN {game_attempts} qa ON u.id = qa.userid AND qa.gameid = '.$game->id;
$where = " WHERE ra.contextid $contextlists";
$where = " WHERE ra.contextid $contextlists";
if (empty($noattempts)) {
if (empty($noattempts)) {
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0'; // show ONLY students with attempts;
// Show ONLY students with attempts.
$where .= ' AND qa.userid IS NOT NULL AND qa.preview = 0';
} else if ($noattempts == 1) {
} else if ($noattempts == 1) {
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
// The noattempts = 1 means only no attempts,.
$where .= ' AND qa.userid IS NULL'; // show ONLY students without attempts;
// So make the left join ask for only records where the right is null (no attempts).
// Show ONLY students without attempts.
$where .= ' AND qa.userid IS NULL';
} else if ($noattempts == 3) {
} else if ($noattempts == 3) {
// we want all attempts
// We want all attempts.
$from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
$from = 'FROM {user} u JOIN {game_attempts} qa ON u.id = qa.userid ';
$where = ' WHERE qa.gameid = '.$game->id.' AND qa.preview = 0';
$where = ' WHERE qa.gameid = '.$game->id.' AND qa.preview = 0';
} // noattempts = 2 means we want all students, with or without attempts
} // The noattempts = 2 means we want all students, with or without attempts.
}
}
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where;
$countsql = 'SELECT COUNT(DISTINCT('.sql_concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).')) '.$from.$where;
} else {
} else {
@ -349,36 +375,35 @@ class game_report extends game_default_report {
}
}
}
}
if (!$download) {
if (!$download) {
// Add extra limits due to initials bar
// Add extra limits due to initials bar.
if($table->get_sql_where()) {
if ($table->get_sql_where()) {
$where .= ' AND '.$table->get_sql_where();
$where .= ' AND '.$table->get_sql_where();
}
}
// Count the records NOW, before funky question grade sorting messes up $from
// Count the records NOW, before funky question grade sorting messes up $from.
if (!empty($countsql)) {
if (!empty($countsql)) {
$totalinitials = count_records_sql($countsql);
$totalinitials = count_records_sql($countsql);
if ($table->get_sql_where()) {
if ($table->get_sql_where()) {
$countsql .= ' AND '.$table->get_sql_where();
$countsql .= ' AND '.$table->get_sql_where();
}
}
$total = count_records_sql($countsql);
$total = count_records_sql($countsql);
}
}
// Add extra limits due to sorting by question grade
// Add extra limits due to sorting by question grade.
if($sort = $table->get_sql_sort()) {
if ($sort = $table->get_sql_sort()) {
$sortparts = explode(',', $sort);
$sortparts = explode(',', $sort);
$newsort = array();
$newsort = array();
$questionsort = false;
$questionsort = false;
foreach($sortparts as $sortpart) {
foreach ($sortparts as $sortpart) {
$sortpart = trim($sortpart);
$sortpart = trim($sortpart);
if(substr($sortpart, 0, 1) == '$') {
if (substr($sortpart, 0, 1) == '$') {
if(!$questionsort) {
if (!$questionsort) {
$qid = intval(substr($sortpart, 1));
$qid = intval(substr($sortpart, 1));
$select .= ', grade ';
$select .= ', grade ';
$from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id '.
$from .= ' LEFT JOIN {question_sessions} qns ON qns.attemptid = qa.id '.
'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded ';
'LEFT JOIN {question_states} qs ON qs.id = qns.newgraded ';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
$newsort[] = 'grade '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
$newsort[] = 'grade '.(strpos($sortpart, 'ASC') ? 'ASC' : 'DESC');
$questionsort = true;
$questionsort = true;
}
}
} else {
} else {
@ -386,14 +411,13 @@ class game_report extends game_default_report {
}
}
}
}
// Reconstruct the sort string
// Reconstruct the sort string.
$sort = ' ORDER BY '.implode(', ', $newsort);
$sort = ' ORDER BY '.implode(', ', $newsort);
}
}
// Fix some wired sorting
// Fix some wired sorting.
if (empty($sort)) {
if (empty($sort)) {
//$sort = ' ORDER BY uniqueid';
$sort = ' ORDER BY qa.id';
$sort = ' ORDER BY qa.id';
}
}
$table->pagesize($pagesize, $total);
$table->pagesize($pagesize, $total);
@ -402,15 +426,16 @@ class game_report extends game_default_report {
// If there is feedback, include it in the query.
// If there is feedback, include it in the query.
if ($hasfeedback) {
if ($hasfeedback) {
$select .= ', qf.feedbacktext ';
$select .= ', qf.feedbacktext ';
$from .= " JOIN {game_feedback} AS qf ON " .
$from .= " JOIN {game_feedback} qf ON " .
"qf.gameid = $game->id AND qf.mingrade < = qa.score * $game->grade AND qa.score * $game->grade < qf.maxgrade " ;
"qf.gameid = $game->id AND qf.mingrade < = qa.score * $game->grade AND qa.score * $game->grade < qf.maxgrade " ;
}
}
// Fetch the attempts
// 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 (!empty($from)) {
// If we're in the site course and displaying no attempts, it makes no sense to do the query.
if (!$download) {
if (!$download) {
$attempts = get_records_sql($select.$from.$where.$sort,
$attempts = get_records_sql($select.$from.$where.$sort,
$table->get_page_start(), $table->get_page_size());
$table->get_page_start(), $table->get_page_size());
} else {
} else {
$attempts = get_records_sql($select.$from.$where.$sort);
$attempts = get_records_sql($select.$from.$where.$sort);
}
}
@ -418,66 +443,81 @@ class game_report extends game_default_report {
$attempts = array();
$attempts = array();
}
}
// Build table rows.
// Build table rows
if (!$download) {
if (!$download) {
$table->initialbars($totalinitials>20);
$table->initialbars($totalinitials > 20);
}
}
if(!empty($attempts) || !empty($noattempts)) {
if (!empty($attempts) || !empty($noattempts)) {
if ($attempts) {
if ($attempts) {
foreach ($attempts as $attempt) {
foreach ($attempts as $attempt) {
$picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
$picture = print_user_picture($attempt->userid, $course->id, $attempt->picture, false, true);
/* Uncomment the commented lines below if you are choosing to show unenrolled users and
// uncomment the commented lines below if you are choosing to show unenrolled users and
* have uncommented the corresponding lines earlier in this script
// have uncommented the corresponding lines earlier in this script
* if (in_array($attempt->userid, $unenrolledusers)) {
//if (in_array($attempt->userid, $unenrolledusers)) {
* $userlink = '< a class = "dimmed" href = "'.$CFG- > wwwroot.
// $userlink = '< a class = "dimmed" href = "'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&course='.$course->id.'" > '.fullname($attempt).'< / a > ';
* '/user/view.php?id='.$attempt->userid.'& course='.$course->id.'">'.fullname($attempt).'< / a > ';
//}
*}
//else {
*else {
$userlink = '< a href = "'.$CFG->wwwroot.'/user/view.php?id='.$attempt->userid.'&course='.$course->id.'" > '.fullname($attempt).'< / a > ';
* $userlink = '< a href = "'.$CFG- > wwwroot.'/user/view.php?id='.
//}
* $attempt->userid.'& course='.$course->id.'">'.fullname($attempt).'< / a > ';
*}
*/
if (!$download) {
if (!$download) {
$row = array(
$row = array(
'< input type = "checkbox" name = "attemptid[]" value = "'.$attempt->attempt.'" / > ',
'< input type = "checkbox" name = "attemptid[]" value = "'.$attempt->attempt.'" / > ',
$picture,
$picture,
$userlink,
$userlink,
empty($attempt->attempt) ? '-' : '< a href = "review.php?q='.$game->id.'&attempt='.$attempt->attempt.'" > '.userdate($attempt->timestart, $strtimeformat).'< / a > ',
empty($attempt->attempt) ? '-' : '< a href = "review.php?q='.
empty($attempt->timefinish) ? '-' : '< a href = "review.php?q='.$game->id.'&attempt='.$attempt->attempt.'" > '.userdate($attempt->timefinish, $strtimeformat).'< / a > ',
$game->id.'& attempt='.$attempt->attempt.'">'.
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))
userdate($attempt->timestart, $strtimeformat).'< / a > ',
empty($attempt->timefinish) ? '-' : '< a href = "review.php?q='.
$game->id.'& attempt='.$attempt->attempt.'">'.
userdate($attempt->timefinish, $strtimeformat).'< / a > ',
empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time(
$attempt->duration))
);
);
} else {
} else {
$row = array(fullname($attempt),
$row = array(fullname($attempt),
empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
empty($attempt->attempt) ? '-' : userdate($attempt->timestart, $strtimeformat),
empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat),
empty($attempt->timefinish) ? '-' : userdate($attempt->timefinish, $strtimeformat),
empty($attempt->attempt) ? '-' : (empty($attempt->timefinish) ? get_string('unfinished', 'game') : format_time($attempt->duration))
empty($attempt->attempt) ? '-' : (
empty($attempt->timefinish) ? get_string(
'unfinished', 'game') : format_time($attempt->duration))
);
);
}
}
if ($game->grade) {
if ($game->grade) {
if (!$download) {
if (!$download) {
$row[] = $attempt->score === NULL ? '-' : '< a href = "review.php?q='.$game->id.'&attempt='.$attempt->attempt.'" > '.round($attempt->score * $game->grade,$game->decimalpoints).'< / a > ';
$row[] = $attempt->score === null ? '-' : '< a href = "review.php?q='.
$game->id.'& attempt='.$attempt->attempt.'">'.
round($attempt->score * $game->grade, $game->decimalpoints).'< / a > ';
} else {
} else {
$row[] = $attempt->score === NULL ? '-' : round($attempt->score * $game->grade,$game->decimalpoints);
$row[] = $attempt->score === null ? '-' : round($attempt->score * $game->grade, $game->decimalpoints);
}
}
}
}
if($detailedmarks) {
if ($detailedmarks) {
if(empty($attempt->attempt)) {
if (empty($attempt->attempt)) {
foreach($questionids as $questionid) {
foreach ($questionids as $questionid) {
$row[] = '-';
$row[] = '-';
}
}
} else {
} else {
foreach($questionids as $questionid) {
foreach ($questionids as $questionid) {
if ($gradedstateid = get_field('question_sessions', 'newgraded', 'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
if ($gradedstateid = get_field('question_sessions', 'newgraded',
$grade = round(get_field('question_states', 'grade', 'id', $gradedstateid), $game->decimalpoints);
'attemptid', $attempt->attemptuniqueid, 'questionid', $questionid)) {
$grade = round(get_field('question_states', 'grade', 'id',
$gradedstateid), $game->decimalpoints);
} else {
} else {
$grade = '--';
$grade = '--';
}
}
if (!$download) {
if (!$download) {
$row[] = link_to_popup_window ('/mod/game/reviewquestion.php?state='.$gradedstateid.'& number='.$questions[$questionid]->number, 'reviewquestion', $grade, 450, 650, $strreviewquestion, 'none', true);
$row[] = link_to_popup_window (
'/mod/game/reviewquestion.php?state='.
$gradedstateid.'& number='.
$questions[$questionid]->number, 'reviewquestion', $grade,
450, 650, $strreviewquestion, 'none', true);
} else {
} else {
$row[] = $grade;
$row[] = $grade;
}
}
}
}
}
}
@ -493,43 +533,50 @@ class game_report extends game_default_report {
$table->add_data($row);
$table->add_data($row);
} else if ($download == 'Excel' or $download == 'ODS') {
} else if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
$colnum = 0;
foreach($row as $item){
foreach ($row as $item) {
$myxls->write($rownum,$colnum,$item,$format);
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
$colnum++;
}
}
$rownum++;
$rownum++;
} else if ($download=='CSV') {
} else if ($download == 'CSV') {
$text = implode("\t", $row);
$text = implode("\t", $row);
echo $text." \n";
echo $text." \n";
}
}
}
}
}
}
if (!$download) {
if (!$download) {
// Start form
// Start form.
echo '< div id = "tablecontainer" > ';
echo '< div id = "tablecontainer" > ';
echo '< form id = "attemptsform" method = "post" action = "report.php" onsubmit = "var menu = document.getElementById(\'menuaction\'); return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);" > ';
echo '< form id = "attemptsform" method = "post" action = "report.php" ' .
'onsubmit="var menu = document.getElementById(\'menuaction\'); '.
'return (menu.options[menu.selectedIndex].value == \'delete\' ? confirm(\''.$strreallydel.'\') : true);">';
echo '< div > ';
echo '< div > ';
echo '< input type = "hidden" name = "id" value = "'.$cm->id.'" / > ';
echo '< input type = "hidden" name = "id" value = "'.$cm->id.'" / > ';
echo '< input type = "hidden" name = "mode" value = "overview" / > ';
echo '< input type = "hidden" name = "mode" value = "overview" / > ';
// Print table
// Print table.
$table->print_html();
$table->print_html();
// Print "Select all" etc.
// Print "Select all" etc..
if (!empty($attempts)) {
if (!empty($attempts)) {
echo '< table id = "commands" > ';
echo '< table id = "commands" > ';
echo '< tr > < td > ';
echo '< tr > < td > ';
echo '< a href = "javascript:select_all_in(\'DIV\',null,\'tablecontainer\');" > '.get_string('selectall', 'game').'< / a > / ';
echo '< a href = "javascript:select_all_in(\'DIV\',null,\'tablecontainer\');" > '.
echo '< a href = "javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');" > '.get_string('selectnone', 'game').'< / a > ';
get_string('selectall', 'game').'< / a > / ';
echo '< a href = "javascript:deselect_all_in(\'DIV\',null,\'tablecontainer\');" > '.
get_string('selectnone', 'game').'< / a > ';
echo ' ';
echo ' ';
$options = array('delete' => get_string('delete'));
$options = array('delete' => get_string('delete'));
echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'), 'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
echo choose_from_menu($options, 'action', '', get_string('withselected', 'game'),
'if(this.selectedIndex > 0) submitFormById(\'attemptsform\');', '', true);
echo '< noscript id = "noscriptmenuaction" style = "display: inline;" > < div > ';
echo '< noscript id = "noscriptmenuaction" style = "display: inline;" > < div > ';
echo '< input type = "submit" value = "'.get_string('go').'" / > < / div > < / noscript > ';
echo '< input type = "submit" value = "'.get_string('go').'" / > < / div > < / noscript > ';
echo '< script type = "text/javascript" > '."\n<!--\n".' document . getElementById ( "noscriptmenuaction" ) . style . display = "none" ; '."\n-->\n".' < / script > ';
echo '< script type = "text/javascript" > ' . " \ n < ! - - \ n " .
'document.getElementById("noscriptmenuaction").style.display = "none";'
."\n-->\n".'< / script > ';
echo '< / td > < / tr > < / table > ';
echo '< / td > < / tr > < / table > ';
}
}
// Close form
// Close form.
echo '< / div > ';
echo '< / div > ';
echo '< / form > < / div > ';
echo '< / form > < / div > ';
@ -545,7 +592,7 @@ class game_report extends game_default_report {
$options['detailedmarks'] = $detailedmarks;
$options['detailedmarks'] = $detailedmarks;
echo '< td > ';
echo '< td > ';
$options["download"] = "ODS";
$options["download"] = "ODS";
print_single_button("report.php", $options, get_string("downloadods", 'game')); ///check bdaloukas
print_single_button("report.php", $options, get_string("downloadods", 'game'));
echo "< / td > \n";
echo "< / td > \n";
echo '< td > ';
echo '< td > ';
$options["download"] = "Excel";
$options["download"] = "Excel";
@ -572,7 +619,7 @@ class game_report extends game_default_report {
$table->print_html();
$table->print_html();
}
}
}
}
// Print display options
// Print display options.
echo '< div class = "controls" > ';
echo '< div class = "controls" > ';
echo '< form id = "options" action = "report.php" method = "get" > ';
echo '< form id = "options" action = "report.php" method = "get" > ';
echo '< div > ';
echo '< div > ';
@ -589,16 +636,19 @@ class game_report extends game_default_report {
echo '< / tr > ';
echo '< / tr > ';
echo '< tr align = "left" > ';
echo '< tr align = "left" > ';
echo '< td colspan = "2" > ';
echo '< td colspan = "2" > ';
$options = array(0 => get_string('attemptsonly','game', $course->students));
$options = array(0 => get_string('attemptsonly', 'game', $course->students));
if ($course->id != SITEID) {
if ($course->id != SITEID) {
$options[1] = get_string('noattemptsonly', 'game', $course->students);
$options[1] = get_string('noattemptsonly', 'game', $course->students);
$options[2] = get_string('allstudents','game', $course->students);
$options[2] = get_string('allstudents', 'game', $course->students);
$options[3] = get_string('allattempts','game');
$options[3] = get_string('allattempts', 'game');
}
}
choose_from_menu($options,'noattempts',$noattempts,'');
choose_from_menu($options, 'noattempts', $noattempts, '');
echo '< / td > < / tr > ';
echo '< / td > < / tr > ';
echo '< tr align = "left" > ';
echo '< tr align = "left" > ';
echo '< td colspan = "2" > < input type = "checkbox" id = "checkdetailedmarks" name = "detailedmarks" ' . ( $ detailedmarks ? ' checked = "checked" ' : ' ' ) . ' value = "1" / > < label for = "checkdetailedmarks" > '.get_string('showdetailedmarks', 'game').'< / label > ';
echo '< td colspan = "2" > < input type = "checkbox" id = "checkdetailedmarks" name = "detailedmarks" ' .
($detailedmarks ? 'checked="checked" ' : '').
'value="1" /> < label for = "checkdetailedmarks" > '.
get_string('showdetailedmarks', 'game').'< / label > ';
echo '< / td > < / tr > ';
echo '< / td > < / tr > ';
echo '< tr > < td colspan = "2" align = "center" > ';
echo '< tr > < td colspan = "2" align = "center" > ';
echo '< input type = "submit" value = "'.get_string('go').'" / > ';
echo '< input type = "submit" value = "'.get_string('go').'" / > ';
@ -611,5 +661,3 @@ class game_report extends game_default_report {
return true;
return true;
}
}
}
}
?>