From 39759ac468693f2b21c1c3bae2682ef3e5a421a0 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 12 May 2011 21:03:24 +0100 Subject: [PATCH] MDL-27408 fix a few minor bugs with the upgrade from 2.0. More testing, and adaptive mode, still to come. --- lib/moodlelib.php | 4 ++-- local/qeupgradehelper/README.txt | 9 +++++++++ mod/quiz/lang/en/quiz.php | 1 + mod/quiz/locallib.php | 1 + question/engine/upgrade/upgradelib.php | 13 ++++++++---- question/type/numerical/db/upgradelib.php | 24 ++++++++++++++++++++++- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ec24ac6061ef4..d8a087306600f 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -7067,7 +7067,8 @@ function get_plugin_types($fullpaths=true) { static $fullinfo = null; if (!$info) { - $info = array('mod' => 'mod', + $info = array('qtype' => 'question/type', + 'mod' => 'mod', 'auth' => 'auth', 'enrol' => 'enrol', 'message' => 'message/output', @@ -7087,7 +7088,6 @@ function get_plugin_types($fullpaths=true) { 'portfolio' => 'portfolio', 'qbehaviour' => 'question/behaviour', 'qformat' => 'question/format', - 'qtype' => 'question/type', 'plagiarism' => 'plagiarism', 'theme' => 'theme'); // this is a bit hacky, themes may be in $CFG->themedir too diff --git a/local/qeupgradehelper/README.txt b/local/qeupgradehelper/README.txt index 80e457917d935..ec4fd5e17f614 100755 --- a/local/qeupgradehelper/README.txt +++ b/local/qeupgradehelper/README.txt @@ -5,6 +5,15 @@ With a lot of question attempts, doing the whole conversion on upgrade is very slow. The plugin can help with that in various ways. +To install using git, type this command in the root of your Moodle install + git clone git://github.com/timhunt/moodle-local_qeupgradehelper.git local/qeupgradehelper +Then add /local/qeupgradehelper to your git ignore. + +Alternatively, download the zip from + https://github.com/timhunt/moodle-local_qeupgradehelper/zipball/master +unzip it into the local folder, and then rename the new folder to qeupgradehelper. + + When installed in a Moodle 2.0 site: 1. It provies a report of how much data there is to upgrade. diff --git a/mod/quiz/lang/en/quiz.php b/mod/quiz/lang/en/quiz.php index f260a85b16112..cbb92ee33e69f 100644 --- a/mod/quiz/lang/en/quiz.php +++ b/mod/quiz/lang/en/quiz.php @@ -96,6 +96,7 @@ $string['attemptsnumthisgroup'] = 'Attempts: {$a->total} ({$a->group} from this group)'; $string['attemptsnumyourgroups'] = 'Attempts: {$a->total} ({$a->group} from your groups)'; $string['attemptsonly'] = 'Show only students with attempts'; +$string['attemptstillinprogress'] = 'Attempt still in progress'; $string['attemptsunlimited'] = 'Unlimited attempts'; $string['back'] = 'Back to preview question'; $string['backtocourse'] = 'Back to the course'; diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 45b171318ec7e..72aca38087b7a 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -34,6 +34,7 @@ require_once($CFG->dirroot . '/mod/quiz/lib.php'); require_once($CFG->dirroot . '/mod/quiz/accessrules.php'); +require_once($CFG->dirroot . '/mod/quiz/renderer.php'); require_once($CFG->dirroot . '/mod/quiz/attemptlib.php'); require_once($CFG->dirroot . '/question/editlib.php'); require_once($CFG->libdir . '/eventslib.php'); diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index d840339791706..f472c546dfa48 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; +require_once($CFG->dirroot . '/question/engine/bank.php'); require_once($CFG->dirroot . '/question/engine/upgrade/logger.php'); require_once($CFG->dirroot . '/question/engine/upgrade/behaviourconverters.php'); @@ -282,9 +283,12 @@ public function load_question($questionid, $quizid = null) { } public function get_next_question_session($attempt, moodle_recordset $questionsessionsrs) { + if (!$questionsessionsrs->valid()) { + return false; + } + $qsession = $questionsessionsrs->current(); -print_object($qsession); // DONOTCOMMIT - if (!$qsession || $qsession->attemptid != $attempt->uniqueid) { + if ($qsession->attemptid != $attempt->uniqueid) { // No more question sessions belonging to this attempt. return false; } @@ -297,8 +301,9 @@ public function get_next_question_session($attempt, moodle_recordset $questionse public function get_question_states($attempt, $question, moodle_recordset $questionsstatesrs) { $qstates = array(); - while ($state = $questionsstatesrs->current()) { - if (!$state || $state->attempt != $attempt->uniqueid || + while ($questionsstatesrs->valid()) { + $state = $questionsstatesrs->current(); + if ($state->attempt != $attempt->uniqueid || $state->question != $question->id) { // We have found all the states for this attempt. Stop. break; diff --git a/question/type/numerical/db/upgradelib.php b/question/type/numerical/db/upgradelib.php index ef7ddcdb1160b..cfba998b1c883 100644 --- a/question/type/numerical/db/upgradelib.php +++ b/question/type/numerical/db/upgradelib.php @@ -68,8 +68,30 @@ public function supply_missing_first_step_data(&$data) { } public function set_data_elements_for_step($state, &$data) { - if (!empty($state->answer)) { + if (empty($state->answer)) { + return; + } + if (strpos($state->answer, '|||||') === false) { $data['answer'] = $state->answer; + } else { + list($answer, $unit) = explode('|||||', $state->answer, 2); + if ($this->question->options->showunits == 1) { + // Multichoice units. + $data['answer'] = $answer; + $data['unit'] = $unit; + } else if (!empty($this->question->options->unitsleft)) { + if (!empty($unit)) { + $data['answer'] = $unit . ' ' . $answer; + } else { + $data['answer'] = $answer; + } + } else { + if (!empty($unit)) { + $data['answer'] = $answer . ' ' . $unit; + } else { + $data['answer'] = $answer; + } + } } } }