Vasilis Daloukas
9 years ago
14 changed files with 1824 additions and 1707 deletions
@ -1,82 +1,92 @@ |
|||||
<?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/>. |
||||
|
|
||||
require_once(dirname(__FILE__) . '/../../config.php'); |
require_once(dirname(__FILE__) . '/../../config.php'); |
||||
require_once($CFG->libdir.'/gradelib.php'); |
require_once($CFG->libdir.'/gradelib.php'); |
||||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
||||
require_once($CFG->libdir . '/completionlib.php'); |
require_once($CFG->libdir . '/completionlib.php'); |
||||
|
|
||||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or |
$id = optional_param('id', 0, PARAM_INT); // Course Module ID. |
||||
$q = optional_param('q', 0, PARAM_INT); // game ID |
$q = optional_param('q', 0, PARAM_INT); // Game ID. |
||||
|
|
||||
if ($id) { |
if ($id) { |
||||
if (! $cm = get_coursemodule_from_id('game', $id)) { |
if (!$cm = get_coursemodule_from_id('game', $id)) { |
||||
print_error('invalidcoursemodule'); |
print_error('invalidcoursemodule'); |
||||
} |
|
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) { |
|
||||
print_error('coursemisconf'); |
|
||||
} |
|
||||
if (! $game = $DB->get_record('game', array('id' => $cm->instance))) { |
|
||||
print_error('invalidcoursemodule'); |
|
||||
} |
|
||||
} else { |
|
||||
if (! $game = $DB->get_record('game', array('id' => $q))) { |
|
||||
print_error('invalidgameid q='.$q, 'game'); |
|
||||
} |
|
||||
if (! $course = $DB->get_record('course', array('id' => $game->course))) { |
|
||||
print_error('invalidcourseid'); |
|
||||
} |
|
||||
if (! $cm = get_coursemodule_from_instance('game', $game->id, $course->id)) { |
|
||||
print_error('invalidcoursemodule'); |
|
||||
} |
|
||||
} |
} |
||||
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) { |
||||
|
print_error('coursemisconf'); |
||||
|
} |
||||
|
if (! $game = $DB->get_record('game', array('id' => $cm->instance))) { |
||||
|
print_error('invalidcoursemodule'); |
||||
|
} |
||||
|
} else { |
||||
|
if (! $game = $DB->get_record('game', array('id' => $q))) { |
||||
|
print_error('invalidgameid q='.$q, 'game'); |
||||
|
} |
||||
|
if (!$course = $DB->get_record('course', array('id' => $game->course))) { |
||||
|
print_error('invalidcourseid'); |
||||
|
} |
||||
|
if (!$cm = get_coursemodule_from_instance('game', $game->id, $course->id)) { |
||||
|
print_error('invalidcoursemodule'); |
||||
|
} |
||||
|
} |
||||
|
|
||||
/// Check login and get context. |
// Check login and get context. |
||||
require_login($course->id, false, $cm); |
require_login($course->id, false, $cm); |
||||
$context = game_get_context_module_instance( $cm->id); |
$context = game_get_context_module_instance( $cm->id); |
||||
require_capability('mod/game:view', $context); |
require_capability('mod/game:view', $context); |
||||
|
|
||||
/// Cache some other capabilites we use several times. |
|
||||
$canattempt = has_capability('mod/game:attempt', $context); |
|
||||
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context); |
|
||||
|
|
||||
/// Create an object to manage all the other (non-roles) access rules. |
// Cache some other capabilites we use several times. |
||||
$timenow = time(); |
$canattempt = has_capability('mod/game:attempt', $context); |
||||
//$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow); |
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context); |
||||
|
|
||||
/// If no questions have been set up yet redirect to edit.php |
// Create an object to manage all the other (non-roles) access rules. |
||||
//if (!$game->questions && has_capability('mod/game:manage', $context)) { |
$timenow = time(); |
||||
// redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id); |
|
||||
//} |
|
||||
|
|
||||
/// Log this request. |
// Log this request. |
||||
if( game_use_events()) |
if (game_use_events()) { |
||||
{ |
require( 'classes/event/course_module_viewed.php'); |
||||
require( 'classes/event/course_module_viewed.php'); |
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger(); |
||||
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger(); |
} else { |
||||
}else |
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); |
||||
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); |
} |
||||
|
|
||||
/// Initialize $PAGE, compute blocks |
// Initialize $PAGE, compute blocks. |
||||
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); |
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); |
||||
|
|
||||
$edit = optional_param('edit', -1, PARAM_BOOL); |
$edit = optional_param('edit', -1, PARAM_BOOL); |
||||
if ($edit != -1 && $PAGE->user_allowed_editing()) { |
if ($edit != -1 && $PAGE->user_allowed_editing()) { |
||||
$USER->editing = $edit; |
$USER->editing = $edit; |
||||
} |
} |
||||
|
|
||||
// Note: MDL-19010 there will be further changes to printing header and blocks. |
// Note: MDL-19010 there will be further changes to printing header and blocks. |
||||
// The code will be much nicer than this eventually. |
// The code will be much nicer than this eventually. |
||||
$title = $course->shortname . ': ' . format_string($game->name); |
$title = $course->shortname . ': ' . format_string($game->name); |
||||
|
|
||||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
||||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
||||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
||||
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'. |
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing() ? 'off' : 'on').'" />'. |
||||
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>'; |
'<input type="submit" value="'. |
||||
$PAGE->set_button($buttons); |
get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton'). |
||||
} |
'" /></div></form></td></tr></table>'; |
||||
|
$PAGE->set_button($buttons); |
||||
|
} |
||||
|
|
||||
$PAGE->set_title($title); |
$PAGE->set_title($title); |
||||
$PAGE->set_heading($course->fullname); |
$PAGE->set_heading($course->fullname); |
||||
|
|
||||
echo $OUTPUT->header(); |
echo $OUTPUT->header(); |
||||
|
@ -1,79 +1,76 @@ |
|||||
<?php // $Id: report.php,v 1.5 2012/07/25 11:16:04 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
// This script uses installed report plugins to print game reports |
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
require_once("../../config.php"); |
// it under the terms of the GNU General Public License as published by |
||||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
// the Free Software Foundation, either version 3 of the License, or |
||||
require_once($CFG->dirroot.'/mod/game/report/reportlib.php'); |
// (at your option) any later version. |
||||
|
// |
||||
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or |
// Moodle is distributed in the hope that it will be useful, |
||||
$q = optional_param('q',0,PARAM_INT); // game ID |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode |
// GNU General Public License for more details. |
||||
|
// |
||||
if ($id) { |
// You should have received a copy of the GNU General Public License |
||||
if (! $cm = get_coursemodule_from_id('game', $id)) { |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
print_error( "There is no coursemodule with id $id"); |
|
||||
} |
// This script uses installed report plugins to print game reports. |
||||
|
|
||||
if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { |
require_once("../../config.php"); |
||||
print_error( 'Course is misconfigured'); |
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
||||
} |
require_once($CFG->dirroot.'/mod/game/report/reportlib.php'); |
||||
|
|
||||
if (! $game = $DB->get_record( 'game', array( 'id' => $cm->instance))) { |
$id = optional_param('id', 0, PARAM_INT); // Course Module ID. |
||||
print_error( "The game with id $cm->instance corresponding to this coursemodule $id is missing"); |
$q = optional_param('q', 0, PARAM_INT); // Game ID. |
||||
} |
|
||||
|
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode. |
||||
} else { |
|
||||
if (! $game = $DB->get_record( 'game', array( 'id' => $q))) { |
if ($id) { |
||||
print_error( "There is no game with id $q"); |
if (! $cm = get_coursemodule_from_id('game', $id)) { |
||||
} |
print_error( "There is no coursemodule with id $id"); |
||||
if (! $course = $DB->get_record( 'course', array( 'id' => $game->course))) { |
|
||||
print_error( "The course with id $game->course that the game with id $a 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 $q is missing"); |
|
||||
} |
|
||||
} |
} |
||||
|
|
||||
require_login($course->id, false); |
if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { |
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id); |
print_error( 'Course is misconfigured'); |
||||
require_capability('mod/game:viewreports', $context); |
} |
||||
|
|
||||
// if no questions have been set up yet redirect to edit.php |
|
||||
//if (!$game->questions and has_capability('mod/game:manage', $context)) { |
|
||||
// redirect('edit.php?gameid='.$game->id); |
|
||||
//} |
|
||||
|
|
||||
// Upgrade any attempts that have not yet been upgraded to the |
if (! $game = $DB->get_record( 'game', array( 'id' => $cm->instance))) { |
||||
// Moodle 1.5 model (they will not yet have the timestamp set) |
print_error( "The game with id $cm->instance corresponding to this coursemodule $id is missing"); |
||||
//if ($attempts = get_records_sql("SELECT a.*". |
} |
||||
// " FROM {$CFG->prefix}game_attempts a, {$CFG->prefix}question_states s". |
} else { |
||||
// " WHERE a.game = '$game->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) { |
if (! $game = $DB->get_record( 'game', array( 'id' => $q))) { |
||||
// foreach ($attempts as $attempt) { |
print_error( "There is no game with id $q"); |
||||
// game_upgrade_states($attempt); |
} |
||||
// } |
if (! $course = $DB->get_record( 'course', array( 'id' => $game->course))) { |
||||
//} |
print_error( "The course with id $game->course that the game with id $a 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 $q is missing"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
add_to_log($course->id, "game", "report", "report.php?id=$cm->id", "$game->id", "$cm->id"); |
require_login($course->id, false); |
||||
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id); |
||||
|
require_capability('mod/game:viewreports', $context); |
||||
|
|
||||
/// Open the selected game report and display it |
add_to_log($course->id, "game", "report", "report.php?id=$cm->id", "$game->id", "$cm->id"); |
||||
|
|
||||
$mode = clean_param( $mode, PARAM_SAFEDIR); |
// Open the selected game report and display it. |
||||
|
|
||||
if (! is_readable("report/$mode/report.php")) { |
$mode = clean_param( $mode, PARAM_SAFEDIR); |
||||
print_error("Report not known ($mode)"); |
|
||||
} |
|
||||
|
|
||||
include("report/default.php"); // Parent class |
if (! is_readable("report/$mode/report.php")) { |
||||
include("report/$mode/report.php"); |
print_error("Report not known ($mode)"); |
||||
|
} |
||||
|
|
||||
$report = new game_overview_report(); |
require("report/default.php"); // Parent class. |
||||
|
require("report/$mode/report.php"); |
||||
|
|
||||
if (! $report->display( $game, $cm, $course)) { // Run the report! |
$report = new game_overview_report(); |
||||
print_error( 'Error occurred during pre-processing!'); |
|
||||
} |
|
||||
|
|
||||
/// Print footer |
if (! $report->display( $game, $cm, $course)) { // Run the report! |
||||
|
print_error( 'Error occurred during pre-processing!'); |
||||
|
} |
||||
|
|
||||
echo $OUTPUT->footer($course); |
// Print footer. |
||||
|
echo $OUTPUT->footer($course); |
||||
|
@ -1,327 +1,327 @@ |
|||||
<?php // $Id: review.php,v 1.12 2012/07/25 23:07:43 bdaloukas Exp $
|
<?php |
||||
/** |
// This file is part of Moodle - http://moodle.org/ |
||||
* This page prints a review of a particular game attempt |
// |
||||
* |
// Moodle is free software: you can redistribute it and/or modify |
||||
* @version $Id: review.php,v 1.12 2012/07/25 23:07:43 bdaloukas Exp $ |
// it under the terms of the GNU General Public License as published by |
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
// the Free Software Foundation, either version 3 of the License, or |
||||
* @package game |
// (at your option) any later version. |
||||
*/ |
// |
||||
|
// Moodle is distributed in the hope that it will be useful, |
||||
require_once("../../config.php"); |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
require_once("locallib.php"); |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
require_once("../../lib/questionlib.php"); |
// GNU General Public License for more details. |
||||
|
// |
||||
$attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review |
// You should have received a copy of the GNU General Public License |
||||
$page = optional_param('page', 0, PARAM_INT); // The required page |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
$showall = optional_param('showall', 0, PARAM_BOOL); |
|
||||
|
// This page prints a review of a particular game attempt. |
||||
if (! $attempt = $DB->get_record('game_attempts', array( 'id' => $attempt))) { |
|
||||
print_error("No such attempt ID exists"); |
require_once("../../config.php"); |
||||
} |
require_once("locallib.php"); |
||||
if (! $game = $DB->get_record('game', array( 'id' => $attempt->gameid))) { |
require_once("../../lib/questionlib.php"); |
||||
print_error("The game with id $attempt->gameid belonging to attempt $attempt is missing"); |
|
||||
} |
$attempt = required_param('attempt', PARAM_INT); // A particular attempt ID for review. |
||||
|
$page = optional_param('page', 0, PARAM_INT); // The required page. |
||||
game_compute_attempt_layout( $game, $attempt); |
$showall = optional_param('showall', 0, PARAM_BOOL); |
||||
|
|
||||
if (! $course = $DB->get_record('course', array( 'id' => $game->course))) { |
if (! $attempt = $DB->get_record('game_attempts', array( 'id' => $attempt))) { |
||||
print_error("The course with id $game->course that the game with id $game->id belongs to is missing"); |
print_error("No such attempt ID exists"); |
||||
} |
} |
||||
if (! $cm = get_coursemodule_from_instance("game", $game->id, $course->id)) { |
if (! $game = $DB->get_record('game', array( 'id' => $attempt->gameid))) { |
||||
print_error("The course module for the game with id $game->id is missing"); |
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 = "<a href=\"{$CFG->wwwroot}/course/view.php?id=$course->id\">$course->shortname</a> ->"; |
||||
|
} else { |
||||
|
$navigation = ''; |
||||
} |
} |
||||
|
|
||||
$grade = game_score_to_grade( $attempt->score, $game); |
echo $OUTPUT->heading("$course->shortname: $game->name", "$course->fullname", |
||||
$feedback = game_feedback_for_grade( $grade, $attempt->gameid); |
"$navigation <a href=index.php?id=$course->id>$strgames</a> -> $game->name", |
||||
|
"", "", true, update_module_button($cm->id, $course->id, $strgame), |
||||
require_login( $course->id, false, $cm); |
navmenu($course, $cm)); |
||||
$context = get_context_instance( CONTEXT_MODULE, $cm->id); |
} |
||||
$coursecontext = get_context_instance( CONTEXT_COURSE, $cm->course); |
|
||||
$isteacher = isteacher( $game->course, $USER->id); |
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // For overlib. |
||||
$options = game_get_reviewoptions( $game, $attempt, $context); |
|
||||
$popup = $isteacher ? 0 : $game->popup; // Controls whether this is shown in a javascript-protected window. |
// Print heading and tabs if this is part of a preview. |
||||
|
if ($attempt->userid == $USER->id) { |
||||
add_to_log($course->id, "game", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$game->id", "$cm->id"); |
// This is the report on a preview. |
||||
|
$currenttab = 'preview'; |
||||
/// Print the page header |
} else { |
||||
|
$currenttab = 'reports'; |
||||
$strgames = get_string('modulenameplural', 'game'); |
$mode = ''; |
||||
$strreview = get_string('review', 'game'); |
} |
||||
$strscore = get_string('score', "game"); |
|
||||
$strgrade = get_string('grade'); |
require('tabs.php'); |
||||
$strbestgrade = get_string('bestgrade', 'quiz'); |
|
||||
$strtimetaken = get_string('timetaken', 'game'); |
// Load all the questions and states needed by this script. |
||||
$strtimecompleted = get_string('completedon', 'game'); |
// Load the questions needed by page. |
||||
|
$pagelist = $showall ? game_questions_in_game( $attempt->layout) : game_questions_on_page( $attempt->layout, $page); |
||||
|
$a = explode( ',', $pagelist); |
||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext) |
$pagelist = ''; |
||||
? update_module_button($cm->id, $course->id, get_string('modulename', 'game')) |
foreach ($a as $item) { |
||||
: ""; |
if (substr( $item, 0, 1)) { |
||||
|
if (substr( $item, -1) != 'G') { |
||||
$strgames = get_string("modulenameplural", "game"); |
$pagelist .= ','.$item; |
||||
$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 = "<a href=\"{$CFG->wwwroot}/course/view.php?id=$course->id\">$course->shortname</a> ->"; |
|
||||
} else { |
|
||||
$navigation = ''; |
|
||||
} |
|
||||
echo $OUTPUT->heading("$course->shortname: $game->name", "$course->fullname", |
|
||||
"$navigation <a href=index.php?id=$course->id>$strgames</a> -> $game->name", |
|
||||
"", "", true, update_module_button($cm->id, $course->id, $strgame), |
|
||||
navmenu($course, $cm)); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib |
|
||||
/// Print heading and tabs if this is part of a preview |
|
||||
//if (has_capability('mod/game:preview', $context)) { |
|
||||
if ($attempt->userid == $USER->id) { // this is the report on a preview |
|
||||
$currenttab = 'preview'; |
|
||||
} else { |
|
||||
$currenttab = 'reports'; |
|
||||
$mode = ''; |
|
||||
} |
} |
||||
include('tabs.php'); |
|
||||
//} else { |
|
||||
// print_heading(format_string($game->name)); |
|
||||
//} |
|
||||
|
|
||||
/// 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'); |
|
||||
} |
} |
||||
|
} |
||||
|
|
||||
|
$pagelist = substr( $pagelist, 1); |
||||
|
|
||||
$states = game_compute_states( $game, $questions); |
if ($pagelist != '') { |
||||
/// Print infobox |
$sql = "SELECT q.*, i.id AS instance,i.id as iid,". |
||||
|
"i.score AS score,i.studentanswer". |
||||
//$timelimit = (int)$game->timelimit * 60; |
" FROM {question} q,". |
||||
$timelimit = 0; |
" {game_queries} i". |
||||
$overtime = 0; |
" WHERE i.attemptid = '$attempt->id' AND q.id = i.questionid AND (i.sourcemodule='question' or i.sourcemodule = 'quiz')". |
||||
|
" AND q.id IN ($pagelist)"; |
||||
if ($attempt->timefinish) { |
|
||||
if ($timetaken = ($attempt->timefinish - $attempt->timestart)) { |
if (!$questions = $DB->get_records_sql( $sql)) { |
||||
if($timelimit && $timetaken > ($timelimit + 60)) { |
print_error('No questions found'); |
||||
$overtime = $timetaken - $timelimit; |
} |
||||
$overtime = format_time($overtime); |
} else { |
||||
} |
$questions = array(); |
||||
$timetaken = format_time($timetaken); |
} |
||||
} else { |
|
||||
$timetaken = "-"; |
// 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 { |
} else { |
||||
$timetaken = get_string('unfinished', 'game'); |
$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, |
||||
|
'<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='. |
||||
|
$course->id.'">'.fullname($student, true).'</a>'); |
||||
|
} |
||||
|
|
||||
$table->align = array("right", "left"); |
if (count($attempts = $DB->get_records('game_attempts', array( 'gameid' => $game->id, |
||||
if ($attempt->userid <> $USER->id) { |
'userid' => $attempt->userid), 'attempt ASC')) > 1) { |
||||
$student = $DB->get_record('user', array( 'id' => $attempt->userid)); |
// Print list of attempts. |
||||
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true); |
$attemptlist = ''; |
||||
$table->data[] = array($picture, '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='.$course->id.'">'.fullname($student, true).'</a>'); |
foreach ($attempts as $at) { |
||||
|
$attemptlist .= ($at->id == $attempt->id) ? '<strong>'.$at->attempt.'</strong>, ' : '<a href="review.php?attempt='. |
||||
|
$at->id.($showall ? '&showall=true' : '').'">'.$at->attempt.'</a>, '; |
||||
} |
} |
||||
//if (has_capability('mod/game:grade', $context)){ |
$table->data[] = array(get_string('attempts', 'game').':', trim($attemptlist, ' ,')); |
||||
if( count($attempts = $DB->get_records('game_attempts', array( 'gameid' => $game->id, 'userid' => $attempt->userid), 'attempt ASC')) > 1) { |
} |
||||
// print list of attempts |
|
||||
$attemptlist = ''; |
$table->data[] = array(get_string('startedon', 'game').':', userdate($attempt->timestart)); |
||||
foreach ($attempts as $at) { |
if ($attempt->timefinish) { |
||||
$attemptlist .= ($at->id == $attempt->id) |
$table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish)); |
||||
? '<strong>'.$at->attempt.'</strong>, ' |
$table->data[] = array("$strtimetaken:", $timetaken); |
||||
: '<a href="review.php?attempt='.$at->id.($showall?'&showall=true':'').'">'.$at->attempt.'</a>, '; |
} |
||||
} |
|
||||
$table->data[] = array(get_string('attempts', 'game').':', trim($attemptlist, ' ,')); |
// If the student is allowed to see their score. |
||||
|
if ($options->scores) { |
||||
|
if ($game->grade) { |
||||
|
if ($overtime) { |
||||
|
$result->sumgrades = "0"; |
||||
|
$result->grade = "0.0"; |
||||
} |
} |
||||
//} |
|
||||
|
|
||||
$table->data[] = array(get_string('startedon', 'game').':', userdate($attempt->timestart)); |
$a = new stdClass; |
||||
if ($attempt->timefinish) { |
$percentage = round($attempt->score * 100, 0); |
||||
$table->data[] = array("$strtimecompleted:", userdate($attempt->timefinish)); |
$a->grade = game_score_to_grade( $attempt->score, $game); |
||||
$table->data[] = array("$strtimetaken:", $timetaken); |
$a->maxgrade = $game->grade; |
||||
|
$table->data[] = array("$strscore:", "{$a->grade}/{$game->grade} ($percentage %)"); |
||||
} |
} |
||||
//if the student is allowed to see their score |
} |
||||
if ($options->scores) { |
|
||||
if ($game->grade) { |
if ($options->overallfeedback && $feedback) { |
||||
if($overtime) { |
$table->data[] = array(get_string('feedback', 'game'), $feedback); |
||||
$result->sumgrades = "0"; |
} |
||||
$result->grade = "0.0"; |
|
||||
} |
if ($isteacher and $attempt->userid == $USER->id) { |
||||
|
// The teacher is at the end of a preview. Print button to start new preview. |
||||
$a = new stdClass; |
unset($buttonoptions); |
||||
$percentage = round($attempt->score*100, 0); |
$buttonoptions['q'] = $game->id; |
||||
$a->grade = game_score_to_grade( $attempt->score, $game); |
$buttonoptions['forcenew'] = true; |
||||
$a->maxgrade = $game->grade; |
echo '<div class="controls">'; |
||||
$table->data[] = array("$strscore:", "{$a->grade}/{$game->grade} ($percentage %)"); |
print_single_button($CFG->wwwroot.'/mod/game/attempt.php', $buttonoptions, get_string('startagain', 'game')); |
||||
//$table->data[] = array("$strgrade:", get_string('outof', 'game', $a)); |
echo '</div>'; |
||||
|
} else { |
||||
|
// Print number of the attempt. |
||||
|
print_heading(get_string('reviewofattempt', 'game', $attempt->attempt)); |
||||
|
} |
||||
|
print_table($table); |
||||
|
|
||||
|
// Print javascript button to close the window, if necessary. |
||||
|
if (!$isteacher) { |
||||
|
include('attempt_close_js.php'); |
||||
|
} |
||||
|
|
||||
|
// Print the navigation panel if required. |
||||
|
$numpages = game_number_of_pages( $attempt->layout); |
||||
|
if ($numpages > 1 and !$showall) { |
||||
|
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); |
||||
|
echo '<div class="controls"><a href="review.php?attempt='.$attempt->id.'&showall=true">'; |
||||
|
print_string('showall', 'game'); |
||||
|
echo '</a></div>'; |
||||
|
} |
||||
|
|
||||
|
// Print all the questions. |
||||
|
if ($pagelist) { |
||||
|
game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game); |
||||
|
} |
||||
|
|
||||
|
// Print the navigation panel if required. |
||||
|
if ($numpages > 1 and !$showall) { |
||||
|
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); |
||||
|
} |
||||
|
|
||||
|
// Print javascript button to close the window, if necessary. |
||||
|
if (!$isteacher) { |
||||
|
require('attempt_close_js.php'); |
||||
|
} |
||||
|
|
||||
|
if (empty($popup)) { |
||||
|
echo $OUTPUT->footer($course); |
||||
|
} |
||||
|
|
||||
|
function game_compute_states( $game, $questions) { |
||||
|
global $QTYPES; |
||||
|
|
||||
|
// Restore the question sessions to their most recent states creating new sessions where required. |
||||
|
$states = array(); |
||||
|
foreach ($questions as $question) { |
||||
|
$state = new StdClass; |
||||
|
|
||||
|
$cmoptions->course = $game->course; |
||||
|
$cmoptions->optionflags->optionflags = 0; |
||||
|
$cmoptions->id = 0; |
||||
|
$cmoptions->shuffleanswers = 1; |
||||
|
|
||||
|
$state->last_graded = new StdClass; |
||||
|
$state->last_graded->event = QUESTION_EVENTOPEN; |
||||
|
|
||||
|
$state->raw_grade = 0; |
||||
|
|
||||
|
$attempt = 0; |
||||
|
if (!$QTYPES[$question->qtype]->create_session_and_responses( $question, $state, $cmoptions, $attempt)) { |
||||
|
print_error( 'game_compute_states: problem'); |
||||
} |
} |
||||
} |
|
||||
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 '<div class="controls">'; |
|
||||
print_single_button($CFG->wwwroot.'/mod/game/attempt.php', $buttonoptions, get_string('startagain', 'game')); |
|
||||
echo '</div>'; |
|
||||
} else { // print number of the attempt |
|
||||
print_heading(get_string('reviewofattempt', 'game', $attempt->attempt)); |
|
||||
} |
|
||||
print_table($table); |
|
||||
|
|
||||
// print javascript button to close the window, if necessary |
$state->event = QUESTION_EVENTOPEN; |
||||
if (!$isteacher) { |
$state->manualcomment = ''; |
||||
include('attempt_close_js.php'); |
|
||||
} |
|
||||
|
|
||||
/// Print the navigation panel if required |
$state->responses = array( '' => $question->studentanswer); |
||||
$numpages = game_number_of_pages( $attempt->layout); |
$state->attempt = $question->iid; |
||||
if ($numpages > 1 and !$showall) { |
|
||||
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); |
|
||||
echo '<div class="controls"><a href="review.php?attempt='.$attempt->id.'&showall=true">'; |
|
||||
print_string('showall', 'game'); |
|
||||
echo '</a></div>'; |
|
||||
} |
|
||||
|
|
||||
/// Print all the questions |
$states[ $question->id] = $state; |
||||
if( $pagelist){ |
|
||||
game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game); |
|
||||
} |
} |
||||
|
return $states; |
||||
|
} |
||||
|
|
||||
// Print the navigation panel if required |
function game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game) { |
||||
if ($numpages > 1 and !$showall) { |
$pagequestions = explode(',', $pagelist); |
||||
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); |
$number = game_first_questionnumber( $attempt->layout, $pagelist); |
||||
} |
foreach ($pagequestions as $i) { |
||||
|
if (!isset($questions[$i])) { |
||||
|
echo $OUTPUT->box_start('center', '90%'); |
||||
|
echo '<strong><font size="+1">' . $number . '</font></strong><br />'; |
||||
|
notify(get_string('errormissingquestion', 'quiz', $i)); |
||||
|
echo $OUTPUT->box_end(); |
||||
|
$number++; // Just guessing that the missing question would have lenght 1. |
||||
|
continue; |
||||
|
} |
||||
|
$options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event; |
||||
|
$options->history = false; |
||||
|
unset( $options->questioncommentlink); |
||||
|
|
||||
// print javascript button to close the window, if necessary |
// Print the question. |
||||
if (!$isteacher) { |
if ($i > 0) { |
||||
include('attempt_close_js.php'); |
echo "<br />\n"; |
||||
} |
} |
||||
|
|
||||
|
$questions[$i]->maxgrade = 0; |
||||
|
|
||||
if (empty($popup)) { |
$options->correct_responses = 0; |
||||
echo $OUTPUT->footer($course); |
$options->feedback = 0; |
||||
|
$options->readonly = 0; |
||||
|
|
||||
|
global $QTYPES; |
||||
|
|
||||
|
unset( $cmoptions); |
||||
|
$cmoptions->course = $game->course; |
||||
|
$cmoptions->optionflags->optionflags = 0; |
||||
|
$cmoptions->id = 0; |
||||
|
$cmoptions->shuffleanswers = 1; |
||||
|
$attempt = 0; |
||||
|
$question = $questions[ $i]; |
||||
|
if (!$QTYPES[$question->qtype]->create_session_and_responses( $question, $state, $cmoptions, $attempt)) { |
||||
|
print_error( 'game_sudoku_showquestions_quiz: problem'); |
||||
|
} |
||||
|
$cmoptions->optionflags = 0; |
||||
|
print_question( $question, $states[$i], $number, $cmoptions, $options); |
||||
|
$number += $questions[$i]->length; |
||||
} |
} |
||||
|
} |
||||
function game_compute_states( $game, $questions) |
|
||||
{ |
|
||||
global $QTYPES; |
|
||||
|
|
||||
// Restore the question sessions to their most recent states |
|
||||
// creating new sessions where required |
|
||||
|
|
||||
$states = array(); |
|
||||
foreach ($questions as $question) { |
|
||||
$state = new StdClass; |
|
||||
|
|
||||
$cmoptions->course = $game->course; |
|
||||
$cmoptions->optionflags->optionflags = 0; |
|
||||
$cmoptions->id = 0; |
|
||||
$cmoptions->shuffleanswers = 1; |
|
||||
|
|
||||
$state->last_graded = new StdClass; |
|
||||
$state->last_graded->event = QUESTION_EVENTOPEN; |
|
||||
|
|
||||
$state->raw_grade = 0; |
|
||||
|
|
||||
$attempt = 0; |
|
||||
if (!$QTYPES[$question->qtype]->create_session_and_responses( $question, $state, $cmoptions, $attempt)) { |
|
||||
print_error( 'game_compute_states: problem'); |
|
||||
} |
|
||||
|
|
||||
$state->event = QUESTION_EVENTOPEN; |
|
||||
//$question->maxgrade = 100; |
|
||||
$state->manualcomment = ''; |
|
||||
|
|
||||
$state->responses = array( '' => $question->studentanswer); |
|
||||
$state->attempt = $question->iid; |
|
||||
|
|
||||
$states[ $question->id] = $state; |
|
||||
} |
|
||||
return $states; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
function game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game) |
|
||||
{ |
|
||||
$pagequestions = explode(',', $pagelist); |
|
||||
$number = game_first_questionnumber( $attempt->layout, $pagelist); |
|
||||
foreach ($pagequestions as $i) { |
|
||||
if (!isset($questions[$i])) { |
|
||||
echo $OUTPUT->box_start('center', '90%'); |
|
||||
echo '<strong><font size="+1">' . $number . '</font></strong><br />'; |
|
||||
notify(get_string('errormissingquestion', 'quiz', $i)); |
|
||||
echo $OUTPUT->box_end(); |
|
||||
$number++; // Just guessing that the missing question would have lenght 1 |
|
||||
continue; |
|
||||
} |
|
||||
$options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event; |
|
||||
//$options->history = ($isteacher and !$attempt->preview) ? 'all' : 'graded'; |
|
||||
$options->history = false; |
|
||||
unset( $options->questioncommentlink); |
|
||||
// Print the question |
|
||||
if ($i > 0) { |
|
||||
echo "<br />\n"; |
|
||||
} |
|
||||
$questions[$i]->maxgrade = 0; |
|
||||
|
|
||||
$options->correct_responses = 0; |
|
||||
$options->feedback = 0; |
|
||||
$options->readonly = 0; |
|
||||
|
|
||||
global $QTYPES; |
|
||||
|
|
||||
unset( $cmoptions); |
|
||||
$cmoptions->course = $game->course; |
|
||||
$cmoptions->optionflags->optionflags = 0; |
|
||||
$cmoptions->id = 0; |
|
||||
$cmoptions->shuffleanswers = 1; |
|
||||
$attempt = 0; |
|
||||
$question = $questions[ $i]; |
|
||||
if (!$QTYPES[$question->qtype]->create_session_and_responses( $question, $state, $cmoptions, $attempt)) { |
|
||||
print_error( 'game_sudoku_showquestions_quiz: problem'); |
|
||||
} |
|
||||
$cmoptions->optionflags = 0; |
|
||||
print_question( $question, $states[$i], $number, $cmoptions, $options); |
|
||||
$number += $questions[$i]->length; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
?> |
|
||||
|
@ -1,308 +1,315 @@ |
|||||
<?php // $Id: view.php,v 1.14 2012/07/25 11:16:04 bdaloukas Exp $
|
<?php |
||||
|
// This file is part of Moodle - http://moodle.org/ |
||||
// This page prints a particular instance of game |
// |
||||
|
// Moodle is free software: you can redistribute it and/or modify |
||||
require_once(dirname(__FILE__) . '/../../config.php'); |
// it under the terms of the GNU General Public License as published by |
||||
require_once($CFG->libdir.'/gradelib.php'); |
// the Free Software Foundation, either version 3 of the License, or |
||||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
// (at your option) any later version. |
||||
|
// |
||||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or |
// Moodle is distributed in the hope that it will be useful, |
||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
if (! $cm = get_coursemodule_from_id('game', $id)) { |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
print_error('invalidcoursemodule'); |
// GNU General Public License for more details. |
||||
} |
// |
||||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) { |
// You should have received a copy of the GNU General Public License |
||||
print_error('coursemisconf'); |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
// This page prints a particular instance of game. |
||||
|
|
||||
|
require_once(dirname(__FILE__) . '/../../config.php'); |
||||
|
require_once($CFG->libdir.'/gradelib.php'); |
||||
|
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
||||
|
|
||||
|
$id = optional_param('id', 0, PARAM_INT); // Course Module ID. |
||||
|
|
||||
|
if (! $cm = get_coursemodule_from_id('game', $id)) { |
||||
|
print_error('invalidcoursemodule'); |
||||
|
} |
||||
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) { |
||||
|
print_error('coursemisconf'); |
||||
|
} |
||||
|
if (! $game = $DB->get_record('game', array('id' => $cm->instance))) { |
||||
|
print_error('invalidcoursemodule'); |
||||
|
} |
||||
|
|
||||
|
// Check login and get context. |
||||
|
require_login($course->id, false, $cm); |
||||
|
$context = game_get_context_module_instance( $cm->id); |
||||
|
require_capability('mod/game:view', $context); |
||||
|
|
||||
|
$timenow = time(); |
||||
|
|
||||
|
// Cache some other capabilites we use several times. |
||||
|
$canattempt = true; |
||||
|
$strtimeopenclose = ''; |
||||
|
if ($timenow < $game->timeopen) { |
||||
|
$canattempt = false; |
||||
|
$strtimeopenclose = get_string('gamenotavailable', 'game', userdate($game->timeopen)); |
||||
|
} else if ($game->timeclose && $timenow > $game->timeclose) { |
||||
|
$strtimeopenclose = get_string("gameclosed", "game", userdate($game->timeclose)); |
||||
|
$canattempt = false; |
||||
|
} else { |
||||
|
if ($game->timeopen) { |
||||
|
$strtimeopenclose = get_string('gameopenedon', 'game', userdate($game->timeopen)); |
||||
} |
} |
||||
if (! $game = $DB->get_record('game', array('id' => $cm->instance))) { |
if ($game->timeclose) { |
||||
print_error('invalidcoursemodule'); |
$strtimeopenclose = get_string('gamecloseson', 'game', userdate($game->timeclose)); |
||||
} |
} |
||||
|
} |
||||
/// Check login and get context. |
if (has_capability('mod/game:manage', $context)) { |
||||
require_login($course->id, false, $cm); |
|
||||
$context = game_get_context_module_instance( $cm->id); |
|
||||
require_capability('mod/game:view', $context); |
|
||||
|
|
||||
$timenow = time(); |
|
||||
|
|
||||
/// Cache some other capabilites we use several times. |
|
||||
$canattempt = true; |
$canattempt = true; |
||||
$strtimeopenclose = ''; |
} |
||||
if ($timenow < $game->timeopen) { |
|
||||
$canattempt = false; |
|
||||
$strtimeopenclose = get_string('gamenotavailable', 'game', userdate($game->timeopen)); |
|
||||
} else if ($game->timeclose && $timenow > $game->timeclose) { |
|
||||
$strtimeopenclose = get_string("gameclosed", "game", userdate($game->timeclose)); |
|
||||
$canattempt = false; |
|
||||
} else { |
|
||||
if ($game->timeopen) { |
|
||||
$strtimeopenclose = get_string('gameopenedon', 'game', userdate($game->timeopen)); |
|
||||
} |
|
||||
if ($game->timeclose) { |
|
||||
$strtimeopenclose = get_string('gamecloseson', 'game', userdate($game->timeclose)); |
|
||||
} |
|
||||
} |
|
||||
if (has_capability('mod/game:manage', $context)) { |
|
||||
$canattempt = true; |
|
||||
} |
|
||||
|
|
||||
/// Log this request. |
|
||||
if( game_use_events()) |
|
||||
{ |
|
||||
require( 'classes/event/course_module_viewed.php'); |
|
||||
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger(); |
|
||||
}else |
|
||||
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); |
|
||||
|
|
||||
// Mark as viewed |
|
||||
$completion=new completion_info($course); |
|
||||
$completion->set_module_viewed($cm); |
|
||||
|
|
||||
/// Initialize $PAGE, compute blocks |
|
||||
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); |
|
||||
|
|
||||
$edit = optional_param('edit', -1, PARAM_BOOL); |
|
||||
if ($edit != -1 && $PAGE->user_allowed_editing()) { |
|
||||
$USER->editing = $edit; |
|
||||
} |
|
||||
|
|
||||
$title = $course->shortname . ': ' . format_string($game->name); |
// Log this request. |
||||
|
if (game_use_events()) { |
||||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
require( 'classes/event/course_module_viewed.php'); |
||||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
\mod_game\event\course_module_viewed::viewed($game, $context)->trigger(); |
||||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
} else { |
||||
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'. |
add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); |
||||
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>'; |
} |
||||
$PAGE->set_button($buttons); |
|
||||
} |
// Mark as viewed. |
||||
|
$completion = new completion_info($course); |
||||
$PAGE->set_title($title); |
$completion->set_module_viewed($cm); |
||||
$PAGE->set_heading($course->fullname); |
|
||||
|
// Initialize $PAGE, compute blocks. |
||||
echo $OUTPUT->header(); |
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); |
||||
|
|
||||
/// Print game name and description |
$edit = optional_param('edit', -1, PARAM_BOOL); |
||||
echo $OUTPUT->heading(format_string($game->name)); |
if ($edit != -1 && $PAGE->user_allowed_editing()) { |
||||
|
$USER->editing = $edit; |
||||
/// Display information about this game. |
} |
||||
|
|
||||
echo $OUTPUT->box_start('quizinfo'); |
$title = $course->shortname . ': ' . format_string($game->name); |
||||
if ($game->attempts != 1) { |
|
||||
echo get_string('gradingmethod', 'quiz', game_get_grading_option_name($game->grademethod)); |
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
||||
} |
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
||||
echo $OUTPUT->box_end(); |
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
||||
|
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing() ? 'off' : 'on').'" />'. |
||||
/// Show number of attempts summary to those who can view reports. |
'<input type="submit" value="'. |
||||
if (has_capability('mod/game:viewreports', $context)) { |
get_string($PAGE->user_is_editing() ? 'blockseditoff' : 'blocksediton'). |
||||
if ($strattemptnum = game_get_user_attempts($game->id, $USER->id)) { |
'" /></div></form></td></tr></table>'; |
||||
//echo '<div class="gameattemptcounts"><a href="report.php?mode=overview&id=' . |
$PAGE->set_button($buttons); |
||||
// $cm->id . '">' . $strattemptnum . "</a></div>\n"; |
} |
||||
echo get_string( 'attempts', 'game').': '.count( $strattemptnum); |
|
||||
if( $game->maxattempts) |
$PAGE->set_title($title); |
||||
{ |
$PAGE->set_heading($course->fullname); |
||||
echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')'; |
|
||||
} |
echo $OUTPUT->header(); |
||||
|
|
||||
|
// Print game name and description. |
||||
|
echo $OUTPUT->heading(format_string($game->name)); |
||||
|
|
||||
|
// Display information about this game. |
||||
|
echo $OUTPUT->box_start('quizinfo'); |
||||
|
if ($game->attempts != 1) { |
||||
|
echo get_string('gradingmethod', 'quiz', game_get_grading_option_name($game->grademethod)); |
||||
|
} |
||||
|
echo $OUTPUT->box_end(); |
||||
|
|
||||
|
// Show number of attempts summary to those who can view reports. |
||||
|
if (has_capability('mod/game:viewreports', $context)) { |
||||
|
if ($strattemptnum = game_get_user_attempts($game->id, $USER->id)) { |
||||
|
echo get_string( 'attempts', 'game').': '.count( $strattemptnum); |
||||
|
if ($game->maxattempts) { |
||||
|
echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')'; |
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
/// Get this user's attempts. |
|
||||
$attempts = game_get_user_attempts($game->id, $USER->id); |
// Get this user's attempts. |
||||
$lastfinishedattempt = end($attempts); |
$attempts = game_get_user_attempts($game->id, $USER->id); |
||||
$unfinished = false; |
$lastfinishedattempt = end($attempts); |
||||
if ($unfinishedattempt = game_get_user_attempt_unfinished($game->id, $USER->id)) { |
$unfinished = false; |
||||
$attempts[] = $unfinishedattempt; |
if ($unfinishedattempt = game_get_user_attempt_unfinished($game->id, $USER->id)) { |
||||
$unfinished = true; |
$attempts[] = $unfinishedattempt; |
||||
} |
$unfinished = true; |
||||
$numattempts = count($attempts); |
} |
||||
|
$numattempts = count($attempts); |
||||
/// Work out the final grade, checking whether it was overridden in the gradebook. |
|
||||
$mygrade = game_get_best_grade($game, $USER->id); |
// Work out the final grade, checking whether it was overridden in the gradebook. |
||||
$mygradeoverridden = false; |
$mygrade = game_get_best_grade($game, $USER->id); |
||||
$gradebookfeedback = ''; |
$mygradeoverridden = false; |
||||
|
$gradebookfeedback = ''; |
||||
$grading_info = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id); |
|
||||
if (!empty($grading_info->items)) { |
$gradinginfo = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id); |
||||
$item = $grading_info->items[0]; |
if (!empty($gradinginfo->items)) { |
||||
if (isset($item->grades[$USER->id])) { |
$item = $gradinginfo->items[0]; |
||||
$grade = $item->grades[$USER->id]; |
if (isset($item->grades[$USER->id])) { |
||||
|
$grade = $item->grades[$USER->id]; |
||||
if ($grade->overridden) { |
|
||||
$mygrade = $grade->grade + 0; // Convert to number. |
if ($grade->overridden) { |
||||
$mygradeoverridden = true; |
$mygrade = $grade->grade + 0; // Convert to number. |
||||
} |
$mygradeoverridden = true; |
||||
if (!empty($grade->str_feedback)) { |
} |
||||
$gradebookfeedback = $grade->str_feedback; |
if (!empty($grade->str_feedback)) { |
||||
} |
$gradebookfeedback = $grade->str_feedback; |
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
|
|
||||
/// Print table with existing attempts |
// Print table with existing attempts. |
||||
if ($attempts) { |
if ($attempts) { |
||||
|
echo $OUTPUT->heading(get_string('summaryofattempts', 'quiz')); |
||||
|
|
||||
echo $OUTPUT->heading(get_string('summaryofattempts', 'quiz')); |
// Work out which columns we need, taking account what data is available in each attempt. |
||||
|
list($someoptions, $alloptions) = game_get_combined_reviewoptions($game, $attempts, $context); |
||||
|
|
||||
// Work out which columns we need, taking account what data is available in each attempt. |
$attemptcolumn = $game->attempts != 1; |
||||
list($someoptions, $alloptions) = game_get_combined_reviewoptions($game, $attempts, $context); |
|
||||
|
|
||||
$attemptcolumn = $game->attempts != 1; |
$gradecolumn = $someoptions->scores && ($game->grade > 0); |
||||
|
$overallstats = $alloptions->scores; |
||||
|
|
||||
$gradecolumn = $someoptions->scores && ($game->grade > 0); |
// Prepare table header. |
||||
//$markcolumn = $gradecolumn && ($game->grade != $game->sumgrades); |
$table = new html_table(); |
||||
$overallstats = $alloptions->scores; |
$table->attributes['class'] = 'generaltable gameattemptsummary'; |
||||
|
$table->head = array(); |
||||
|
$table->align = array(); |
||||
|
$table->size = array(); |
||||
|
if ($attemptcolumn) { |
||||
|
$table->head[] = get_string('attempt', 'game'); |
||||
|
$table->align[] = 'center'; |
||||
|
$table->size[] = ''; |
||||
|
} |
||||
|
$table->head[] = get_string('timecompleted', 'game'); |
||||
|
$table->align[] = 'left'; |
||||
|
$table->size[] = ''; |
||||
|
|
||||
// Prepare table header |
if ($gradecolumn) { |
||||
$table = new html_table(); |
$table->head[] = get_string('grade') . ' / ' . game_format_grade( $game, $game->grade); |
||||
$table->attributes['class'] = 'generaltable gameattemptsummary'; |
$table->align[] = 'center'; |
||||
$table->head = array(); |
|
||||
$table->align = array(); |
|
||||
$table->size = array(); |
|
||||
if ($attemptcolumn) { |
|
||||
$table->head[] = get_string('attempt', 'game'); |
|
||||
$table->align[] = 'center'; |
|
||||
$table->size[] = ''; |
|
||||
} |
|
||||
$table->head[] = get_string('timecompleted', 'game'); |
|
||||
$table->align[] = 'left'; |
|
||||
$table->size[] = ''; |
$table->size[] = ''; |
||||
|
} |
||||
|
|
||||
if ($gradecolumn) { |
$table->head[] = get_string('timetaken', 'game'); |
||||
$table->head[] = get_string('grade') . ' / ' . game_format_grade( $game, $game->grade); |
$table->align[] = 'left'; |
||||
$table->align[] = 'center'; |
$table->size[] = ''; |
||||
$table->size[] = ''; |
|
||||
} |
|
||||
|
|
||||
$table->head[] = get_string('timetaken', 'game'); |
// One row for each attempt. |
||||
$table->align[] = 'left'; |
foreach ($attempts as $attempt) { |
||||
$table->size[] = ''; |
$attemptoptions = game_get_reviewoptions($game, $attempt, $context); |
||||
|
$row = array(); |
||||
|
|
||||
// One row for each attempt |
// Add the attempt number, making it a link, if appropriate. |
||||
foreach ($attempts as $attempt) { |
if ($attemptcolumn) { |
||||
$attemptoptions = game_get_reviewoptions($game, $attempt, $context); |
if ($attempt->preview) { |
||||
$row = array(); |
$row[] = get_string('preview', 'game'); |
||||
|
} else { |
||||
// Add the attempt number, making it a link, if appropriate. |
$row[] = $attempt->attempt; |
||||
if ($attemptcolumn) { |
|
||||
if ($attempt->preview) { |
|
||||
$row[] = get_string('preview', 'game'); |
|
||||
} else { |
|
||||
$row[] = $attempt->attempt; |
|
||||
} |
|
||||
} |
} |
||||
|
} |
||||
|
|
||||
// prepare strings for time taken and date completed |
// Prepare strings for time taken and date completed. |
||||
$timetaken = ''; |
$timetaken = ''; |
||||
|
$datecompleted = ''; |
||||
|
if ($attempt->timefinish > 0) { |
||||
|
// Attempt has finished. |
||||
|
$timetaken = format_time($attempt->timefinish - $attempt->timestart); |
||||
|
$datecompleted = userdate($attempt->timefinish); |
||||
|
} else { |
||||
|
// The a is still in progress. |
||||
|
$timetaken = format_time($timenow - $attempt->timestart); |
||||
$datecompleted = ''; |
$datecompleted = ''; |
||||
if ($attempt->timefinish > 0) { |
} |
||||
// attempt has finished |
$row[] = $datecompleted; |
||||
$timetaken = format_time($attempt->timefinish - $attempt->timestart); |
|
||||
$datecompleted = userdate($attempt->timefinish); |
|
||||
} else |
|
||||
{ |
|
||||
// The a is still in progress. |
|
||||
$timetaken = format_time($timenow - $attempt->timestart); |
|
||||
$datecompleted = ''; |
|
||||
} |
|
||||
$row[] = $datecompleted; |
|
||||
|
|
||||
// Ouside the if because we may be showing feedback but not grades. bdaloukas |
// Ouside the if because we may be showing feedback but not grades. |
||||
$attemptgrade = game_score_to_grade($attempt->score, $game); |
$attemptgrade = game_score_to_grade($attempt->score, $game); |
||||
|
|
||||
if ($gradecolumn) { |
if ($gradecolumn) { |
||||
if ($attemptoptions->scores) { |
if ($attemptoptions->scores) { |
||||
$formattedgrade = game_format_grade($game, $attemptgrade); |
$formattedgrade = game_format_grade($game, $attemptgrade); |
||||
// highlight the highest grade if appropriate |
// Highlight the highest grade if appropriate. |
||||
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) && |
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) && |
||||
$attemptgrade == $mygrade && $game->grademethod == QUIZ_GRADEHIGHEST) { |
$attemptgrade == $mygrade && $game->grademethod == QUIZ_GRADEHIGHEST) { |
||||
$table->rowclasses[$attempt->attempt] = 'bestrow'; |
$table->rowclasses[$attempt->attempt] = 'bestrow'; |
||||
} |
|
||||
|
|
||||
$row[] = $formattedgrade; |
|
||||
} else { |
|
||||
$row[] = ''; |
|
||||
} |
} |
||||
} |
|
||||
|
|
||||
$row[] = $timetaken; |
|
||||
|
|
||||
if ($attempt->preview) { |
$row[] = $formattedgrade; |
||||
$table->data['preview'] = $row; |
|
||||
} else { |
} else { |
||||
$table->data[$attempt->attempt] = $row; |
$row[] = ''; |
||||
} |
} |
||||
} // End of loop over attempts. |
} |
||||
echo html_writer::table($table); |
|
||||
} |
|
||||
|
|
||||
/// Print information about the student's best score for this game if possible. |
$row[] = $timetaken; |
||||
|
|
||||
|
if ($attempt->preview) { |
||||
|
$table->data['preview'] = $row; |
||||
|
} else { |
||||
|
$table->data[$attempt->attempt] = $row; |
||||
|
} |
||||
|
} // End of loop over attempts. |
||||
|
echo html_writer::table($table); |
||||
|
} |
||||
|
|
||||
|
// Print information about the student's best score for this game if possible. |
||||
|
if ($numattempts && $gradecolumn && !is_null($mygrade)) { |
||||
|
$resultinfo = ''; |
||||
|
|
||||
|
if ($overallstats) { |
||||
|
$a = new stdClass; |
||||
|
$a->grade = game_format_grade($game, $mygrade); |
||||
|
$a->maxgrade = game_format_grade($game, $game->grade); |
||||
|
$a = get_string('outofshort', 'quiz', $a); |
||||
|
$resultinfo .= $OUTPUT->heading(get_string('yourfinalgradeis', 'game', $a), 2, 'main'); |
||||
|
} |
||||
|
|
||||
if ($numattempts && $gradecolumn && !is_null($mygrade)) { |
if ($mygradeoverridden) { |
||||
$resultinfo = ''; |
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n"; |
||||
|
} |
||||
|
|
||||
if ($overallstats) { |
if ($gradebookfeedback) { |
||||
$a = new stdClass; |
$resultinfo .= $OUTPUT->heading(get_string('comment', 'game'), 3, 'main'); |
||||
$a->grade = game_format_grade($game, $mygrade); |
$resultinfo .= '<p class="gameteacherfeedback">'.$gradebookfeedback."</p>\n"; |
||||
$a->maxgrade = game_format_grade($game, $game->grade); |
} |
||||
$a = get_string('outofshort', 'quiz', $a); |
|
||||
$resultinfo .= $OUTPUT->heading(get_string('yourfinalgradeis', 'game', $a), 2, 'main'); |
|
||||
} |
|
||||
|
|
||||
if ($mygradeoverridden) { |
if ($resultinfo) { |
||||
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n"; |
echo $OUTPUT->box($resultinfo, 'generalbox', 'feedback'); |
||||
} |
} |
||||
if ($gradebookfeedback) { |
} |
||||
$resultinfo .= $OUTPUT->heading(get_string('comment', 'game'), 3, 'main'); |
|
||||
$resultinfo .= '<p class="gameteacherfeedback">'.$gradebookfeedback."</p>\n"; |
|
||||
} |
|
||||
|
|
||||
if ($resultinfo) { |
// Determine if we should be showing a start/continue attempt button or a button to go back to the course page. |
||||
echo $OUTPUT->box($resultinfo, 'generalbox', 'feedback'); |
echo $OUTPUT->box_start('gameattempt'); |
||||
} |
$buttontext = ''; // This will be set something if as start/continue attempt button should appear. |
||||
|
|
||||
|
if ($unfinished) { |
||||
|
if ($canattempt) { |
||||
|
$buttontext = get_string('continueattemptgame', 'game'); |
||||
|
} |
||||
|
} else { |
||||
|
// Game is finished. Check if max number of attempts is reached. |
||||
|
if (!game_can_start_new_attempt( $game)) { |
||||
|
$canattempt = false; |
||||
} |
} |
||||
|
|
||||
/// Determine if we should be showing a start/continue attempt button, |
if ($canattempt) { |
||||
/// or a button to go back to the course page. |
echo '<br>'; |
||||
echo $OUTPUT->box_start('gameattempt'); |
|
||||
$buttontext = ''; // This will be set something if as start/continue attempt button should appear. |
|
||||
|
|
||||
if ($unfinished) { |
if ($numattempts == 0) { |
||||
if ($canattempt) { |
$buttontext = get_string('attemptgamenow', 'game'); |
||||
$buttontext = get_string('continueattemptgame', 'game'); |
} else { |
||||
} |
$buttontext = get_string('reattemptgame', 'game'); |
||||
} else { |
|
||||
//Game is finished. Check if max number of attempts is reached |
|
||||
if( !game_can_start_new_attempt( $game)) |
|
||||
$canattempt = false; |
|
||||
|
|
||||
if ($canattempt) { |
|
||||
echo '<br>'; |
|
||||
if ($numattempts == 0) { |
|
||||
$buttontext = get_string('attemptgamenow', 'game'); |
|
||||
} else { |
|
||||
$buttontext = get_string('reattemptgame', 'game'); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
} |
||||
|
|
||||
/// Now actually print the appropriate button. |
// Now actually print the appropriate button. |
||||
|
echo $strtimeopenclose; |
||||
|
|
||||
echo $strtimeopenclose; |
if ($buttontext) { |
||||
|
global $OUTPUT; |
||||
|
|
||||
if ($buttontext) { |
$strconfirmstartattempt = ''; |
||||
|
|
||||
global $OUTPUT; |
// Show the start button, in a div that is initially hidden. |
||||
|
echo '<div id="gamestartbuttondiv">'; |
||||
|
$url = new moodle_url($CFG->wwwroot.'/mod/game/attempt.php', array('id' => $id)); |
||||
|
$button = new single_button($url, $buttontext); |
||||
|
echo $OUTPUT->render($button); |
||||
|
echo "</div>\n"; |
||||
|
} else { |
||||
|
echo $OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id); |
||||
|
} |
||||
|
echo $OUTPUT->box_end(); |
||||
|
|
||||
$strconfirmstartattempt = ''; |
echo $OUTPUT->footer(); |
||||
|
|
||||
/// Show the start button, in a div that is initially hidden. |
|
||||
echo '<div id="gamestartbuttondiv">'; |
|
||||
$url = new moodle_url($CFG->wwwroot.'/mod/game/attempt.php', array('id' => $id)); |
|
||||
$button = new single_button($url, $buttontext); |
|
||||
echo $OUTPUT->render($button); |
|
||||
echo "</div>\n"; |
|
||||
} else { |
|
||||
echo $OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id); |
|
||||
} |
|
||||
echo $OUTPUT->box_end(); |
|
||||
|
|
||||
echo $OUTPUT->footer(); |
|
||||
|
Loading…
Reference in new issue