MDL-3054 record the current page of a quiz attempt

This commit is contained in:
Charles Fulton 2012-01-08 14:14:09 -08:00
parent 60e99097e4
commit 5db8294940
6 changed files with 35 additions and 4 deletions

View File

@ -96,6 +96,11 @@ if (empty($slots)) {
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound');
}
// Update attempt page
if ($attemptobj->get_currentpage() != $page) {
$DB->set_field('quiz_attempts', 'currentpage', $page);
}
// Initialise the JavaScript.
$headtags = $attemptobj->get_html_head_contributions($page);
$PAGE->requires->js_init_call('M.mod_quiz.init_attempt_form', null, false, quiz_get_js_module());

View File

@ -601,6 +601,11 @@ class quiz_attempt {
public function get_userid() {
return $this->attempt->userid;
}
/** @return int the current page of the attempt. */
public function get_currentpage() {
return $this->attempt->currentpage;
}
/**
* @return bool whether this attempt has been finished (true) or is still

View File

@ -61,8 +61,9 @@
<FIELD NAME="timestart" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="sumgrades" NEXT="timefinish"/>
<FIELD NAME="timefinish" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timestart" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timefinish" NEXT="layout"/>
<FIELD NAME="layout" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="preview"/>
<FIELD NAME="preview" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="layout" NEXT="needsupgradetonewqe"/>
<FIELD NAME="layout" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="currentpage"/>
<FIELD NAME="currentpage" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="layout" NEXT="preview"/>
<FIELD NAME="preview" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="currentpage" NEXT="needsupgradetonewqe"/>
<FIELD NAME="needsupgradetonewqe" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="preview"/>
</FIELDS>
<KEYS>

View File

@ -69,6 +69,18 @@ function xmldb_quiz_upgrade($oldversion) {
// quiz savepoint reached
upgrade_mod_savepoint(true, 2011120701, 'quiz');
}
if ($oldversion < 2011120703) {
// Track page of quiz attempts
$table = new xmldb_table('quiz_attempts');
$field = new xmldb_field('currentpage', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_mod_savepoint(true, 2011120703, 'quiz');
}
return true;
}

View File

@ -33,7 +33,7 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
// Get submitted parameters.
$id = required_param('cmid', PARAM_INT); // Course module id
$forcenew = optional_param('forcenew', false, PARAM_BOOL); // Used to force a new preview
$page = optional_param('page', 0, PARAM_INT); // Page to jump to in the attempt.
$page = optional_param('page', -1, PARAM_INT); // Page to jump to in the attempt.
if (!$cm = get_coursemodule_from_id('quiz', $id)) {
print_error('invalidcoursemodule');
@ -82,6 +82,10 @@ $lastattempt = end($attempts);
if ($lastattempt && !$lastattempt->timefinish) {
$currentattemptid = $lastattempt->id;
$messages = $accessmanager->prevent_access();
if ($page == -1) {
$page = $lastattempt->currentpage;
}
} else {
// Get number for the next or unfinished attempt
@ -95,6 +99,10 @@ if ($lastattempt && !$lastattempt->timefinish) {
$messages = $accessmanager->prevent_access() +
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
if ($page == -1) {
$page = 0;
}
}
// Check access.

View File

@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2011120702; // The current module version (Date: YYYYMMDDXX)
$module->version = 2011120703; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2011112900; // Requires this Moodle version
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics)
$module->cron = 60;