Vasilis Daloukas
9 years ago
14 changed files with 1824 additions and 1707 deletions
@ -1,82 +1,92 @@ |
|||
<?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($CFG->libdir.'/gradelib.php'); |
|||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
|||
require_once($CFG->libdir . '/completionlib.php'); |
|||
require_once(dirname(__FILE__) . '/../../config.php'); |
|||
require_once($CFG->libdir.'/gradelib.php'); |
|||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
|||
require_once($CFG->libdir . '/completionlib.php'); |
|||
|
|||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or |
|||
$q = optional_param('q', 0, PARAM_INT); // game ID |
|||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID. |
|||
$q = optional_param('q', 0, PARAM_INT); // Game ID. |
|||
|
|||
if ($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'); |
|||
} |
|||
} 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 ($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'); |
|||
} |
|||
} 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. |
|||
require_login($course->id, false, $cm); |
|||
$context = game_get_context_module_instance( $cm->id); |
|||
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); |
|||
// 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); |
|||
|
|||
/// Create an object to manage all the other (non-roles) access rules. |
|||
$timenow = time(); |
|||
//$accessmanager = new game_access_manager(game::create($game->id, $USER->id), $timenow); |
|||
// Cache some other capabilites we use several times. |
|||
$canattempt = has_capability('mod/game:attempt', $context); |
|||
$canreviewmine = has_capability('mod/game:reviewmyattempts', $context); |
|||
|
|||
/// If no questions have been set up yet redirect to edit.php |
|||
//if (!$game->questions && has_capability('mod/game:manage', $context)) { |
|||
// redirect($CFG->wwwroot . '/mod/game/edit.php?cmid=' . $cm->id); |
|||
//} |
|||
// Create an object to manage all the other (non-roles) access rules. |
|||
$timenow = time(); |
|||
|
|||
/// 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); |
|||
// 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); |
|||
} |
|||
|
|||
/// Initialize $PAGE, compute blocks |
|||
$PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); |
|||
// 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; |
|||
} |
|||
$edit = optional_param('edit', -1, PARAM_BOOL); |
|||
if ($edit != -1 && $PAGE->user_allowed_editing()) { |
|||
$USER->editing = $edit; |
|||
} |
|||
|
|||
// Note: MDL-19010 there will be further changes to printing header and blocks. |
|||
// The code will be much nicer than this eventually. |
|||
$title = $course->shortname . ': ' . format_string($game->name); |
|||
// Note: MDL-19010 there will be further changes to printing header and blocks. |
|||
// The code will be much nicer than this eventually. |
|||
$title = $course->shortname . ': ' . format_string($game->name); |
|||
|
|||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
|||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
|||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
|||
'<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>'; |
|||
$PAGE->set_button($buttons); |
|||
} |
|||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
|||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
|||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
|||
'<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>'; |
|||
$PAGE->set_button($buttons); |
|||
} |
|||
|
|||
$PAGE->set_title($title); |
|||
$PAGE->set_heading($course->fullname); |
|||
$PAGE->set_title($title); |
|||
$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 $
|
|||
|
|||
// This script uses installed report plugins to print game reports |
|||
|
|||
require_once("../../config.php"); |
|||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
|||
require_once($CFG->dirroot.'/mod/game/report/reportlib.php'); |
|||
|
|||
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or |
|||
$q = optional_param('q',0,PARAM_INT); // game ID |
|||
|
|||
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode |
|||
|
|||
if ($id) { |
|||
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' => $cm->course))) { |
|||
print_error( 'Course is misconfigured'); |
|||
} |
|||
|
|||
if (! $game = $DB->get_record( 'game', array( 'id' => $cm->instance))) { |
|||
print_error( "The game with id $cm->instance corresponding to this coursemodule $id is missing"); |
|||
} |
|||
|
|||
} else { |
|||
if (! $game = $DB->get_record( 'game', array( 'id' => $q))) { |
|||
print_error( "There is no game with id $q"); |
|||
} |
|||
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"); |
|||
} |
|||
<?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 uses installed report plugins to print game reports. |
|||
|
|||
require_once("../../config.php"); |
|||
require_once($CFG->dirroot.'/mod/game/locallib.php'); |
|||
require_once($CFG->dirroot.'/mod/game/report/reportlib.php'); |
|||
|
|||
$id = optional_param('id', 0, PARAM_INT); // Course Module ID. |
|||
$q = optional_param('q', 0, PARAM_INT); // Game ID. |
|||
|
|||
$mode = optional_param('mode', 'overview', PARAM_ALPHA); // Report mode. |
|||
|
|||
if ($id) { |
|||
if (! $cm = get_coursemodule_from_id('game', $id)) { |
|||
print_error( "There is no coursemodule with id $id"); |
|||
} |
|||
|
|||
require_login($course->id, false); |
|||
$context = get_context_instance(CONTEXT_MODULE, $cm->id); |
|||
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); |
|||
//} |
|||
if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { |
|||
print_error( 'Course is misconfigured'); |
|||
} |
|||
|
|||
// Upgrade any attempts that have not yet been upgraded to the |
|||
// Moodle 1.5 model (they will not yet have the timestamp set) |
|||
//if ($attempts = get_records_sql("SELECT a.*". |
|||
// " FROM {$CFG->prefix}game_attempts a, {$CFG->prefix}question_states s". |
|||
// " WHERE a.game = '$game->id' AND s.attempt = a.uniqueid AND s.timestamp = 0")) { |
|||
// foreach ($attempts as $attempt) { |
|||
// game_upgrade_states($attempt); |
|||
// } |
|||
//} |
|||
if (! $game = $DB->get_record( 'game', array( 'id' => $cm->instance))) { |
|||
print_error( "The game with id $cm->instance corresponding to this coursemodule $id is missing"); |
|||
} |
|||
} else { |
|||
if (! $game = $DB->get_record( 'game', array( 'id' => $q))) { |
|||
print_error( "There is no game with id $q"); |
|||
} |
|||
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")) { |
|||
print_error("Report not known ($mode)"); |
|||
} |
|||
$mode = clean_param( $mode, PARAM_SAFEDIR); |
|||
|
|||
include("report/default.php"); // Parent class |
|||
include("report/$mode/report.php"); |
|||
if (! is_readable("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! |
|||
print_error( 'Error occurred during pre-processing!'); |
|||
} |
|||
$report = new game_overview_report(); |
|||
|
|||
/// 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 $
|
|||
/** |
|||
* This page prints a review of a particular game attempt |
|||
* |
|||
* @version $Id: review.php,v 1.12 2012/07/25 23:07:43 bdaloukas Exp $ |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License |
|||
* @package game |
|||
*/ |
|||
|
|||
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"); |
|||
<?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 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 = "<a href=\"{$CFG->wwwroot}/course/view.php?id=$course->id\">$course->shortname</a> ->"; |
|||
} else { |
|||
$navigation = ''; |
|||
} |
|||
|
|||
$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 = ''; |
|||
} |
|||
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 = ''; |
|||
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 ($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; |
|||
} |
|||
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); |
|||
/// Print infobox |
|||
|
|||
//$timelimit = (int)$game->timelimit * 60; |
|||
$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 = "-"; |
|||
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 = 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 ($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>'); |
|||
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) ? '<strong>'.$at->attempt.'</strong>, ' : '<a href="review.php?attempt='. |
|||
$at->id.($showall ? '&showall=true' : '').'">'.$at->attempt.'</a>, '; |
|||
} |
|||
//if (has_capability('mod/game:grade', $context)){ |
|||
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) |
|||
? '<strong>'.$at->attempt.'</strong>, ' |
|||
: '<a href="review.php?attempt='.$at->id.($showall?'&showall=true':'').'">'.$at->attempt.'</a>, '; |
|||
} |
|||
$table->data[] = array(get_string('attempts', 'game').':', trim($attemptlist, ' ,')); |
|||
$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"; |
|||
} |
|||
//} |
|||
|
|||
$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); |
|||
$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 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 %)"); |
|||
//$table->data[] = array("$strgrade:", get_string('outof', 'game', $a)); |
|||
} |
|||
|
|||
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. |
|||
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 |
|||
if (!$isteacher) { |
|||
include('attempt_close_js.php'); |
|||
} |
|||
$state->event = QUESTION_EVENTOPEN; |
|||
$state->manualcomment = ''; |
|||
|
|||
/// 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>'; |
|||
} |
|||
$state->responses = array( '' => $question->studentanswer); |
|||
$state->attempt = $question->iid; |
|||
|
|||
/// Print all the questions |
|||
if( $pagelist){ |
|||
game_print_questions( $pagelist, $attempt, $questions, $options, $states, $game); |
|||
$states[ $question->id] = $state; |
|||
} |
|||
return $states; |
|||
} |
|||
|
|||
// Print the navigation panel if required |
|||
if ($numpages > 1 and !$showall) { |
|||
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&'); |
|||
} |
|||
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 = false; |
|||
unset( $options->questioncommentlink); |
|||
|
|||
// print javascript button to close the window, if necessary |
|||
if (!$isteacher) { |
|||
include('attempt_close_js.php'); |
|||
} |
|||
// Print the question. |
|||
if ($i > 0) { |
|||
echo "<br />\n"; |
|||
} |
|||
|
|||
$questions[$i]->maxgrade = 0; |
|||
|
|||
if (empty($popup)) { |
|||
echo $OUTPUT->footer($course); |
|||
$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; |
|||
} |
|||
|
|||
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 $
|
|||
|
|||
// 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, or |
|||
|
|||
if (! $cm = get_coursemodule_from_id('game', $id)) { |
|||
print_error('invalidcoursemodule'); |
|||
} |
|||
if (! $course = $DB->get_record('course', array('id' => $cm->course))) { |
|||
print_error('coursemisconf'); |
|||
<?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 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))) { |
|||
print_error('invalidcoursemodule'); |
|||
if ($game->timeclose) { |
|||
$strtimeopenclose = get_string('gamecloseson', 'game', userdate($game->timeclose)); |
|||
} |
|||
|
|||
/// 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. |
|||
} |
|||
if (has_capability('mod/game:manage', $context)) { |
|||
$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); |
|||
|
|||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
|||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
|||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
|||
'<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>'; |
|||
$PAGE->set_button($buttons); |
|||
} |
|||
|
|||
$PAGE->set_title($title); |
|||
$PAGE->set_heading($course->fullname); |
|||
|
|||
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 '<div class="gameattemptcounts"><a href="report.php?mode=overview&id=' . |
|||
// $cm->id . '">' . $strattemptnum . "</a></div>\n"; |
|||
echo get_string( 'attempts', 'game').': '.count( $strattemptnum); |
|||
if( $game->maxattempts) |
|||
{ |
|||
echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')'; |
|||
} |
|||
// 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); |
|||
|
|||
if ($PAGE->user_allowed_editing() && !empty($CFG->showblocksonmodpages)) { |
|||
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'. |
|||
'<input type="hidden" name="id" value="'.$cm->id.'" />'. |
|||
'<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>'; |
|||
$PAGE->set_button($buttons); |
|||
} |
|||
|
|||
$PAGE->set_title($title); |
|||
$PAGE->set_heading($course->fullname); |
|||
|
|||
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); |
|||
$lastfinishedattempt = end($attempts); |
|||
$unfinished = false; |
|||
if ($unfinishedattempt = game_get_user_attempt_unfinished($game->id, $USER->id)) { |
|||
$attempts[] = $unfinishedattempt; |
|||
$unfinished = true; |
|||
} |
|||
$numattempts = count($attempts); |
|||
|
|||
/// Work out the final grade, checking whether it was overridden in the gradebook. |
|||
$mygrade = game_get_best_grade($game, $USER->id); |
|||
$mygradeoverridden = false; |
|||
$gradebookfeedback = ''; |
|||
|
|||
$grading_info = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id); |
|||
if (!empty($grading_info->items)) { |
|||
$item = $grading_info->items[0]; |
|||
if (isset($item->grades[$USER->id])) { |
|||
$grade = $item->grades[$USER->id]; |
|||
|
|||
if ($grade->overridden) { |
|||
$mygrade = $grade->grade + 0; // Convert to number. |
|||
$mygradeoverridden = true; |
|||
} |
|||
if (!empty($grade->str_feedback)) { |
|||
$gradebookfeedback = $grade->str_feedback; |
|||
} |
|||
} |
|||
|
|||
// Get this user's attempts. |
|||
$attempts = game_get_user_attempts($game->id, $USER->id); |
|||
$lastfinishedattempt = end($attempts); |
|||
$unfinished = false; |
|||
if ($unfinishedattempt = game_get_user_attempt_unfinished($game->id, $USER->id)) { |
|||
$attempts[] = $unfinishedattempt; |
|||
$unfinished = true; |
|||
} |
|||
$numattempts = count($attempts); |
|||
|
|||
// Work out the final grade, checking whether it was overridden in the gradebook. |
|||
$mygrade = game_get_best_grade($game, $USER->id); |
|||
$mygradeoverridden = false; |
|||
$gradebookfeedback = ''; |
|||
|
|||
$gradinginfo = grade_get_grades($course->id, 'mod', 'game', $game->id, $USER->id); |
|||
if (!empty($gradinginfo->items)) { |
|||
$item = $gradinginfo->items[0]; |
|||
if (isset($item->grades[$USER->id])) { |
|||
$grade = $item->grades[$USER->id]; |
|||
|
|||
if ($grade->overridden) { |
|||
$mygrade = $grade->grade + 0; // Convert to number. |
|||
$mygradeoverridden = true; |
|||
} |
|||
if (!empty($grade->str_feedback)) { |
|||
$gradebookfeedback = $grade->str_feedback; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// Print table with existing attempts |
|||
if ($attempts) { |
|||
// Print table with existing 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. |
|||
list($someoptions, $alloptions) = game_get_combined_reviewoptions($game, $attempts, $context); |
|||
$attemptcolumn = $game->attempts != 1; |
|||
|
|||
$attemptcolumn = $game->attempts != 1; |
|||
$gradecolumn = $someoptions->scores && ($game->grade > 0); |
|||
$overallstats = $alloptions->scores; |
|||
|
|||
$gradecolumn = $someoptions->scores && ($game->grade > 0); |
|||
//$markcolumn = $gradecolumn && ($game->grade != $game->sumgrades); |
|||
$overallstats = $alloptions->scores; |
|||
// Prepare table header. |
|||
$table = new html_table(); |
|||
$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 |
|||
$table = new html_table(); |
|||
$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'; |
|||
if ($gradecolumn) { |
|||
$table->head[] = get_string('grade') . ' / ' . game_format_grade( $game, $game->grade); |
|||
$table->align[] = 'center'; |
|||
$table->size[] = ''; |
|||
} |
|||
|
|||
if ($gradecolumn) { |
|||
$table->head[] = get_string('grade') . ' / ' . game_format_grade( $game, $game->grade); |
|||
$table->align[] = 'center'; |
|||
$table->size[] = ''; |
|||
} |
|||
$table->head[] = get_string('timetaken', 'game'); |
|||
$table->align[] = 'left'; |
|||
$table->size[] = ''; |
|||
|
|||
$table->head[] = get_string('timetaken', 'game'); |
|||
$table->align[] = 'left'; |
|||
$table->size[] = ''; |
|||
// One row for each attempt. |
|||
foreach ($attempts as $attempt) { |
|||
$attemptoptions = game_get_reviewoptions($game, $attempt, $context); |
|||
$row = array(); |
|||
|
|||
// One row for each attempt |
|||
foreach ($attempts as $attempt) { |
|||
$attemptoptions = game_get_reviewoptions($game, $attempt, $context); |
|||
$row = array(); |
|||
|
|||
// Add the attempt number, making it a link, if appropriate. |
|||
if ($attemptcolumn) { |
|||
if ($attempt->preview) { |
|||
$row[] = get_string('preview', 'game'); |
|||
} else { |
|||
$row[] = $attempt->attempt; |
|||
} |
|||
// Add the attempt number, making it a link, if appropriate. |
|||
if ($attemptcolumn) { |
|||
if ($attempt->preview) { |
|||
$row[] = get_string('preview', 'game'); |
|||
} else { |
|||
$row[] = $attempt->attempt; |
|||
} |
|||
} |
|||
|
|||
// prepare strings for time taken and date completed |
|||
$timetaken = ''; |
|||
// Prepare strings for time taken and date completed. |
|||
$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 = ''; |
|||
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 = ''; |
|||
} |
|||
$row[] = $datecompleted; |
|||
} |
|||
$row[] = $datecompleted; |
|||
|
|||
// Ouside the if because we may be showing feedback but not grades. bdaloukas |
|||
$attemptgrade = game_score_to_grade($attempt->score, $game); |
|||
// Ouside the if because we may be showing feedback but not grades. |
|||
$attemptgrade = game_score_to_grade($attempt->score, $game); |
|||
|
|||
if ($gradecolumn) { |
|||
if ($attemptoptions->scores) { |
|||
$formattedgrade = game_format_grade($game, $attemptgrade); |
|||
// highlight the highest grade if appropriate |
|||
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) && |
|||
$attemptgrade == $mygrade && $game->grademethod == QUIZ_GRADEHIGHEST) { |
|||
if ($gradecolumn) { |
|||
if ($attemptoptions->scores) { |
|||
$formattedgrade = game_format_grade($game, $attemptgrade); |
|||
// Highlight the highest grade if appropriate. |
|||
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) && |
|||
$attemptgrade == $mygrade && $game->grademethod == QUIZ_GRADEHIGHEST) { |
|||
$table->rowclasses[$attempt->attempt] = 'bestrow'; |
|||
} |
|||
|
|||
$row[] = $formattedgrade; |
|||
} else { |
|||
$row[] = ''; |
|||
} |
|||
} |
|||
|
|||
$row[] = $timetaken; |
|||
|
|||
if ($attempt->preview) { |
|||
$table->data['preview'] = $row; |
|||
$row[] = $formattedgrade; |
|||
} 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)) { |
|||
$resultinfo = ''; |
|||
if ($mygradeoverridden) { |
|||
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n"; |
|||
} |
|||
|
|||
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 ($gradebookfeedback) { |
|||
$resultinfo .= $OUTPUT->heading(get_string('comment', 'game'), 3, 'main'); |
|||
$resultinfo .= '<p class="gameteacherfeedback">'.$gradebookfeedback."</p>\n"; |
|||
} |
|||
|
|||
if ($mygradeoverridden) { |
|||
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n"; |
|||
} |
|||
if ($gradebookfeedback) { |
|||
$resultinfo .= $OUTPUT->heading(get_string('comment', 'game'), 3, 'main'); |
|||
$resultinfo .= '<p class="gameteacherfeedback">'.$gradebookfeedback."</p>\n"; |
|||
} |
|||
if ($resultinfo) { |
|||
echo $OUTPUT->box($resultinfo, 'generalbox', 'feedback'); |
|||
} |
|||
} |
|||
|
|||
if ($resultinfo) { |
|||
echo $OUTPUT->box($resultinfo, 'generalbox', 'feedback'); |
|||
} |
|||
// Determine if we should be showing a start/continue attempt button or a button to go back to the course page. |
|||
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, |
|||
/// or a button to go back to the course page. |
|||
echo $OUTPUT->box_start('gameattempt'); |
|||
$buttontext = ''; // This will be set something if as start/continue attempt button should appear. |
|||
if ($canattempt) { |
|||
echo '<br>'; |
|||
|
|||
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; |
|||
|
|||
if ($canattempt) { |
|||
echo '<br>'; |
|||
if ($numattempts == 0) { |
|||
$buttontext = get_string('attemptgamenow', 'game'); |
|||
} else { |
|||
$buttontext = get_string('reattemptgame', 'game'); |
|||
} |
|||
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 = ''; |
|||
|
|||
/// 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(); |
|||
echo $OUTPUT->footer(); |
|||
|
Loading…
Reference in new issue