MDL-67830 quiz: notice in grade details redirect script

This commit is contained in:
Tim Hunt 2020-01-29 18:34:39 +00:00
parent 4e41ace0be
commit a33e0b4d84
2 changed files with 25 additions and 15 deletions

View File

@ -576,25 +576,12 @@ class quiz_attempt {
* of the state of each question. Else just set up the basic details of the attempt.
*/
public function __construct($attempt, $quiz, $cm, $course, $loadquestions = true) {
global $DB;
$this->attempt = $attempt;
$this->quizobj = new quiz($quiz, $cm, $course);
if (!$loadquestions) {
return;
if ($loadquestions) {
$this->load_questions();
}
$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->slots = $DB->get_records('quiz_slots',
array('quizid' => $this->get_quizid()), 'slot',
'slot, id, requireprevious, questionid, includingsubcategories');
$this->sections = array_values($DB->get_records('quiz_sections',
array('quizid' => $this->get_quizid()), 'firstslot'));
$this->link_sections_and_slots();
$this->determine_layout();
$this->number_questions();
}
/**
@ -643,6 +630,28 @@ class quiz_attempt {
return quiz_attempt_state_name($state);
}
/**
* This method can be called later if the object was constructed with $loadqusetions = false.
*/
public function load_questions() {
global $DB;
if (isset($this->quba)) {
throw new coding_exception('This quiz attempt has already had the questions loaded.');
}
$this->quba = question_engine::load_questions_usage_by_activity($this->attempt->uniqueid);
$this->slots = $DB->get_records('quiz_slots',
array('quizid' => $this->get_quizid()), 'slot',
'slot, id, requireprevious, questionid, includingsubcategories');
$this->sections = array_values($DB->get_records('quiz_sections',
array('quizid' => $this->get_quizid()), 'firstslot'));
$this->link_sections_and_slots();
$this->determine_layout();
$this->number_questions();
}
/**
* Let each slot know which section it is part of.
*/

View File

@ -81,6 +81,7 @@ if ($userid) {
if ($attempt) {
$attemptobj = new quiz_attempt($attempt, $quiz, $cm, $course, false);
if ($attemptobj->is_review_allowed()) {
$attemptobj->load_questions();
redirect($attemptobj->review_url());
}
}