mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-15539 - Rework review.php to use attemptlib.php - the bulk of the conversion.
This commit is contained in:
parent
1aab356193
commit
4fc3d7e549
2 changed files with 78 additions and 103 deletions
|
@ -38,7 +38,6 @@ class quiz {
|
||||||
// Fields set later if that data is needed.
|
// Fields set later if that data is needed.
|
||||||
protected $questions = null;
|
protected $questions = null;
|
||||||
protected $accessmanager = null;
|
protected $accessmanager = null;
|
||||||
protected $reviewoptions = null;
|
|
||||||
protected $ispreviewuser = null;
|
protected $ispreviewuser = null;
|
||||||
|
|
||||||
// Constructor =========================================================================
|
// Constructor =========================================================================
|
||||||
|
@ -366,6 +365,7 @@ class quiz_attempt extends quiz {
|
||||||
|
|
||||||
// Fields set later if that data is needed.
|
// Fields set later if that data is needed.
|
||||||
protected $states = array();
|
protected $states = array();
|
||||||
|
protected $reviewoptions = null;
|
||||||
|
|
||||||
// Constructor =========================================================================
|
// Constructor =========================================================================
|
||||||
/**
|
/**
|
||||||
|
@ -439,6 +439,11 @@ class quiz_attempt extends quiz {
|
||||||
return $this->attempt->timefinish != 0;
|
return $this->attempt->timefinish != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return boolean whether this attemp is a preview attempt. */
|
||||||
|
public function is_preview() {
|
||||||
|
return $this->attempt->preview;
|
||||||
|
}
|
||||||
|
|
||||||
public function get_question_state($questionid) {
|
public function get_question_state($questionid) {
|
||||||
$this->ensure_state_loaded($questionid);
|
$this->ensure_state_loaded($questionid);
|
||||||
return $this->states[$questionid];
|
return $this->states[$questionid];
|
||||||
|
@ -447,7 +452,7 @@ class quiz_attempt extends quiz {
|
||||||
/**
|
/**
|
||||||
* Wrapper that calls quiz_get_reviewoptions with the appropriate arguments.
|
* Wrapper that calls quiz_get_reviewoptions with the appropriate arguments.
|
||||||
*
|
*
|
||||||
* @return object the review optoins for this user on this attempt.
|
* @return object the review options for this user on this attempt.
|
||||||
*/
|
*/
|
||||||
public function get_review_options() {
|
public function get_review_options() {
|
||||||
if (is_null($this->reviewoptions)) {
|
if (is_null($this->reviewoptions)) {
|
||||||
|
@ -456,6 +461,15 @@ class quiz_attempt extends quiz {
|
||||||
return $this->reviewoptions;
|
return $this->reviewoptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper that calls get_render_options with the appropriate arguments.
|
||||||
|
*
|
||||||
|
* @return object the render options for this user on this attempt.
|
||||||
|
*/
|
||||||
|
public function get_render_options($state) {
|
||||||
|
return quiz_get_renderoptions($this->quiz->review, $state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a quiz_attempt_question_iterator for either a page of the quiz, or a whole quiz.
|
* Get a quiz_attempt_question_iterator for either a page of the quiz, or a whole quiz.
|
||||||
* You must have called load_questions with an appropriate argument first.
|
* You must have called load_questions with an appropriate argument first.
|
||||||
|
@ -555,9 +569,12 @@ class quiz_attempt extends quiz {
|
||||||
* and $page will be ignored.
|
* and $page will be ignored.
|
||||||
* @return string the URL to review this attempt.
|
* @return string the URL to review this attempt.
|
||||||
*/
|
*/
|
||||||
public function review_url($questionid = 0, $page = -1, $showall = false) {
|
public function review_url($questionid = 0, $page = -1, $showall = false, $otherattemptid = null) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $this->attempt->id . '&' .
|
if (is_null($otherattemptid)) {
|
||||||
|
$otherattemptid = $this->attempt->id;
|
||||||
|
}
|
||||||
|
return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $otherattemptid . '&' .
|
||||||
$this->page_and_question_fragment($questionid, $page, $showall);
|
$this->page_and_question_fragment($questionid, $page, $showall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,7 +593,11 @@ class quiz_attempt extends quiz {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function print_question($id) {
|
public function print_question($id) {
|
||||||
$options = quiz_get_renderoptions($this->quiz->review, $this->states[$id]);
|
if ($this->is_finished()) {
|
||||||
|
$options = $this->get_review_options();
|
||||||
|
} else {
|
||||||
|
$options = $this->get_render_options($this->states[$id]);
|
||||||
|
}
|
||||||
print_question($this->questions[$id], $this->states[$id], $this->questions[$id]->_number,
|
print_question($this->questions[$id], $this->states[$id], $this->questions[$id]->_number,
|
||||||
$this->quiz, $options);
|
$this->quiz, $options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,55 +2,38 @@
|
||||||
/**
|
/**
|
||||||
* This page prints a review of a particular quiz attempt
|
* This page prints a review of a particular quiz attempt
|
||||||
*
|
*
|
||||||
* @author Martin Dougiamas and many others. This has recently been completely
|
* @author Martin Dougiamas and many others.
|
||||||
* rewritten by Alex Smith, Julian Sedding and Gustav Delius as part of
|
|
||||||
* the Serving Mathematics project
|
|
||||||
* {@link http://maths.york.ac.uk/serving_maths}
|
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
||||||
* @package quiz
|
* @package quiz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('../../config.php');
|
require_once(dirname(__FILE__) . '/../../config.php');
|
||||||
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||||
|
|
||||||
$attemptid = required_param('attempt', PARAM_INT); // A particular attempt ID for review
|
$attemptid = required_param('attempt', PARAM_INT);
|
||||||
$page = optional_param('page', 0, PARAM_INT); // The required page
|
$page = optional_param('page', 0, PARAM_INT);
|
||||||
$showall = optional_param('showall', 0, PARAM_BOOL);
|
$showall = optional_param('showall', 0, PARAM_BOOL);
|
||||||
|
|
||||||
if (!$attempt = quiz_load_attempt($attemptid)) {
|
$attemptobj = new quiz_attempt($attemptid);
|
||||||
print_error('invalidattemptid', 'quiz');
|
|
||||||
}
|
/// Check login.
|
||||||
if (! $quiz = $DB->get_record('quiz', array('id' => $attempt->quiz))) {
|
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
|
||||||
print_error('invalidquizid', 'quiz');
|
|
||||||
}
|
|
||||||
if (! $course = $DB->get_record('course', array('id' => $quiz->course))) {
|
|
||||||
print_error("invalidcoursemodule");
|
|
||||||
}
|
|
||||||
if (! $cm = get_coursemodule_from_instance("quiz", $quiz->id, $course->id)) {
|
|
||||||
print_error("invalidcoursemodule");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check login and get contexts.
|
|
||||||
require_login($course->id, false, $cm);
|
|
||||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $cm->course);
|
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
||||||
$canpreview = has_capability('mod/quiz:preview', get_context_instance(CONTEXT_MODULE, $cm->id));
|
|
||||||
|
|
||||||
/// Create an object to manage all the other (non-roles) access rules.
|
/// Create an object to manage all the other (non-roles) access rules.
|
||||||
$timenow = time();
|
$accessmanager = $attemptobj->get_access_manager(time());
|
||||||
$accessmanager = new quiz_access_manager(new quiz($quiz, $cm, $course), $timenow,
|
$options = $attemptobj->get_review_options();
|
||||||
has_capability('mod/quiz:ignoretimelimits', $context, NULL, false));
|
|
||||||
$options = quiz_get_reviewoptions($quiz, $attempt, $context);
|
|
||||||
|
|
||||||
/// Work out if this is a student viewing their own attempt/teacher previewing,
|
/// Work out if this is a student viewing their own attempt/teacher previewing,
|
||||||
/// or someone with 'mod/quiz:viewreports' reviewing someone elses attempt.
|
/// or someone with 'mod/quiz:viewreports' reviewing someone elses attempt.
|
||||||
$reviewofownattempt = $attempt->userid == $USER->id && (!$canpreview || $attempt->preview);
|
$reviewofownattempt = $attemptobj->get_userid() == $USER->id &&
|
||||||
|
(!$attemptobj->is_preview_user() || $attemptobj->is_preview());
|
||||||
|
|
||||||
/// Permissions checks for normal users who do not have quiz:viewreports capability.
|
/// Permissions checks for normal users who do not have quiz:viewreports capability.
|
||||||
if (!has_capability('mod/quiz:viewreports', $context)) {
|
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
|
||||||
/// Can't review during the attempt - send them back to the attempt page.
|
/// Can't review during the attempt - send them back to the attempt page.
|
||||||
if (!$attempt->timefinish) {
|
if (!$attemptobj->is_finished()) {
|
||||||
redirect($CFG->wwwroot . '/mod/quiz/attempt.php?q=' . $quiz->id);
|
redirect($attemptobj->attempt_url(0, $page));
|
||||||
}
|
}
|
||||||
/// Can't review other users' attempts.
|
/// Can't review other users' attempts.
|
||||||
if (!$reviewofownattempt) {
|
if (!$reviewofownattempt) {
|
||||||
|
@ -58,55 +41,43 @@
|
||||||
}
|
}
|
||||||
/// Can't review unless Students may review -> Responses option is turned on.
|
/// Can't review unless Students may review -> Responses option is turned on.
|
||||||
if (!$options->responses) {
|
if (!$options->responses) {
|
||||||
$accessmanager->back_to_view_page($canpreview,
|
$accessmanager->back_to_view_page($attemptobj->is_preview_user(),
|
||||||
$accessmanager->cannot_review_message($options));
|
$accessmanager->cannot_review_message($options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Log this review.
|
/// Log this review.
|
||||||
add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&attempt=$attempt->id", "$quiz->id", "$cm->id");
|
add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'review.php?attempt=' .
|
||||||
|
$attemptobj->get_attemptid(), $attemptobj->get_quizid(), $attemptobj->get_cmid());
|
||||||
|
|
||||||
/// load the questions needed by page
|
/// load the questions and states needed by this page.
|
||||||
if ($showall) {
|
if ($showall) {
|
||||||
$questionlist = quiz_questions_in_quiz($attempt->layout);
|
$questionids = $attemptobj->get_question_ids();
|
||||||
} else {
|
} else {
|
||||||
$questionlist = quiz_questions_on_page($attempt->layout, $page);
|
$questionids = $attemptobj->get_question_ids($page);
|
||||||
}
|
}
|
||||||
$pagequestions = explode(',', $questionlist);
|
$attemptobj->load_questions($questionids);
|
||||||
$questions = question_load_questions($questionlist, 'qqi.grade AS maxgrade, qqi.id AS instance',
|
$attemptobj->load_question_states($questionids);
|
||||||
'{quiz_question_instances} qqi ON qqi.quiz = ' . $quiz->id . ' AND q.id = qqi.question');
|
|
||||||
if (is_string($questions)) {
|
|
||||||
quiz_error($quiz, 'loadingquestionsfailed', $questions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Restore the question sessions to their most recent states creating new sessions where required.
|
|
||||||
if (!$states = get_question_states($questions, $quiz, $attempt)) {
|
|
||||||
print_error('cannotrestore', 'quiz');
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Work out appropriate title.
|
/// Work out appropriate title.
|
||||||
if ($canpreview && $reviewofownattempt) {
|
if ($attemptobj->is_preview_user() && $reviewofownattempt) {
|
||||||
$strreviewtitle = get_string('reviewofpreview', 'quiz');
|
$strreviewtitle = get_string('reviewofpreview', 'quiz');
|
||||||
} else {
|
} else {
|
||||||
$strreviewtitle = get_string('reviewofattempt', 'quiz', $attempt->attempt);
|
$strreviewtitle = get_string('reviewofattempt', 'quiz', $attempt->attempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Print the page header
|
/// Print the page header
|
||||||
$headtags = get_html_head_contributions($pagequestions, $questions, $states);
|
$headtags = $attemptobj->get_html_head_contributions($page);
|
||||||
if ($accessmanager->securewindow_required($canpreview)) {
|
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
|
||||||
$accessmanager->setup_secure_page($course->shortname.': '.format_string($quiz->name), $headtags);
|
$accessmanager->setup_secure_page($course->shortname.': '.format_string($quiz->name), $headtags);
|
||||||
} else {
|
} else {
|
||||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
print_header_simple(format_string($attemptobj->get_quiz_name()), '', $attemptobj->navigation($strreviewtitle),
|
||||||
? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz'))
|
'', $headtags, true, $attemptobj->update_module_button());
|
||||||
: "";
|
|
||||||
get_string('reviewofattempt', 'quiz', $attempt->attempt);
|
|
||||||
$navigation = build_navigation($strreviewtitle, $cm);
|
|
||||||
print_header_simple(format_string($quiz->name), "", $navigation, "", $headtags, true, $strupdatemodule);
|
|
||||||
}
|
}
|
||||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
||||||
|
|
||||||
/// Print tabs if they should be there.
|
/// Print tabs if they should be there.
|
||||||
if ($canpreview) {
|
if ($attemptobj->is_preview_user()) {
|
||||||
if ($reviewofownattempt) {
|
if ($reviewofownattempt) {
|
||||||
$currenttab = 'preview';
|
$currenttab = 'preview';
|
||||||
} else {
|
} else {
|
||||||
|
@ -118,19 +89,22 @@
|
||||||
|
|
||||||
/// Print heading.
|
/// Print heading.
|
||||||
print_heading(format_string($quiz->name));
|
print_heading(format_string($quiz->name));
|
||||||
if ($canpreview && $reviewofownattempt) {
|
if ($attemptobj->is_preview_user() && $reviewofownattempt) {
|
||||||
$attemptobj = new quiz_attempt($attemptid);
|
|
||||||
$attemptobj->print_restart_preview_button();
|
$attemptobj->print_restart_preview_button();
|
||||||
}
|
}
|
||||||
print_heading($strreviewtitle);
|
print_heading($strreviewtitle);
|
||||||
|
|
||||||
/// Finish review link.
|
/// Finish review link.
|
||||||
if ($reviewofownattempt) {
|
if ($reviewofownattempt) {
|
||||||
$accessmanager->print_finish_review_link($canpreview);
|
$accessmanager->print_finish_review_link($attemptobj->is_preview_user());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Summary table start ============================================================================
|
||||||
|
|
||||||
/// Work out some time-related things.
|
/// Work out some time-related things.
|
||||||
$timelimit = (int)$quiz->timelimit * 60;
|
$attempt = $attemptobj->get_attempt();
|
||||||
|
$quiz = $attemptobj->get_quiz();
|
||||||
|
$timelimit = $quiz->timelimit * 60;
|
||||||
$overtime = 0;
|
$overtime = 0;
|
||||||
|
|
||||||
if ($attempt->timefinish) {
|
if ($attempt->timefinish) {
|
||||||
|
@ -161,18 +135,13 @@
|
||||||
if (has_capability('mod/quiz:viewreports', $context) &&
|
if (has_capability('mod/quiz:viewreports', $context) &&
|
||||||
count($attempts = $DB->get_records_select('quiz_attempts', "quiz = ? AND userid = ?", array($quiz->id, $attempt->userid), 'attempt ASC')) > 1) {
|
count($attempts = $DB->get_records_select('quiz_attempts', "quiz = ? AND userid = ?", array($quiz->id, $attempt->userid), 'attempt ASC')) > 1) {
|
||||||
/// List of all this user's attempts for people who can see reports.
|
/// List of all this user's attempts for people who can see reports.
|
||||||
$urloptions = '';
|
|
||||||
if ($showall) {
|
|
||||||
$urloptions .= '&showall=true';
|
|
||||||
} else if ($page > 0) {
|
|
||||||
$urloptions .= '&page=' . $page;
|
|
||||||
}
|
|
||||||
$attemptlist = array();
|
$attemptlist = array();
|
||||||
foreach ($attempts as $at) {
|
foreach ($attempts as $at) {
|
||||||
if ($at->id == $attempt->id) {
|
if ($at->id == $attempt->id) {
|
||||||
$attemptlist[] = '<strong>' . $at->attempt . '</strong>';
|
$attemptlist[] = '<strong>' . $at->attempt . '</strong>';
|
||||||
} else {
|
} else {
|
||||||
$attemptlist[] = '<a href="review.php?attempt=' . $at->id . $urloptions . ' ">' . $at->attempt . '</a>';
|
$attemptlist[] = '<a href="' . $attemptobj->review_url(0, $page, $showall, $at->id) .
|
||||||
|
'">' . $at->attempt . '</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
|
$rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') .
|
||||||
|
@ -234,44 +203,29 @@
|
||||||
echo "\n</tbody></table>\n";
|
echo "\n</tbody></table>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Summary table end ==============================================================================
|
||||||
|
|
||||||
/// Print the navigation panel if required
|
/// Print the navigation panel if required
|
||||||
$numpages = quiz_number_of_pages($attempt->layout);
|
// TODO!!!
|
||||||
if ($numpages > 1 and !$showall) {
|
print_paging_bar($attemptobj->get_num_pages(), $page, 1, 'review.php?attempt='.$attempt->id.'&');
|
||||||
print_paging_bar($numpages, $page, 1, 'review.php?attempt='.$attempt->id.'&');
|
echo '<div class="controls"><a href="review.php?attempt='.$attempt->id.'&showall=true">';
|
||||||
echo '<div class="controls"><a href="review.php?attempt='.$attempt->id.'&showall=true">';
|
print_string('showall', 'quiz');
|
||||||
print_string('showall', 'quiz');
|
echo '</a></div>';
|
||||||
echo '</a></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Print all the questions
|
/// Print all the questions
|
||||||
$number = quiz_first_questionnumber($attempt->layout, $questionlist);
|
if ($showall) {
|
||||||
foreach ($pagequestions as $i) {
|
$page = 'all';
|
||||||
if (!isset($questions[$i])) {
|
|
||||||
print_simple_box_start('center', '90%');
|
|
||||||
echo '<strong><font size="+1">' . $number . '</font></strong><br />';
|
|
||||||
notify(get_string('errormissingquestion', 'quiz', $i));
|
|
||||||
print_simple_box_end();
|
|
||||||
$number++; // Just guessing that the missing question would have lenght 1
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$options->validation = QUESTION_EVENTVALIDATE === $states[$i]->event;
|
|
||||||
$options->history = ($canpreview and !$attempt->preview) ? 'all' : 'graded';
|
|
||||||
// Print the question
|
|
||||||
print_question($questions[$i], $states[$i], $number, $quiz, $options);
|
|
||||||
$number += $questions[$i]->length;
|
|
||||||
}
|
}
|
||||||
|
foreach ($attemptobj->get_question_ids($page) as $id) {
|
||||||
// Print the navigation panel if required
|
$attemptobj->print_question($id);
|
||||||
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
|
// print javascript button to close the window, if necessary
|
||||||
if ($reviewofownattempt) {
|
if ($reviewofownattempt) {
|
||||||
$accessmanager->print_finish_review_link($canpreview);
|
$accessmanager->print_finish_review_link($attemptobj->is_preview_user());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($accessmanager->securewindow_required($canpreview)) {
|
if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
|
||||||
print_footer('empty');
|
print_footer('empty');
|
||||||
} else {
|
} else {
|
||||||
print_footer($course);
|
print_footer($course);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue