. // This page prints a review of a particular game attempt. require_once("../../config.php"); require_once("locallib.php"); require_once("../../lib/questionlib.php"); $attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review. $page = optional_param('page', 0, PARAM_INT); // The required page. $showall = optional_param('showall', 0, PARAM_BOOL); if (! $attempt = $DB->get_record('game_attempts', array( 'id' => $attempt))) { print_error("No such attempt ID exists"); } if (! $game = $DB->get_record('game', array( 'id' => $attempt->gameid))) { print_error("The game with id $attempt->gameid belonging to attempt $attempt is missing"); } game_compute_attempt_layout( $game, $attempt); if (! $course = $DB->get_record('course', array( 'id' => $game->course))) { print_error("The course with id $game->course that the game with id $game->id belongs to is missing"); } if (! $cm = get_coursemodule_from_instance("game", $game->id, $course->id)) { print_error("The course module for the game with id $game->id is missing"); } $grade = game_score_to_grade( $attempt->score, $game); $feedback = game_feedback_for_grade( $grade, $attempt->gameid); require_login( $course->id, false, $cm); $context = get_context_instance( CONTEXT_MODULE, $cm->id); $coursecontext = get_context_instance( CONTEXT_COURSE, $cm->course); $isteacher = isteacher( $game->course, $USER->id); $options = game_get_reviewoptions( $game, $attempt, $context); $popup = $isteacher ? 0 : $game->popup; // Controls whether this is shown in a javascript-protected window. add_to_log($course->id, "game", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$game->id", "$cm->id"); // Print the page header. $strgames = get_string('modulenameplural', 'game'); $strreview = get_string('review', 'game'); $strscore = get_string('score', "game"); $strgrade = get_string('grade'); $strbestgrade = get_string('bestgrade', 'quiz'); $strtimetaken = get_string('timetaken', 'game'); $strtimecompleted = get_string('completedon', 'game'); $strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext) ? update_module_button($cm->id, $course->id, get_string('modulename', 'game')) : ''; $strgames = get_string("modulenameplural", "game"); $strgame = get_string("modulename", "game"); if (function_exists( 'build_navigation')) { $navigation = build_navigation('', $cm); echo $OUTPUT->heading("$course->shortname: $game->name", "$course->shortname: $game->name", $navigation, "", "", true, update_module_button($cm->id, $course->id, $strgame), navmenu($course, $cm)); } else { if ($course->category) { $navigation = "wwwroot}/course/view.php?id=$course->id\">$course->shortname ->"; } else { $navigation = ''; } echo $OUTPUT->heading("$course->shortname: $game->name", "$course->fullname", "$navigation id>$strgames -> $game->name", "", "", true, update_module_button($cm->id, $course->id, $strgame), navmenu($course, $cm)); } echo '
'; // For overlib. // Print heading and tabs if this is part of a preview. if ($attempt->userid == $USER->id) { // This is the report on a preview. $currenttab = 'preview'; } else { $currenttab = 'reports'; $mode = ''; } require('tabs.php'); // Load all the questions and states needed by this script. // Load the questions needed by page. $pagelist = $showall ? game_questions_in_game( $attempt->layout) : game_questions_on_page( $attempt->layout, $page); $a = explode( ',', $pagelist); $pagelist = ''; foreach ($a as $item) { if (substr( $item, 0, 1)) { if (substr( $item, -1) != 'G') { $pagelist .= ','.$item; } } } $pagelist = substr( $pagelist, 1); if ($pagelist != '') { $sql = "SELECT q.*, i.id AS instance,i.id as iid,". "i.score AS score,i.studentanswer". " FROM {question} q,". " {game_queries} i". " WHERE i.attemptid = '$attempt->id' AND q.id = i.questionid AND (i.sourcemodule='question' or i.sourcemodule = 'quiz')". " AND q.id IN ($pagelist)"; if (!$questions = $DB->get_records_sql( $sql)) { print_error('No questions found'); } } else { $questions = array(); } // Load the question type specific information. if (!get_question_options( $questions)) { print_error('Could not load question options'); } $states = game_compute_states( $game, $questions); // Print infobox. $timelimit = 0; $overtime = 0; if ($attempt->timefinish) { if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { if ($timelimit && $timetaken > ($timelimit + 60)) { $overtime = $timetaken - $timelimit; $overtime = format_time($overtime); } $timetaken = format_time($timetaken); } else { $timetaken = "-"; } } else { $timetaken = get_string('unfinished', 'game'); } $table->align = array("right", "left"); if ($attempt->userid <> $USER->id) { $student = $DB->get_record('user', array( 'id' => $attempt->userid)); $picture = print_user_picture($student->id, $course->id, $student->picture, false, true); $table->data[] = array($picture, ''.fullname($student, true).''); } if (count($attempts = $DB->get_records('game_attempts', array( 'gameid' => $game->id, 'userid' => $attempt->userid), 'attempt ASC')) > 1) { // Print list of attempts. $attemptlist = ''; foreach ($attempts as $at) { $attemptlist .= ($at->id == $attempt->id) ? ''.$at->attempt.', ' : ''.$at->attempt.', '; } $table->data[] = array(get_string('attempts', 'game').':', trim($attemptlist, ' ,')); } $table->data[] = array(get_string('startedon', 'game').':', userdate($attempt->timestart)); if ($attempt->timefinish) { $table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish)); $table->data[] = array("$strtimetaken:", $timetaken); } // If the student is allowed to see their score. if ($options->scores) { if ($game->grade) { if ($overtime) { $result->sumgrades = "0"; $result->grade = "0.0"; } $a = new stdClass; $percentage = round($attempt->score * 100, 0); $a->grade = game_score_to_grade( $attempt->score, $game); $a->maxgrade = $game->grade; $table->data[] = array("$strscore:", "{$a->grade}/{$game->grade} ($percentage %)"); } } if ($options->overallfeedback && $feedback) { $table->data[] = array(get_string('feedback', 'game'), $feedback); } if ($isteacher and $attempt->userid == $USER->id) { // The teacher is at the end of a preview. Print button to start new preview. unset($buttonoptions); $buttonoptions['q'] = $game->id; $buttonoptions['forcenew'] = true; echo '