2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// This page prints a particular instance of quiz
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2008-07-08 17:46:59 +00:00
|
|
|
require_once(dirname(__FILE__) . '/../../config.php');
|
2007-10-11 11:42:49 +00:00
|
|
|
require_once($CFG->libdir.'/gradelib.php');
|
|
|
|
require_once($CFG->dirroot.'/mod/quiz/locallib.php');
|
2009-05-08 09:00:41 +00:00
|
|
|
require_once($CFG->libdir . '/completionlib.php');
|
2007-10-11 11:42:49 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
|
|
|
|
$q = optional_param('q', 0, PARAM_INT); // quiz ID
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2002-10-04 02:59:05 +00:00
|
|
|
if ($id) {
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('quiz', $id)) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('coursemisconf');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $quiz = $DB->get_record('quiz', array('id' => $cm->instance))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $quiz = $DB->get_record('quiz', array('id' => $q))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidquizid', 'quiz');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
2008-06-09 10:00:35 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcourseid');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
|
2008-06-10 06:27:38 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-10-04 02:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-22 13:53:39 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Check login and get context.
|
2005-02-16 10:40:48 +00:00
|
|
|
require_login($course->id, false, $cm);
|
2006-08-25 16:03:54 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2008-03-07 12:33:07 +00:00
|
|
|
require_capability('mod/quiz:view', $context);
|
|
|
|
|
2010-09-17 10:27:26 +00:00
|
|
|
/// Cache some other capabilities we use several times.
|
2008-03-07 12:33:07 +00:00
|
|
|
$canattempt = has_capability('mod/quiz:attempt', $context);
|
2009-01-14 07:08:02 +00:00
|
|
|
$canreviewmine = has_capability('mod/quiz:reviewmyattempts', $context);
|
2008-03-07 12:33:07 +00:00
|
|
|
$canpreview = has_capability('mod/quiz:preview', $context);
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Create an object to manage all the other (non-roles) access rules.
|
|
|
|
$timenow = time();
|
2010-03-08 16:01:38 +00:00
|
|
|
$accessmanager = new quiz_access_manager(quiz::create($quiz->id, $USER->id), $timenow,
|
2008-03-07 12:33:07 +00:00
|
|
|
has_capability('mod/quiz:ignoretimelimits', $context, NULL, false));
|
|
|
|
|
|
|
|
/// If no questions have been set up yet redirect to edit.php
|
|
|
|
if (!$quiz->questions && has_capability('mod/quiz:manage', $context)) {
|
2008-04-22 15:19:50 +00:00
|
|
|
redirect($CFG->wwwroot . '/mod/quiz/edit.php?cmid=' . $cm->id);
|
2005-01-02 07:15:19 +00:00
|
|
|
}
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Log this request.
|
2004-01-31 15:22:04 +00:00
|
|
|
add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id);
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Initialize $PAGE, compute blocks
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/mod/quiz/view.php', array('id' => $cm->id));
|
2002-10-06 03:23:34 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
$edit = optional_param('edit', -1, PARAM_BOOL);
|
|
|
|
if ($edit != -1 && $PAGE->user_allowed_editing()) {
|
2006-04-23 20:58:06 +00:00
|
|
|
$USER->editing = $edit;
|
2005-02-01 07:16:19 +00:00
|
|
|
}
|
|
|
|
|
2009-12-16 20:25:14 +00:00
|
|
|
$PAGE->requires->yui2_lib('event');
|
2009-05-06 09:24:45 +00:00
|
|
|
|
2009-05-06 09:29:05 +00:00
|
|
|
// Note: MDL-19010 there will be further changes to printing header and blocks.
|
|
|
|
// The code will be much nicer than this eventually.
|
2009-05-06 09:24:45 +00:00
|
|
|
$title = $course->shortname . ': ' . format_string($quiz->name);
|
|
|
|
|
2010-08-06 06:20:28 +00:00
|
|
|
if ($PAGE->user_allowed_editing()) {
|
2010-02-11 13:27:02 +00:00
|
|
|
$buttons = '<table><tr><td><form method="get" action="view.php"><div>'.
|
2009-05-06 09:24:45 +00:00
|
|
|
'<input type="hidden" name="id" value="'.$cm->id.'" />'.
|
|
|
|
'<input type="hidden" name="edit" value="'.($PAGE->user_is_editing()?'off':'on').'" />'.
|
2009-12-23 01:57:55 +00:00
|
|
|
'<input type="submit" value="'.get_string($PAGE->user_is_editing()?'blockseditoff':'blocksediton').'" /></div></form></td></tr></table>';
|
|
|
|
$PAGE->set_button($buttons);
|
2009-05-06 09:24:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 02:11:54 +00:00
|
|
|
$PAGE->set_title($title);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
2010-03-08 16:01:38 +00:00
|
|
|
|
2009-09-07 02:11:54 +00:00
|
|
|
echo $OUTPUT->header();
|
2002-10-13 13:51:56 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Print quiz name and description
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(format_string($quiz->name));
|
2008-03-07 12:33:07 +00:00
|
|
|
if (trim(strip_tags($quiz->intro))) {
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box(format_module_intro('quiz', $quiz, $cm->id), 'generalbox', 'intro');
|
2008-03-07 12:33:07 +00:00
|
|
|
}
|
2002-10-06 03:23:34 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Display information about this quiz.
|
|
|
|
$messages = $accessmanager->describe_rules();
|
|
|
|
if ($quiz->attempts != 1) {
|
|
|
|
$messages[] = get_string('gradingmethod', 'quiz', quiz_get_grading_option_name($quiz->grademethod));
|
2004-08-23 12:35:13 +00:00
|
|
|
}
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_start('quizinfo');
|
2008-03-07 12:33:07 +00:00
|
|
|
$accessmanager->print_messages($messages);
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2002-10-06 03:23:34 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Show number of attempts summary to those who can view reports.
|
2006-08-25 16:03:54 +00:00
|
|
|
if (has_capability('mod/quiz:viewreports', $context)) {
|
2010-07-28 15:08:34 +00:00
|
|
|
if ($strattemptnum = quiz_attempt_summary_link_to_reports($quiz, $cm, $context)) {
|
|
|
|
echo '<div class="quizattemptcounts">' . $strattemptnum . "</div>\n";
|
2005-06-05 20:51:15 +00:00
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Guests can't do a quiz, so offer them a choice of logging in or going back.
|
2007-02-28 11:34:50 +00:00
|
|
|
if (isguestuser()) {
|
2009-08-20 08:45:47 +00:00
|
|
|
echo $OUTPUT->confirm('<p>' . get_string('guestsno', 'quiz') . "</p>\n\n<p>" .
|
2009-01-02 22:56:48 +00:00
|
|
|
get_string('liketologin') . "</p>\n", get_login_url(), get_referer(false));
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-07-09 07:35:03 +00:00
|
|
|
exit;
|
2006-08-22 13:53:39 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 07:08:02 +00:00
|
|
|
/// If they are not enrolled in this course in a good enough role, tell them to enrol.
|
|
|
|
if (!($canattempt || $canpreview || $canreviewmine)) {
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box('<p>' . get_string('youneedtoenrol', 'quiz') . "</p>\n\n<p>" .
|
2009-08-18 05:16:08 +00:00
|
|
|
$OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id) .
|
2008-03-07 12:33:07 +00:00
|
|
|
"</p>\n", 'generalbox', 'notice');
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-07-09 07:35:03 +00:00
|
|
|
exit;
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2002-10-15 12:54:11 +00:00
|
|
|
|
2010-03-08 16:01:38 +00:00
|
|
|
/// Update the quiz with overrides for the current user
|
|
|
|
$quiz = quiz_update_effective_access($quiz, $USER->id);
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Get this user's attempts.
|
2007-09-20 15:14:24 +00:00
|
|
|
$attempts = quiz_get_user_attempts($quiz->id, $USER->id);
|
2008-03-07 12:33:07 +00:00
|
|
|
$lastfinishedattempt = end($attempts);
|
2007-09-20 15:14:24 +00:00
|
|
|
$unfinished = false;
|
|
|
|
if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) {
|
|
|
|
$attempts[] = $unfinishedattempt;
|
|
|
|
$unfinished = true;
|
|
|
|
}
|
|
|
|
$numattempts = count($attempts);
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Work out the final grade, checking whether it was overridden in the gradebook.
|
2007-09-20 15:14:24 +00:00
|
|
|
$mygrade = quiz_get_best_grade($quiz, $USER->id);
|
2007-10-11 11:42:49 +00:00
|
|
|
$mygradeoverridden = false;
|
|
|
|
$gradebookfeedback = '';
|
|
|
|
|
|
|
|
$grading_info = grade_get_grades($course->id, 'mod', 'quiz', $quiz->id, $USER->id);
|
2007-10-23 07:48:03 +00:00
|
|
|
if (!empty($grading_info->items)) {
|
|
|
|
$item = $grading_info->items[0];
|
|
|
|
if (isset($item->grades[$USER->id])) {
|
|
|
|
$grade = $item->grades[$USER->id];
|
2008-01-13 08:30:39 +00:00
|
|
|
|
2007-10-23 07:48:03 +00:00
|
|
|
if ($grade->overridden) {
|
|
|
|
$mygrade = $grade->grade + 0; // Convert to number.
|
|
|
|
$mygradeoverridden = true;
|
|
|
|
}
|
|
|
|
if (!empty($grade->str_feedback)) {
|
|
|
|
$gradebookfeedback = $grade->str_feedback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Print table with existing attempts
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($attempts) {
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(get_string('summaryofattempts', 'quiz'));
|
2005-05-08 11:24:03 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
// Work out which columns we need, taking account what data is available in each attempt.
|
|
|
|
list($someoptions, $alloptions) = quiz_get_combined_reviewoptions($quiz, $attempts, $context);
|
|
|
|
|
2008-09-04 09:22:37 +00:00
|
|
|
$attemptcolumn = $quiz->attempts != 1;
|
|
|
|
|
2008-09-23 07:18:15 +00:00
|
|
|
$gradecolumn = $someoptions->scores && quiz_has_grades($quiz);
|
2007-09-20 15:14:24 +00:00
|
|
|
$markcolumn = $gradecolumn && ($quiz->grade != $quiz->sumgrades);
|
|
|
|
$overallstats = $alloptions->scores;
|
|
|
|
|
2008-09-23 07:18:15 +00:00
|
|
|
$feedbackcolumn = quiz_has_feedback($quiz) && $alloptions->overallfeedback;
|
2007-09-20 15:14:24 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
// Prepare table header
|
2009-08-20 08:45:47 +00:00
|
|
|
$table = new html_table();
|
2010-03-20 22:15:54 +00:00
|
|
|
$table->attributes['class'] = 'generaltable quizattemptsummary';
|
2008-09-04 09:22:37 +00:00
|
|
|
$table->head = array();
|
|
|
|
$table->align = array();
|
|
|
|
$table->size = array();
|
|
|
|
if ($attemptcolumn) {
|
2010-08-03 10:55:22 +00:00
|
|
|
$table->head[] = get_string('attemptnumber', 'quiz');
|
2008-09-04 09:22:37 +00:00
|
|
|
$table->align[] = 'center';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
2009-06-25 06:58:43 +00:00
|
|
|
$table->head[] = get_string('timecompleted', 'quiz');
|
2008-09-04 09:22:37 +00:00
|
|
|
$table->align[] = 'left';
|
|
|
|
$table->size[] = '';
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($markcolumn) {
|
2008-08-15 11:15:08 +00:00
|
|
|
$table->head[] = get_string('marks', 'quiz') . ' / ' . quiz_format_grade($quiz, $quiz->sumgrades);
|
2007-09-20 15:14:24 +00:00
|
|
|
$table->align[] = 'center';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
|
|
|
if ($gradecolumn) {
|
2008-08-15 11:15:08 +00:00
|
|
|
$table->head[] = get_string('grade') . ' / ' . quiz_format_grade($quiz, $quiz->grade);
|
2007-09-20 15:14:24 +00:00
|
|
|
$table->align[] = 'center';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
2009-01-14 07:08:02 +00:00
|
|
|
if ($canreviewmine) {
|
|
|
|
$table->head[] = get_string('review', 'quiz');
|
|
|
|
$table->align[] = 'center';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($feedbackcolumn) {
|
2008-05-15 15:32:43 +00:00
|
|
|
$table->head[] = get_string('feedback', 'quiz');
|
2007-09-20 15:14:24 +00:00
|
|
|
$table->align[] = 'left';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
|
|
|
if (isset($quiz->showtimetaken)) {
|
2008-05-15 15:32:43 +00:00
|
|
|
$table->head[] = get_string('timetaken', 'quiz');
|
2007-09-20 15:14:24 +00:00
|
|
|
$table->align[] = 'left';
|
|
|
|
$table->size[] = '';
|
|
|
|
}
|
2006-12-22 12:52:13 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
// One row for each attempt
|
|
|
|
foreach ($attempts as $attempt) {
|
|
|
|
$attemptoptions = quiz_get_reviewoptions($quiz, $attempt, $context);
|
|
|
|
$row = array();
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
// Add the attempt number, making it a link, if appropriate.
|
2008-09-04 09:22:37 +00:00
|
|
|
if ($attemptcolumn) {
|
|
|
|
if ($attempt->preview) {
|
|
|
|
$row[] = get_string('preview', 'quiz');
|
|
|
|
} else {
|
|
|
|
$row[] = $attempt->attempt;
|
|
|
|
}
|
2006-08-22 17:31:26 +00:00
|
|
|
}
|
2005-05-08 11:24:03 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
// 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);
|
2008-03-07 12:33:07 +00:00
|
|
|
} else if (!$quiz->timeclose || $timenow < $quiz->timeclose) {
|
2007-09-20 15:14:24 +00:00
|
|
|
// The attempt is still in progress.
|
2008-03-07 12:33:07 +00:00
|
|
|
$timetaken = format_time($timenow - $attempt->timestart);
|
2007-09-20 15:14:24 +00:00
|
|
|
$datecompleted = '';
|
2008-03-07 12:33:07 +00:00
|
|
|
} else {
|
2007-09-20 15:14:24 +00:00
|
|
|
$timetaken = format_time($quiz->timeclose - $attempt->timestart);
|
|
|
|
$datecompleted = userdate($quiz->timeclose);
|
|
|
|
}
|
|
|
|
$row[] = $datecompleted;
|
2006-08-22 17:31:26 +00:00
|
|
|
|
2010-08-04 19:02:45 +00:00
|
|
|
if ($markcolumn) {
|
|
|
|
if ($attemptoptions->scores && $attempt->timefinish > 0) {
|
2008-09-04 09:22:37 +00:00
|
|
|
$row[] = quiz_format_grade($quiz, $attempt->sumgrades);
|
2007-09-20 15:14:24 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '';
|
2006-04-18 22:54:10 +00:00
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
// Ouside the if because we may be showing feedback but not grades.
|
quiz settings: MDL-18485 Improve quiz settings form
* Reorder form fields to group things more logically.
** and on the corresponding admin page too.
* Set some options to be 'Advanced' by default:
** Apply penalties.
** Each attempt builds on the last.
** Decimal places for question grades.
** The five 'Extra restrictions on attempts' settings. (password, etc.)
* Admins can still change this to suit their institiution at Administration > Plugins > Activity modules > Quiz.
* These new defaults are applied if the admin had not previously set any fields to be advanced.
* Disable some filds when they are not applicable:
** Grading method, if num attempts = 1
** Penaly scheme, if adaptive mode = no
** Each attempt builds of last, if num attempts = 1
** Review after quiz closed options, if no close date.
** Delay between 1st and 2nd attempts, if num attempts = 1
** Delay between later attempts, if num attempts < 3
* Convert quiz.timelimit to be in seconds, for consistency, and ready for the new duration field type (MDL 18500).
** Including ensuring that backup and restore is backwards compatible.
* MDL-5537 New setting, questiondecimalpoints, so, for example, you can show the quiz grade as an integer, but have fractional question grades.
** There is a 'Same as overall decimal points' option, which is the default.
* Improve some field labels.
* Make corresponding changes in the help files.
2009-03-10 08:39:51 +00:00
|
|
|
$attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz, false);
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($gradecolumn) {
|
2007-11-27 19:18:36 +00:00
|
|
|
if ($attemptoptions->scores && $attempt->timefinish > 0) {
|
quiz settings: MDL-18485 Improve quiz settings form
* Reorder form fields to group things more logically.
** and on the corresponding admin page too.
* Set some options to be 'Advanced' by default:
** Apply penalties.
** Each attempt builds on the last.
** Decimal places for question grades.
** The five 'Extra restrictions on attempts' settings. (password, etc.)
* Admins can still change this to suit their institiution at Administration > Plugins > Activity modules > Quiz.
* These new defaults are applied if the admin had not previously set any fields to be advanced.
* Disable some filds when they are not applicable:
** Grading method, if num attempts = 1
** Penaly scheme, if adaptive mode = no
** Each attempt builds of last, if num attempts = 1
** Review after quiz closed options, if no close date.
** Delay between 1st and 2nd attempts, if num attempts = 1
** Delay between later attempts, if num attempts < 3
* Convert quiz.timelimit to be in seconds, for consistency, and ready for the new duration field type (MDL 18500).
** Including ensuring that backup and restore is backwards compatible.
* MDL-5537 New setting, questiondecimalpoints, so, for example, you can show the quiz grade as an integer, but have fractional question grades.
** There is a 'Same as overall decimal points' option, which is the default.
* Improve some field labels.
* Make corresponding changes in the help files.
2009-03-10 08:39:51 +00:00
|
|
|
$formattedgrade = quiz_format_grade($quiz, $attemptgrade);
|
2007-09-20 15:14:24 +00:00
|
|
|
// highlight the highest grade if appropriate
|
2008-03-07 12:33:07 +00:00
|
|
|
if ($overallstats && !$attempt->preview && $numattempts > 1 && !is_null($mygrade) &&
|
|
|
|
$attemptgrade == $mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) {
|
2009-07-15 05:37:31 +00:00
|
|
|
$table->rowclasses[$attempt->attempt] = 'bestrow';
|
2006-08-25 16:03:54 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 09:22:37 +00:00
|
|
|
$row[] = $formattedgrade;
|
2007-09-20 15:14:24 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '';
|
2006-08-25 16:03:54 +00:00
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2009-01-14 07:08:02 +00:00
|
|
|
if ($canreviewmine) {
|
|
|
|
$row[] = $accessmanager->make_review_link($attempt, $canpreview, $attemptoptions);
|
|
|
|
}
|
2008-09-04 09:22:37 +00:00
|
|
|
|
2007-11-27 19:18:36 +00:00
|
|
|
if ($feedbackcolumn && $attempt->timefinish > 0) {
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($attemptoptions->overallfeedback) {
|
2010-08-10 09:56:48 +00:00
|
|
|
$row[] = quiz_feedback_for_grade($attemptgrade, $quiz, $context, $cm);
|
2007-09-20 15:14:24 +00:00
|
|
|
} else {
|
|
|
|
$row[] = '';
|
2006-08-25 16:03:54 +00:00
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
if (isset($quiz->showtimetaken)) {
|
|
|
|
$row[] = $timetaken;
|
|
|
|
}
|
2002-10-06 03:23:34 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
if ($attempt->preview) {
|
|
|
|
$table->data['preview'] = $row;
|
|
|
|
} else {
|
|
|
|
$table->data[$attempt->attempt] = $row;
|
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
} // End of loop over attempts.
|
2010-03-20 22:15:54 +00:00
|
|
|
echo html_writer::table($table);
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Print information about the student's best score for this quiz if possible.
|
|
|
|
$moreattempts = $unfinished || !$accessmanager->is_finished($numattempts, $lastfinishedattempt);
|
2007-09-20 15:14:24 +00:00
|
|
|
if (!$moreattempts) {
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(get_string("nomoreattempts", "quiz"));
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2008-09-23 07:18:15 +00:00
|
|
|
if ($numattempts && $gradecolumn && !is_null($mygrade)) {
|
2007-10-11 11:42:49 +00:00
|
|
|
$resultinfo = '';
|
2008-01-13 08:30:39 +00:00
|
|
|
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($overallstats) {
|
2008-03-07 12:33:07 +00:00
|
|
|
if ($moreattempts) {
|
2007-09-20 15:14:24 +00:00
|
|
|
$a = new stdClass;
|
|
|
|
$a->method = quiz_get_grading_option_name($quiz->grademethod);
|
2008-08-29 11:02:02 +00:00
|
|
|
$a->mygrade = quiz_format_grade($quiz, $mygrade);
|
|
|
|
$a->quizgrade = quiz_format_grade($quiz, $quiz->grade);
|
2009-08-06 08:23:24 +00:00
|
|
|
$resultinfo .= $OUTPUT->heading(get_string('gradesofar', 'quiz', $a), 2, 'main');
|
2007-09-20 15:14:24 +00:00
|
|
|
} else {
|
2010-05-07 00:08:16 +00:00
|
|
|
$a = new stdClass;
|
|
|
|
$a->grade = quiz_format_grade($quiz, $mygrade);
|
|
|
|
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
|
|
|
|
$a = get_string('outofshort', 'quiz', $a);
|
2009-08-06 08:23:24 +00:00
|
|
|
$resultinfo .= $OUTPUT->heading(get_string('yourfinalgradeis', 'quiz', $a), 2, 'main');
|
2006-08-22 17:31:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-12 07:24:47 +00:00
|
|
|
if ($mygradeoverridden) {
|
|
|
|
$resultinfo .= '<p class="overriddennotice">'.get_string('overriddennotice', 'grades')."</p>\n";
|
|
|
|
}
|
2007-10-11 11:42:49 +00:00
|
|
|
if ($gradebookfeedback) {
|
2009-08-06 08:23:24 +00:00
|
|
|
$resultinfo .= $OUTPUT->heading(get_string('comment', 'quiz'), 3, 'main');
|
2008-03-07 12:33:07 +00:00
|
|
|
$resultinfo .= '<p class="quizteacherfeedback">'.$gradebookfeedback."</p>\n";
|
2007-10-11 11:42:49 +00:00
|
|
|
}
|
2008-09-04 09:27:19 +00:00
|
|
|
if ($feedbackcolumn) {
|
2009-08-06 08:23:24 +00:00
|
|
|
$resultinfo .= $OUTPUT->heading(get_string('overallfeedback', 'quiz'), 3, 'main');
|
2010-08-10 09:56:48 +00:00
|
|
|
$resultinfo .= '<p class="quizgradefeedback">'.quiz_feedback_for_grade($mygrade, $quiz, $context, $cm)."</p>\n";
|
2007-10-11 11:42:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($resultinfo) {
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box($resultinfo, 'generalbox', 'feedback');
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-22 12:52:13 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Determine if we should be showing a start/continue attempt button,
|
|
|
|
/// or a button to go back to the course page.
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_start('quizattempt');
|
2008-03-07 12:33:07 +00:00
|
|
|
$buttontext = ''; // This will be set something if as start/continue attempt button should appear.
|
2011-01-29 12:11:10 +00:00
|
|
|
if (!quiz_clean_layout($quiz->questions, true)) {
|
2009-08-06 08:23:24 +00:00
|
|
|
echo $OUTPUT->heading(get_string("noquestions", "quiz"));
|
2008-03-07 12:33:07 +00:00
|
|
|
} else {
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($unfinished) {
|
2010-08-11 16:57:34 +00:00
|
|
|
if ($canpreview) {
|
2009-01-14 07:08:02 +00:00
|
|
|
$buttontext = get_string('continuepreview', 'quiz');
|
2010-08-11 16:57:34 +00:00
|
|
|
} else if ($canattempt) {
|
|
|
|
$buttontext = get_string('continueattemptquiz', 'quiz');
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-08-11 16:57:34 +00:00
|
|
|
if ($canpreview) {
|
|
|
|
$buttontext = get_string('previewquiznow', 'quiz');
|
|
|
|
} else if ($canattempt) {
|
2009-01-14 07:08:02 +00:00
|
|
|
$messages = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
|
|
|
|
if ($messages) {
|
|
|
|
$accessmanager->print_messages($messages);
|
2008-03-07 12:33:07 +00:00
|
|
|
} else if ($numattempts == 0) {
|
|
|
|
$buttontext = get_string('attemptquiznow', 'quiz');
|
|
|
|
} else {
|
|
|
|
$buttontext = get_string('reattemptquiz', 'quiz');
|
2006-08-25 16:03:54 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-22 17:31:26 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
// If, so far, we think a button should be printed, so check if they will be allowed to access it.
|
2007-09-20 15:14:24 +00:00
|
|
|
if ($buttontext) {
|
2008-03-07 12:33:07 +00:00
|
|
|
if (!$moreattempts) {
|
|
|
|
$buttontext = '';
|
2009-01-14 07:08:02 +00:00
|
|
|
} else if ($canattempt && $messages = $accessmanager->prevent_access()) {
|
2008-03-07 12:33:07 +00:00
|
|
|
$accessmanager->print_messages($messages);
|
|
|
|
$buttontext = '';
|
2007-09-20 15:14:24 +00:00
|
|
|
}
|
2006-08-22 17:31:26 +00:00
|
|
|
}
|
2008-03-07 12:33:07 +00:00
|
|
|
}
|
2007-09-20 15:14:24 +00:00
|
|
|
|
2008-03-07 12:33:07 +00:00
|
|
|
/// Now actually print the appropriate button.
|
|
|
|
if ($buttontext) {
|
|
|
|
$accessmanager->print_start_attempt_button($canpreview, $buttontext, $unfinished);
|
2007-09-20 15:14:24 +00:00
|
|
|
} else {
|
2009-08-18 05:16:08 +00:00
|
|
|
echo $OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id);
|
2006-06-28 10:13:40 +00:00
|
|
|
}
|
2009-08-10 05:00:41 +00:00
|
|
|
echo $OUTPUT->box_end();
|
2002-10-04 02:59:05 +00:00
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
// Mark module as viewed (note, we do this here and not in finish_page,
|
2009-08-10 05:00:41 +00:00
|
|
|
// otherwise the 'not enrolled' error conditions would result in marking
|
2008-07-28 12:31:29 +00:00
|
|
|
// 'viewed', I think it's better if they don't.)
|
|
|
|
$completion=new completion_info($course);
|
2009-07-09 07:35:03 +00:00
|
|
|
$completion->set_module_viewed($cm);
|
2006-08-25 16:03:54 +00:00
|
|
|
|
2009-08-06 14:13:48 +00:00
|
|
|
echo $OUTPUT->footer();
|