From 96bee2b33467a1ce54f88c77b8a867ef1f7a9a97 Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Sun, 9 Sep 2012 16:54:35 +0200 Subject: First version of algebra question type initially written by Roger Moore for Moodle 2.3 --- db/install.xml | 47 ++++++++++++++++++++++++++++++++++++ db/upgrade.php | 59 +++++++++++++++++++++++++++++++++++++++++++++ db/upgradelib.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 db/install.xml create mode 100644 db/upgrade.php create mode 100644 db/upgradelib.php (limited to 'db') diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000..51b8d85 --- /dev/null +++ b/db/install.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+
+
diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..371150b --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,59 @@ +get_manager(); + +/// And upgrade begins here. For each one, you'll need one +/// block of code similar to the next one. Please, delete +/// this comment lines once this file start handling proper +/// upgrade code. + + // Add the field to store the string which is placed in front of the answer + // box when the question is displayed + if ($oldversion < 2008061500) { + $table = new xmldb_table('question_algebra'); + $field = new xmldb_field('answerprefix', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, '', 'allowedfuncs'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_plugin_savepoint(true, 2008061500, 'qtype', 'algebra'); + } + + // Drop the answers and variables fields wich are totaly redundants + if ($oldversion < 2011072800) { + $table = new xmldb_table('question_algebra'); + $field = new xmldb_field('answers'); + + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + $field = new xmldb_field('variables'); + + if ($dbman->field_exists($table, $field)) { + $dbman->drop_field($table, $field); + } + upgrade_plugin_savepoint(true, 2011072800, 'qtype', 'algebra'); + } + return true; +} + diff --git a/db/upgradelib.php b/db/upgradelib.php new file mode 100644 index 0000000..2f05142 --- /dev/null +++ b/db/upgradelib.php @@ -0,0 +1,71 @@ +. + +/** + * Upgrade library code for the algebra question type. + * + * @package qtype + * @subpackage algebra + * @copyright 2010 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + + +defined('MOODLE_INTERNAL') || die(); + + +/** + * Class for converting attempt data for algebra questions when upgrading + * attempts to the new question engine. + * + * This class is used by the code in question/engine/upgrade/upgradelib.php. + * + * @copyright 2010 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class qtype_algebra_qe2_attempt_updater extends question_qtype_attempt_updater { + public function right_answer() { + foreach ($this->question->options->answers as $ans) { + if ($ans->fraction > 0.999) { + return $ans->answer; + } + } + } + + public function was_answered($state) { + return !empty($state->answer); + } + + public function response_summary($state) { + if (!empty($state->answer)) { + return $state->answer; + } else { + return null; + } + } + + public function set_first_step_data_elements($state, &$data) { + } + + public function supply_missing_first_step_data(&$data) { + } + + public function set_data_elements_for_step($state, &$data) { + if (!empty($state->answer)) { + $data['answer'] = $state->answer; + } + } +} -- cgit v1.2.3