mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-3054 record the current page of a quiz attempt
This commit is contained in:
parent
60e99097e4
commit
5db8294940
6 changed files with 35 additions and 4 deletions
|
@ -96,6 +96,11 @@ if (empty($slots)) {
|
||||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound');
|
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.
|
// Initialise the JavaScript.
|
||||||
$headtags = $attemptobj->get_html_head_contributions($page);
|
$headtags = $attemptobj->get_html_head_contributions($page);
|
||||||
$PAGE->requires->js_init_call('M.mod_quiz.init_attempt_form', null, false, quiz_get_js_module());
|
$PAGE->requires->js_init_call('M.mod_quiz.init_attempt_form', null, false, quiz_get_js_module());
|
||||||
|
|
|
@ -602,6 +602,11 @@ class quiz_attempt {
|
||||||
return $this->attempt->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
|
* @return bool whether this attempt has been finished (true) or is still
|
||||||
* in progress (false).
|
* in progress (false).
|
||||||
|
|
|
@ -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="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="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="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="layout" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="currentpage"/>
|
||||||
<FIELD NAME="preview" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="layout" NEXT="needsupgradetonewqe"/>
|
<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"/>
|
<FIELD NAME="needsupgradetonewqe" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="preview"/>
|
||||||
</FIELDS>
|
</FIELDS>
|
||||||
<KEYS>
|
<KEYS>
|
||||||
|
|
|
@ -70,6 +70,18 @@ function xmldb_quiz_upgrade($oldversion) {
|
||||||
upgrade_mod_savepoint(true, 2011120701, 'quiz');
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||||
// Get submitted parameters.
|
// Get submitted parameters.
|
||||||
$id = required_param('cmid', PARAM_INT); // Course module id
|
$id = required_param('cmid', PARAM_INT); // Course module id
|
||||||
$forcenew = optional_param('forcenew', false, PARAM_BOOL); // Used to force a new preview
|
$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)) {
|
if (!$cm = get_coursemodule_from_id('quiz', $id)) {
|
||||||
print_error('invalidcoursemodule');
|
print_error('invalidcoursemodule');
|
||||||
|
@ -83,6 +83,10 @@ if ($lastattempt && !$lastattempt->timefinish) {
|
||||||
$currentattemptid = $lastattempt->id;
|
$currentattemptid = $lastattempt->id;
|
||||||
$messages = $accessmanager->prevent_access();
|
$messages = $accessmanager->prevent_access();
|
||||||
|
|
||||||
|
if ($page == -1) {
|
||||||
|
$page = $lastattempt->currentpage;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Get number for the next or unfinished attempt
|
// Get number for the next or unfinished attempt
|
||||||
if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
|
if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
|
||||||
|
@ -95,6 +99,10 @@ if ($lastattempt && !$lastattempt->timefinish) {
|
||||||
|
|
||||||
$messages = $accessmanager->prevent_access() +
|
$messages = $accessmanager->prevent_access() +
|
||||||
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
|
$accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
|
||||||
|
|
||||||
|
if ($page == -1) {
|
||||||
|
$page = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check access.
|
// Check access.
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die();
|
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->requires = 2011112900; // Requires this Moodle version
|
||||||
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics)
|
$module->component = 'mod_quiz'; // Full name of the plugin (used for diagnostics)
|
||||||
$module->cron = 60;
|
$module->cron = 60;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue