Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-3054 record the current page of a quiz attempt

  • Loading branch information...
commit 5db829494030a73d15dabdc8be8685497888b138 1 parent 60e9909
@mackensen mackensen authored
View
5 mod/quiz/attempt.php
@@ -96,6 +96,11 @@
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
5 mod/quiz/attemptlib.php
@@ -601,6 +601,11 @@ public function get_attempt_number() {
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
5 mod/quiz/db/install.xml
@@ -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
12 mod/quiz/db/upgrade.php
@@ -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
10 mod/quiz/startattempt.php
@@ -33,7 +33,7 @@
// 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 @@
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 @@
$messages = $accessmanager->prevent_access() +
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
+
+ if ($page == -1) {
+ $page = 0;
+ }
}
// Check access.
View
2  mod/quiz/version.php
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.