2008-06-27 18:04:48 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This class handles loading all the information about a quiz attempt into memory,
|
|
|
|
* and making it available for attemtp.php, summary.php and review.php.
|
|
|
|
* Initially, it only loads a minimal amout of information about each attempt - loading
|
|
|
|
* extra information only when necessary or when asked. The class tracks which questions
|
|
|
|
* are loaded.
|
2008-06-30 16:56:49 +00:00
|
|
|
*//** */
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2008-07-08 18:22:18 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-30 16:56:49 +00:00
|
|
|
* Class for quiz exceptions. Just saves a couple of arguments on the
|
|
|
|
* constructor for a moodle_exception.
|
2008-06-27 18:04:48 +00:00
|
|
|
*/
|
|
|
|
class moodle_quiz_exception extends moodle_exception {
|
|
|
|
function __construct($quizobj, $errorcode, $a = NULL, $link = '', $debuginfo = null) {
|
|
|
|
if (!$link) {
|
|
|
|
$link = $quizobj->view_url();
|
|
|
|
}
|
|
|
|
parent::__construct($errorcode, 'quiz', $link, $a, $debuginfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* A base class for holding and accessing information about a quiz and its questions,
|
|
|
|
* before details of a particular attempt are loaded.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
class quiz {
|
|
|
|
// Fields initialised in the constructor.
|
|
|
|
protected $course;
|
|
|
|
protected $cm;
|
|
|
|
protected $quiz;
|
|
|
|
protected $context;
|
2008-07-08 16:33:47 +00:00
|
|
|
protected $questionids; // All question ids in order that they appear in the quiz.
|
|
|
|
protected $pagequestionids; // array page no => array of questionids on the page in order.
|
2008-08-29 07:29:35 +00:00
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
// Fields set later if that data is needed.
|
2008-07-08 16:33:47 +00:00
|
|
|
protected $questions = null;
|
2008-06-27 18:04:48 +00:00
|
|
|
protected $accessmanager = null;
|
2008-06-30 16:56:49 +00:00
|
|
|
protected $ispreviewuser = null;
|
2008-06-27 18:04:48 +00:00
|
|
|
|
|
|
|
// Constructor =========================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* Constructor, assuming we already have the necessary data loaded.
|
|
|
|
*
|
|
|
|
* @param object $quiz the row from the quiz table.
|
|
|
|
* @param object $cm the course_module object for this quiz.
|
|
|
|
* @param object $course the row from the course table for the course we belong to.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
function __construct($quiz, $cm, $course) {
|
|
|
|
$this->quiz = $quiz;
|
|
|
|
$this->cm = $cm;
|
|
|
|
$this->course = $course;
|
|
|
|
$this->context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->determine_layout();
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Functions for loading more data =====================================================
|
|
|
|
public function load_questions_on_page($page) {
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->load_questions($this->pagequestionids[$page]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preload_questions() {
|
|
|
|
if (empty($this->questionids)) {
|
|
|
|
throw new moodle_quiz_exception($this, 'noquestions', $this->edit_url());
|
|
|
|
}
|
|
|
|
$this->questions = question_preload_questions($this->questionids,
|
|
|
|
'qqi.grade AS maxgrade, qqi.id AS instance',
|
|
|
|
'{quiz_question_instances} qqi ON qqi.quiz = :quizid AND q.id = qqi.question',
|
|
|
|
array('quizid' => $this->quiz->id));
|
|
|
|
$this->number_questions();
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 06:37:43 +00:00
|
|
|
/**
|
2008-06-27 18:04:48 +00:00
|
|
|
* Load some or all of the queestions for this quiz.
|
|
|
|
*
|
2008-07-08 16:33:47 +00:00
|
|
|
* @param array $questionids question ids of the questions to load. null for all.
|
2008-06-27 18:04:48 +00:00
|
|
|
*/
|
2008-07-08 16:33:47 +00:00
|
|
|
public function load_questions($questionids = null) {
|
|
|
|
if (is_null($questionids)) {
|
|
|
|
$questionids = $this->questionids;
|
|
|
|
}
|
|
|
|
$questionstoprocess = array();
|
|
|
|
foreach ($questionids as $id) {
|
|
|
|
$questionstoprocess[$id] = $this->questions[$id];
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
2008-07-08 16:33:47 +00:00
|
|
|
if (!get_question_options($questionstoprocess)) {
|
|
|
|
throw new moodle_quiz_exception($this, 'loadingquestionsfailed', implode(', ', $questionids));
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple getters ======================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return integer the course id. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_courseid() {
|
|
|
|
return $this->course->id;
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/** @return object the row of the course table. */
|
|
|
|
public function get_course() {
|
|
|
|
return $this->course;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return integer the quiz id. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_quizid() {
|
|
|
|
return $this->quiz->id;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return object the row of the quiz table. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_quiz() {
|
|
|
|
return $this->quiz;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return string the name of this quiz. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_quiz_name() {
|
|
|
|
return $this->quiz->name;
|
|
|
|
}
|
|
|
|
|
2008-07-10 17:23:56 +00:00
|
|
|
/** @return integer the number of attempts allowed at this quiz (0 = infinite). */
|
|
|
|
public function get_num_attempts_allowed() {
|
|
|
|
return $this->quiz->attempts;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return integer the course_module id. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_cmid() {
|
|
|
|
return $this->cm->id;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return object the course_module object. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_cm() {
|
|
|
|
return $this->cm;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
2008-08-29 07:29:35 +00:00
|
|
|
* @return boolean wether the current user is someone who previews the quiz,
|
2008-06-30 16:56:49 +00:00
|
|
|
* rather than attempting it.
|
|
|
|
*/
|
|
|
|
public function is_preview_user() {
|
|
|
|
if (is_null($this->ispreviewuser)) {
|
|
|
|
$this->ispreviewuser = has_capability('mod/quiz:preview', $this->context);
|
|
|
|
}
|
|
|
|
return $this->ispreviewuser;
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/**
|
|
|
|
* @return integer number fo pages in this quiz.
|
|
|
|
*/
|
|
|
|
public function get_num_pages() {
|
|
|
|
return count($this->pagequestionids);
|
|
|
|
}
|
2008-08-29 07:29:35 +00:00
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $page page number
|
|
|
|
* @return boolean true if this is the last page of the quiz.
|
|
|
|
*/
|
|
|
|
public function is_last_page($page) {
|
|
|
|
return $page == count($this->pagequestionids) - 1;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @param integer $id the question id.
|
|
|
|
* @return object the question object with that id.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_question($id) {
|
|
|
|
return $this->questions[$id];
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/**
|
|
|
|
* @param array $questionids question ids of the questions to load. null for all.
|
|
|
|
*/
|
|
|
|
public function get_questions($questionids = null) {
|
|
|
|
if (is_null($questionids)) {
|
|
|
|
$questionids = $this->questionids;
|
|
|
|
}
|
|
|
|
$questions = array();
|
|
|
|
foreach ($questionids as $id) {
|
|
|
|
$questions[$id] = $this->questions[$id];
|
|
|
|
$this->ensure_question_loaded($id);
|
|
|
|
}
|
|
|
|
return $questions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-08-29 07:29:35 +00:00
|
|
|
* Return the list of question ids for either a given page of the quiz, or for the
|
2008-07-08 16:33:47 +00:00
|
|
|
* whole quiz.
|
|
|
|
*
|
|
|
|
* @param mixed $page string 'all' or integer page number.
|
|
|
|
* @return array the reqested list of question ids.
|
|
|
|
*/
|
|
|
|
public function get_question_ids($page = 'all') {
|
2008-07-10 17:31:12 +00:00
|
|
|
if ($page === 'all') {
|
2008-07-08 16:33:47 +00:00
|
|
|
$list = $this->questionids;
|
|
|
|
} else {
|
2008-07-10 17:34:18 +00:00
|
|
|
$list = $this->pagequestionids[$page];
|
2008-07-08 16:33:47 +00:00
|
|
|
}
|
|
|
|
// Clone the array, so our private arrays cannot be modified.
|
|
|
|
$result = array();
|
|
|
|
foreach ($list as $id) {
|
|
|
|
$result[] = $id;
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @param integer $timenow the current time as a unix timestamp.
|
|
|
|
* @return object and instance of the quiz_access_manager class for this quiz at this time.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_access_manager($timenow) {
|
|
|
|
if (is_null($this->accessmanager)) {
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->accessmanager = new quiz_access_manager($this, $timenow,
|
2008-06-27 18:04:48 +00:00
|
|
|
has_capability('mod/quiz:ignoretimelimits', $this->context, NULL, false));
|
|
|
|
}
|
|
|
|
return $this->accessmanager;
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/**
|
|
|
|
* Wrapper round the has_capability funciton that automatically passes in the quiz context.
|
|
|
|
*/
|
|
|
|
public function has_capability($capability, $userid = NULL, $doanything = true) {
|
|
|
|
return has_capability($capability, $this->context, $userid, $doanything);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper round the require_capability funciton that automatically passes in the quiz context.
|
|
|
|
*/
|
|
|
|
public function require_capability($capability, $userid = NULL, $doanything = true) {
|
|
|
|
return require_capability($capability, $this->context, $userid, $doanything);
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
// URLs related to this attempt ========================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @return string the URL of this quiz's view page.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function view_url() {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/view.php?id=' . $this->cm->id;
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/**
|
|
|
|
* @return string the URL of this quiz's edit page.
|
|
|
|
*/
|
|
|
|
public function edit_url() {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/edit.php?cmid=' . $this->cm->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param integer $attemptid the id of an attempt.
|
|
|
|
* @return string the URL of that attempt.
|
|
|
|
*/
|
|
|
|
public function attempt_url($attemptid) {
|
|
|
|
global $CFG;
|
2008-07-11 17:03:43 +00:00
|
|
|
return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $attemptid;
|
2008-07-08 16:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the URL of this quiz's edit page. Needs to be POSTed to with a cmid parameter.
|
|
|
|
*/
|
|
|
|
public function start_attempt_url() {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/startattempt.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param integer $attemptid the id of an attempt.
|
|
|
|
* @return string the URL of the review of that attempt.
|
|
|
|
*/
|
|
|
|
public function review_url($attemptid) {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $attemptid;
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
// Bits of content =====================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @return string the HTML snipped that needs to be supplied to print_header_simple
|
|
|
|
* as the $button parameter.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function update_module_button() {
|
|
|
|
if (has_capability('moodle/course:manageactivities',
|
|
|
|
get_context_instance(CONTEXT_COURSE, $this->course->id))) {
|
|
|
|
return update_module_button($this->cm->id, $this->course->id, get_string('modulename', 'quiz'));
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @param string $title the name of this particular quiz page.
|
|
|
|
* @return array the data that needs to be sent to print_header_simple as the $navigation
|
|
|
|
* parameter.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function navigation($title) {
|
|
|
|
return build_navigation($title, $this->cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Private methods =====================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
// Check that the definition of a particular question is loaded, and if not throw an exception.
|
2008-07-08 16:33:47 +00:00
|
|
|
protected function ensure_question_loaded($id) {
|
|
|
|
if (isset($this->questions[$id]->_partiallyloaded)) {
|
2008-06-27 18:04:48 +00:00
|
|
|
throw new moodle_quiz_exception($this, 'questionnotloaded', $id);
|
|
|
|
}
|
|
|
|
}
|
2008-07-08 16:33:47 +00:00
|
|
|
|
|
|
|
private function determine_layout() {
|
|
|
|
$this->questionids = array();
|
|
|
|
$this->pagequestionids = array();
|
|
|
|
|
|
|
|
// Get the appropriate layout string (from quiz or attempt).
|
|
|
|
$layout = $this->get_layout_string();
|
|
|
|
if (empty($layout)) {
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break up the layout string into pages.
|
|
|
|
$pagelayouts = explode(',0', $layout);
|
|
|
|
|
|
|
|
// Strip off any empty last page (normally there is one).
|
|
|
|
if (end($pagelayouts) == '') {
|
|
|
|
array_pop($pagelayouts);
|
|
|
|
}
|
|
|
|
|
|
|
|
// File the ids into the arrays.
|
|
|
|
$this->questionids = array();
|
|
|
|
$this->pagequestionids = array();
|
|
|
|
foreach ($pagelayouts as $page => $pagelayout) {
|
|
|
|
$pagelayout = trim($pagelayout, ',');
|
|
|
|
if ($pagelayout == '') continue;
|
|
|
|
$this->pagequestionids[$page] = explode(',', $pagelayout);
|
|
|
|
foreach ($this->pagequestionids[$page] as $id) {
|
|
|
|
$this->questionids[] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Number the questions.
|
|
|
|
private function number_questions() {
|
|
|
|
$number = 1;
|
|
|
|
foreach ($this->pagequestionids as $page => $questionids) {
|
|
|
|
foreach ($questionids as $id) {
|
|
|
|
if ($this->questions[$id]->length > 0) {
|
|
|
|
$this->questions[$id]->_number = $number;
|
|
|
|
$number += $this->questions[$id]->length;
|
|
|
|
} else {
|
|
|
|
$this->questions[$id]->_number = get_string('infoshort', 'quiz');
|
|
|
|
}
|
|
|
|
$this->questions[$id]->_page = $page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the layout of this quiz. Used by number_questions to
|
2008-08-29 07:29:35 +00:00
|
|
|
* work out which questions are on which pages.
|
2008-07-08 16:33:47 +00:00
|
|
|
*/
|
|
|
|
protected function get_layout_string() {
|
|
|
|
return $this->quiz->questions;
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* This class extends the quiz class to hold data about the state of a particular attempt,
|
|
|
|
* in addition to the data about the quiz.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
class quiz_attempt extends quiz {
|
|
|
|
// Fields initialised in the constructor.
|
|
|
|
protected $attempt;
|
|
|
|
|
|
|
|
// Fields set later if that data is needed.
|
|
|
|
protected $states = array();
|
2008-07-08 17:47:57 +00:00
|
|
|
protected $reviewoptions = null;
|
2008-06-27 18:04:48 +00:00
|
|
|
|
|
|
|
// Constructor =========================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* Constructor from just an attemptid.
|
|
|
|
*
|
|
|
|
* @param integer $attemptid the id of the attempt to load. We automatically load the
|
|
|
|
* associated quiz, course, etc.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
function __construct($attemptid) {
|
|
|
|
global $DB;
|
|
|
|
if (!$this->attempt = quiz_load_attempt($attemptid)) {
|
|
|
|
throw new moodle_exception('invalidattemptid', 'quiz');
|
|
|
|
}
|
|
|
|
if (!$quiz = $DB->get_record('quiz', array('id' => $this->attempt->quiz))) {
|
|
|
|
throw new moodle_exception('invalidquizid', 'quiz');
|
|
|
|
}
|
|
|
|
if (!$course = $DB->get_record('course', array('id' => $quiz->course))) {
|
|
|
|
throw new moodle_exception('invalidcoursemodule');
|
|
|
|
}
|
|
|
|
if (!$cm = get_coursemodule_from_instance('quiz', $quiz->id, $course->id)) {
|
|
|
|
throw new moodle_exception('invalidcoursemodule');
|
|
|
|
}
|
|
|
|
parent::__construct($quiz, $cm, $course);
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->preload_questions();
|
2008-09-04 06:37:43 +00:00
|
|
|
$this->preload_question_states();
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Functions for loading more data =====================================================
|
|
|
|
/**
|
2008-07-08 16:33:47 +00:00
|
|
|
* Load the state of a number of questions that have already been loaded.
|
2008-06-27 18:04:48 +00:00
|
|
|
*
|
2008-07-08 16:33:47 +00:00
|
|
|
* @param array $questionids question ids to process. Blank = all.
|
2008-06-27 18:04:48 +00:00
|
|
|
*/
|
2008-07-08 16:33:47 +00:00
|
|
|
public function load_question_states($questionids = null) {
|
|
|
|
if (is_null($questionids)) {
|
|
|
|
$questionids = $this->questionids;
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
2008-07-08 16:33:47 +00:00
|
|
|
$questionstoprocess = array();
|
|
|
|
foreach ($questionids as $id) {
|
|
|
|
$this->ensure_question_loaded($id);
|
|
|
|
$questionstoprocess[$id] = $this->questions[$id];
|
|
|
|
}
|
2008-09-04 07:05:14 +00:00
|
|
|
if (!question_load_states($questionstoprocess, $this->states,
|
2008-09-04 06:37:43 +00:00
|
|
|
$this->quiz, $this->attempt)) {
|
2008-06-27 18:04:48 +00:00
|
|
|
throw new moodle_quiz_exception($this, 'cannotrestore');
|
|
|
|
}
|
2008-09-04 06:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function preload_question_states() {
|
|
|
|
if (empty($this->questionids)) {
|
|
|
|
throw new moodle_quiz_exception($this, 'noquestions', $this->edit_url());
|
|
|
|
}
|
|
|
|
$this->states = question_preload_states($this->attempt->uniqueid);
|
|
|
|
if (!$this->states) {
|
|
|
|
$this->states = array();
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-07-15 15:30:39 +00:00
|
|
|
public function load_specific_question_state($questionid, $stateid) {
|
|
|
|
global $DB;
|
|
|
|
$state = question_load_specific_state($this->questions[$questionid],
|
|
|
|
$this->quiz, $this->attempt, $stateid);
|
|
|
|
if ($state === false) {
|
|
|
|
throw new moodle_quiz_exception($this, 'invalidstateid');
|
|
|
|
}
|
|
|
|
$this->states[$questionid] = $state;
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
// Simple getters ======================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return integer the attempt id. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_attemptid() {
|
|
|
|
return $this->attempt->id;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return object the row from the quiz_attempts table. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_attempt() {
|
|
|
|
return $this->attempt;
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
/** @return integer the number of this attemp (is it this user's first, second, ... attempt). */
|
|
|
|
public function get_attempt_number() {
|
|
|
|
return $this->attempt->attempt;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return integer the id of the user this attempt belongs to. */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_userid() {
|
|
|
|
return $this->attempt->userid;
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/** @return boolean whether this attemp has been finished (true) or is still in progress (false). */
|
2008-06-27 18:04:48 +00:00
|
|
|
public function is_finished() {
|
|
|
|
return $this->attempt->timefinish != 0;
|
|
|
|
}
|
|
|
|
|
2008-07-08 17:47:57 +00:00
|
|
|
/** @return boolean whether this attemp is a preview attempt. */
|
|
|
|
public function is_preview() {
|
|
|
|
return $this->attempt->preview;
|
|
|
|
}
|
|
|
|
|
2008-07-15 15:30:39 +00:00
|
|
|
/**
|
|
|
|
* Is this a student dealing with their own attempt/teacher previewing,
|
|
|
|
* or someone with 'mod/quiz:viewreports' reviewing someone elses attempt.
|
2008-08-29 07:29:35 +00:00
|
|
|
*
|
2008-07-15 15:30:39 +00:00
|
|
|
* @return boolean whether this situation should be treated as someone looking at their own
|
|
|
|
* attempt. The distinction normally only matters when an attempt is being reviewed.
|
|
|
|
*/
|
|
|
|
public function is_own_attempt() {
|
|
|
|
global $USER;
|
|
|
|
return $this->attempt->userid == $USER->id &&
|
|
|
|
(!$this->is_preview_user() || $this->attempt->preview);
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
public function get_question_state($questionid) {
|
|
|
|
$this->ensure_state_loaded($questionid);
|
|
|
|
return $this->states[$questionid];
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* Wrapper that calls quiz_get_reviewoptions with the appropriate arguments.
|
|
|
|
*
|
2008-07-08 17:47:57 +00:00
|
|
|
* @return object the review options for this user on this attempt.
|
2008-06-30 16:56:49 +00:00
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_review_options() {
|
|
|
|
if (is_null($this->reviewoptions)) {
|
|
|
|
$this->reviewoptions = quiz_get_reviewoptions($this->quiz, $this->attempt, $this->context);
|
|
|
|
}
|
|
|
|
return $this->reviewoptions;
|
|
|
|
}
|
|
|
|
|
2008-07-08 17:47:57 +00:00
|
|
|
/**
|
|
|
|
* 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) {
|
2008-08-29 10:08:27 +00:00
|
|
|
return quiz_get_renderoptions($this->quiz, $this->attempt, $this->context, $state);
|
2008-07-08 17:47:57 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param mixed $page as for the @see{get_question_ids} method.
|
|
|
|
* @return quiz_attempt_question_iterator the requested iterator.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_question_iterator($page = 'all') {
|
|
|
|
return new quiz_attempt_question_iterator($this, $page);
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* Return a summary of the current state of a question in this attempt. You must previously
|
|
|
|
* have called load_question_states to load the state data about this question.
|
|
|
|
*
|
|
|
|
* @param integer $questionid question id of a question that belongs to this quiz.
|
|
|
|
* @return string a brief string (that could be used as a CSS class name, for example)
|
|
|
|
* that describes the current state of a question in this attempt. Possible results are:
|
|
|
|
* open|saved|closed|correct|partiallycorrect|incorrect.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function get_question_status($questionid) {
|
2008-06-30 16:56:49 +00:00
|
|
|
$state = $this->states[$questionid];
|
|
|
|
switch ($state->event) {
|
|
|
|
case QUESTION_EVENTOPEN:
|
|
|
|
return 'open';
|
|
|
|
|
|
|
|
case QUESTION_EVENTSAVE:
|
|
|
|
case QUESTION_EVENTGRADE:
|
2008-07-08 18:22:18 +00:00
|
|
|
return 'answered';
|
2008-06-30 16:56:49 +00:00
|
|
|
|
|
|
|
case QUESTION_EVENTCLOSEANDGRADE:
|
|
|
|
case QUESTION_EVENTCLOSE:
|
|
|
|
case QUESTION_EVENTMANUALGRADE:
|
2008-08-29 10:08:27 +00:00
|
|
|
$options = $this->get_render_options($this->states[$questionid]);
|
2008-06-30 16:56:49 +00:00
|
|
|
if ($options->scores) {
|
|
|
|
return question_get_feedback_class($state->last_graded->raw_grade /
|
|
|
|
$this->questions[$questionid]->maxgrade);
|
|
|
|
} else {
|
|
|
|
return 'closed';
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
$a = new stdClass;
|
|
|
|
$a->event = $state->event;
|
|
|
|
$a->questionid = $questionid;
|
|
|
|
$a->attemptid = $this->attempt->id;
|
|
|
|
throw new moodle_quiz_exception($this, 'errorunexpectedevent', $a);
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-08-29 10:08:27 +00:00
|
|
|
/**
|
|
|
|
* @param integer $questionid question id of a question that belongs to this quiz.
|
|
|
|
* @return boolean whether this question hss been flagged by the attempter.
|
|
|
|
*/
|
|
|
|
public function is_question_flagged($questionid) {
|
|
|
|
$state = $this->states[$questionid];
|
|
|
|
return $state->flagged;
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
/**
|
2008-06-30 16:56:49 +00:00
|
|
|
* Return the grade obtained on a particular question, if the user is permitted to see it.
|
|
|
|
* You must previously have called load_question_states to load the state data about this question.
|
2008-06-27 18:04:48 +00:00
|
|
|
*
|
2008-06-30 16:56:49 +00:00
|
|
|
* @param integer $questionid question id of a question that belongs to this quiz.
|
2008-06-27 18:04:48 +00:00
|
|
|
* @return string the formatted grade, to the number of decimal places specified by the quiz.
|
|
|
|
*/
|
|
|
|
public function get_question_score($questionid) {
|
2008-08-29 10:18:11 +00:00
|
|
|
$options = $this->get_render_options($this->states[$questionid]);
|
2008-06-27 18:04:48 +00:00
|
|
|
if ($options->scores) {
|
2008-08-15 06:42:38 +00:00
|
|
|
return quiz_format_grade($this->quiz, $this->states[$questionid]->last_graded->grade);
|
2008-06-27 18:04:48 +00:00
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// URLs related to this attempt ========================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @param integer $page if specified, the URL of this particular page of the attempt, otherwise
|
|
|
|
* the URL will go to the first page.
|
2008-07-08 16:33:47 +00:00
|
|
|
* @param integer $questionid a question id. If set, will add a fragment to the URL
|
2008-06-30 16:56:49 +00:00
|
|
|
* to jump to a particuar question on the page.
|
|
|
|
* @return string the URL to continue this attempt.
|
|
|
|
*/
|
2008-07-08 16:33:47 +00:00
|
|
|
public function attempt_url($questionid = 0, $page = -1) {
|
2008-06-27 18:04:48 +00:00
|
|
|
global $CFG;
|
2008-07-11 17:03:43 +00:00
|
|
|
return $CFG->wwwroot . '/mod/quiz/attempt.php?attempt=' . $this->attempt->id .
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->page_and_question_fragment($questionid, $page);
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @return string the URL of this quiz's summary page.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function summary_url() {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/summary.php?attempt=' . $this->attempt->id;
|
|
|
|
}
|
|
|
|
|
2008-07-15 16:46:24 +00:00
|
|
|
/**
|
|
|
|
* @return string the URL of this quiz's summary page.
|
|
|
|
*/
|
|
|
|
public function processattempt_url() {
|
|
|
|
global $CFG;
|
|
|
|
return $CFG->wwwroot . '/mod/quiz/processattempt.php';
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* @param integer $page if specified, the URL of this particular page of the attempt, otherwise
|
|
|
|
* the URL will go to the first page.
|
2008-07-08 16:33:47 +00:00
|
|
|
* @param integer $questionid a question id. If set, will add a fragment to the URL
|
2008-06-30 16:56:49 +00:00
|
|
|
* to jump to a particuar question on the page.
|
|
|
|
* @param boolean $showall if true, the URL will be to review the entire attempt on one page,
|
|
|
|
* and $page will be ignored.
|
2008-07-10 17:23:56 +00:00
|
|
|
* @param $otherattemptid if given, link to another attempt, instead of the one we represent.
|
2008-06-30 16:56:49 +00:00
|
|
|
* @return string the URL to review this attempt.
|
|
|
|
*/
|
2008-07-15 15:30:39 +00:00
|
|
|
public function review_url($questionid = 0, $page = -1, $showall = false) {
|
2008-06-27 18:04:48 +00:00
|
|
|
global $CFG;
|
2008-07-15 15:30:39 +00:00
|
|
|
return $CFG->wwwroot . '/mod/quiz/review.php?attempt=' . $this->attempt->id .
|
2008-07-08 16:33:47 +00:00
|
|
|
$this->page_and_question_fragment($questionid, $page, $showall);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bits of content =====================================================================
|
|
|
|
public function get_html_head_contributions($page = 'all') {
|
|
|
|
return get_html_head_contributions($this->get_question_ids($page),
|
|
|
|
$this->questions, $this->states);
|
|
|
|
}
|
|
|
|
|
2008-08-28 02:15:19 +00:00
|
|
|
public function get_question_html_head_contributions($questionid) {
|
2008-08-29 11:04:32 +00:00
|
|
|
return get_html_head_contributions(array($questionid),
|
2008-08-28 02:15:19 +00:00
|
|
|
$this->questions, $this->states);
|
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
public function print_restart_preview_button() {
|
|
|
|
global $CFG;
|
|
|
|
echo '<div class="controls">';
|
|
|
|
print_single_button($this->start_attempt_url(), array('cmid' => $this->cm->id,
|
|
|
|
'forcenew' => true, 'sesskey' => sesskey()), get_string('startagain', 'quiz'), 'post');
|
|
|
|
echo '</div>';
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-07-08 16:33:47 +00:00
|
|
|
public function print_question($id) {
|
2008-07-08 17:47:57 +00:00
|
|
|
if ($this->is_finished()) {
|
|
|
|
$options = $this->get_review_options();
|
|
|
|
} else {
|
|
|
|
$options = $this->get_render_options($this->states[$id]);
|
|
|
|
}
|
2008-07-08 16:33:47 +00:00
|
|
|
print_question($this->questions[$id], $this->states[$id], $this->questions[$id]->_number,
|
|
|
|
$this->quiz, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function quiz_send_notification_emails() {
|
|
|
|
quiz_send_notification_emails($this->course, $this->quiz, $this->attempt,
|
|
|
|
$this->context, $this->cm);
|
|
|
|
}
|
2008-07-11 17:03:43 +00:00
|
|
|
|
|
|
|
public function print_navigation_panel($panelclass, $page) {
|
2008-07-14 15:40:24 +00:00
|
|
|
$panel = new $panelclass($this, $this->get_review_options(), $page);
|
2008-07-11 17:03:43 +00:00
|
|
|
$panel->display();
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
|
2008-08-15 06:42:38 +00:00
|
|
|
/// List of all this user's attempts for people who can see reports.
|
2008-07-15 15:30:39 +00:00
|
|
|
public function links_to_other_attempts($url) {
|
|
|
|
$search = '/\battempt=' . $this->attempt->id . '\b/';
|
|
|
|
$attempts = quiz_get_user_attempts($this->quiz->id, $this->attempt->userid, 'all');
|
2008-08-15 06:42:38 +00:00
|
|
|
if (count($attempts) <= 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-15 15:30:39 +00:00
|
|
|
$attemptlist = array();
|
|
|
|
foreach ($attempts as $at) {
|
|
|
|
if ($at->id == $this->attempt->id) {
|
|
|
|
$attemptlist[] = '<strong>' . $at->attempt . '</strong>';
|
|
|
|
} else {
|
|
|
|
$changedurl = preg_replace($search, 'attempt=' . $at->id, $url);
|
|
|
|
$attemptlist[] = '<a href="' . $changedurl . '">' . $at->attempt . '</a>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return implode(', ', $attemptlist);
|
|
|
|
}
|
|
|
|
|
2008-06-27 18:04:48 +00:00
|
|
|
// Private methods =====================================================================
|
2008-06-30 16:56:49 +00:00
|
|
|
// Check that the state of a particular question is loaded, and if not throw an exception.
|
2008-06-27 18:04:48 +00:00
|
|
|
private function ensure_state_loaded($id) {
|
2008-09-04 06:37:43 +00:00
|
|
|
if (!array_key_exists($id, $this->states) || isset($this->states[$id]->_partiallyloaded)) {
|
2008-06-27 18:04:48 +00:00
|
|
|
throw new moodle_quiz_exception($this, 'statenotloaded', $id);
|
|
|
|
}
|
|
|
|
}
|
2008-07-08 16:33:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the layout of this quiz. Used by number_questions to
|
2008-08-29 07:29:35 +00:00
|
|
|
* work out which questions are on which pages.
|
2008-07-08 16:33:47 +00:00
|
|
|
*/
|
|
|
|
protected function get_layout_string() {
|
|
|
|
return $this->attempt->layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $questionid the id of a particular question on the page to jump to.
|
|
|
|
* @param integer $page -1 to look up the page number from the questionid, otherwise the page number to use.
|
|
|
|
* @param boolean $showall
|
|
|
|
* @return string bit to add to the end of a URL.
|
|
|
|
*/
|
|
|
|
private function page_and_question_fragment($questionid, $page, $showall = false) {
|
2008-07-11 17:03:43 +00:00
|
|
|
if ($page == -1) {
|
2008-07-08 16:33:47 +00:00
|
|
|
if ($questionid) {
|
|
|
|
$page = $this->questions[$questionid]->_page;
|
|
|
|
} else {
|
|
|
|
$page = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($showall) {
|
|
|
|
$page = 0;
|
|
|
|
}
|
|
|
|
$fragment = '';
|
|
|
|
if ($questionid && $questionid != reset($this->pagequestionids[$page])) {
|
|
|
|
$fragment = '#q' . $questionid;
|
|
|
|
}
|
|
|
|
$param = '';
|
|
|
|
if ($showall) {
|
2008-08-15 06:42:38 +00:00
|
|
|
$param = '&showall=1';
|
2008-07-11 17:03:43 +00:00
|
|
|
} else if ($page > 0) {
|
2008-08-15 06:42:38 +00:00
|
|
|
$param = '&page=' . $page;
|
2008-07-08 16:33:47 +00:00
|
|
|
}
|
|
|
|
return $param . $fragment;
|
|
|
|
}
|
2008-06-27 18:04:48 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
/**
|
|
|
|
* A PHP Iterator for conviniently looping over the questions in a quiz. The keys are the question
|
|
|
|
* numbers (with 'i' for descriptions) and the values are the question objects.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
class quiz_attempt_question_iterator implements Iterator {
|
2008-06-30 16:56:49 +00:00
|
|
|
private $attemptobj; // Reference to the quiz_attempt object we provide access to.
|
|
|
|
private $questionids; // Array of the question ids within that attempt we are iterating over.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor. Normally, you don't want to call this directly. Instead call
|
|
|
|
* quiz_attempt::get_question_iterator
|
|
|
|
*
|
|
|
|
* @param quiz_attempt $attemptobj the quiz_attempt object we will be providing access to.
|
|
|
|
* @param mixed $page as for @see{quiz_attempt::get_question_iterator}.
|
|
|
|
*/
|
2008-06-27 18:04:48 +00:00
|
|
|
public function __construct(quiz_attempt $attemptobj, $page = 'all') {
|
|
|
|
$this->attemptobj = $attemptobj;
|
|
|
|
$this->questionids = $attemptobj->get_question_ids($page);
|
|
|
|
}
|
|
|
|
|
2008-06-30 16:56:49 +00:00
|
|
|
// Implementation of the Iterator interface ============================================
|
2008-06-27 18:04:48 +00:00
|
|
|
public function rewind() {
|
|
|
|
reset($this->questionids);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function current() {
|
|
|
|
$id = current($this->questionids);
|
|
|
|
if ($id) {
|
|
|
|
return $this->attemptobj->get_question($id);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function key() {
|
|
|
|
$id = current($this->questionids);
|
|
|
|
if ($id) {
|
2008-07-08 16:33:47 +00:00
|
|
|
return $this->attemptobj->get_question($id)->_number;
|
2008-06-27 18:04:48 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function next() {
|
|
|
|
$id = next($this->questionids);
|
|
|
|
if ($id) {
|
|
|
|
return $this->attemptobj->get_question($id);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function valid() {
|
|
|
|
return $this->current() !== false;
|
|
|
|
}
|
|
|
|
}
|
2008-07-11 17:03:43 +00:00
|
|
|
|
|
|
|
abstract class quiz_nav_panel_base {
|
|
|
|
protected $attemptobj;
|
|
|
|
protected $options;
|
|
|
|
protected $page;
|
|
|
|
|
|
|
|
protected function __construct(quiz_attempt $attemptobj, $options, $page) {
|
|
|
|
$this->attemptobj = $attemptobj;
|
|
|
|
$this->options = $options;
|
|
|
|
$this->page = $page;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_question_buttons() {
|
2008-09-03 02:35:56 +00:00
|
|
|
$html = '<div class="qn_buttons">' . "\n";
|
2008-07-11 17:03:43 +00:00
|
|
|
foreach ($this->attemptobj->get_question_iterator() as $number => $question) {
|
2008-09-03 02:35:56 +00:00
|
|
|
$html .= $this->get_question_button($number, $question) . "\n" .
|
|
|
|
$this->get_button_update_script($question) . "\n";
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
2008-09-03 02:35:56 +00:00
|
|
|
$html .= "</div>\n";
|
2008-07-11 17:03:43 +00:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2008-09-03 02:35:56 +00:00
|
|
|
protected function get_button_id($question) {
|
|
|
|
// The id to put on the button element in the HTML.
|
|
|
|
return 'quiznavbutton' . $question->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_button_update_script($question) {
|
|
|
|
return '<script type="text/javascript">' .
|
|
|
|
"\nquiz_init_nav_button('" . $this->get_button_id($question) . "', " .
|
|
|
|
$question->id . ")\n</script>\n";
|
|
|
|
}
|
|
|
|
|
2008-07-11 17:03:43 +00:00
|
|
|
abstract protected function get_question_button($number, $question);
|
|
|
|
|
|
|
|
abstract protected function get_end_bits();
|
|
|
|
|
2008-08-29 10:08:27 +00:00
|
|
|
protected function get_question_state_classes($question) {
|
|
|
|
// The current status of the question.
|
|
|
|
$classes = $this->attemptobj->get_question_status($question->id);
|
|
|
|
|
|
|
|
// Plus a marker for the current page.
|
2008-07-11 17:03:43 +00:00
|
|
|
if ($question->_page == $this->page) {
|
2008-08-29 10:08:27 +00:00
|
|
|
$classes .= ' thispage';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Plus a marker for flagged questions.
|
|
|
|
if ($this->attemptobj->is_question_flagged($question->id)) {
|
|
|
|
$classes .= ' flagged';
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
2008-08-29 10:08:27 +00:00
|
|
|
return $classes;
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function display() {
|
|
|
|
$strquiznavigation = get_string('quiznavigation', 'quiz');
|
2008-09-03 02:35:56 +00:00
|
|
|
$content = $this->get_question_buttons() . "\n" . '<div class="othernav">' .
|
|
|
|
"\n" . $this->get_end_bits() . "\n</div>\n";
|
2008-07-11 17:03:43 +00:00
|
|
|
print_side_block($strquiznavigation, $content, NULL, NULL, '', array('id' => 'quiznavigation'), $strquiznavigation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class quiz_attempt_nav_panel extends quiz_nav_panel_base {
|
|
|
|
public function __construct(quiz_attempt $attemptobj, $options, $page) {
|
|
|
|
parent::__construct($attemptobj, $options, $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_question_button($number, $question) {
|
|
|
|
$questionsonpage = $this->attemptobj->get_question_ids($question->_page);
|
|
|
|
$onclick = '';
|
|
|
|
if ($question->id != reset($questionsonpage)) {
|
|
|
|
$onclick = ' onclick="form.action = form.action + \'#q' . $question->id .
|
|
|
|
'\'; return true;"';
|
|
|
|
}
|
|
|
|
return '<input type="submit" name="gotopage' . $question->_page .
|
|
|
|
'" value="' . $number . '" class="qnbutton ' .
|
2008-09-03 02:35:56 +00:00
|
|
|
$this->get_question_state_classes($question) . '" id="' .
|
|
|
|
$this->get_button_id($question) . '" ' . $onclick . '/>';
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_end_bits() {
|
2008-07-22 11:37:01 +00:00
|
|
|
$output = '';
|
|
|
|
$output .= '<input type="submit" name="gotosummary" value="' .
|
2008-07-11 17:03:43 +00:00
|
|
|
get_string('endtest', 'quiz') . '" class="endtestlink" />';
|
2008-07-22 11:37:01 +00:00
|
|
|
$output .= '<div id="quiz-timer">' . get_string('timeleft', 'quiz') .
|
|
|
|
' <span id="quiz-time-left"></span></div>';
|
|
|
|
return $output;
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class quiz_review_nav_panel extends quiz_nav_panel_base {
|
|
|
|
public function __construct(quiz_attempt $attemptobj, $options, $page) {
|
|
|
|
parent::__construct($attemptobj, $options, $page);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_question_button($number, $question) {
|
|
|
|
return '<a href="' . $this->attemptobj->review_url($question->id) .
|
2008-09-03 02:35:56 +00:00
|
|
|
'" class="qnbutton ' . $this->get_question_state_classes($question) . '" id="' .
|
|
|
|
$this->get_button_id($question) . '">' . $number . '</a>';
|
2008-07-11 17:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function get_end_bits() {
|
2008-07-14 15:40:24 +00:00
|
|
|
$accessmanager = $this->attemptobj->get_access_manager(time());
|
2008-07-11 17:03:43 +00:00
|
|
|
$html = '<a href="' . $this->attemptobj->review_url(0, 0, true) . '">' .
|
|
|
|
get_string('showall', 'quiz') . '</a>';
|
2008-07-14 15:40:24 +00:00
|
|
|
$html .= $accessmanager->print_finish_review_link($this->attemptobj->is_preview_user(), true);
|
2008-07-11 17:03:43 +00:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|
2008-08-29 07:29:35 +00:00
|
|
|
?>
|