Skip to content
Browse files

MDL-37600 qtype match: remove obsolete DB columns, and obey coding st…

…yle.

Tables renamed to start qtype_match, and qtype_match_options.subquestions
and qtype_match_subquestions.code columnd dropped. Also, qtype_match_options
-> question foreign key link changed to be foreign-unique, since that is
what it should be.
  • Loading branch information...
1 parent b3778a0 commit 87d767343d0c80f3376d8370ec3a5c91a7359e86 @timhunt timhunt committed Jan 21, 2013
View
16 question/type/match/backup/moodle2/backup_qtype_match_plugin.class.php
@@ -49,29 +49,29 @@ protected function define_question_plugin_structure() {
// Now create the qtype own structures
$matchoptions = new backup_nested_element('matchoptions', array('id'), array(
- 'subquestions', 'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
+ 'shuffleanswers', 'correctfeedback', 'correctfeedbackformat',
'partiallycorrectfeedback', 'partiallycorrectfeedbackformat',
'incorrectfeedback', 'incorrectfeedbackformat', 'shownumcorrect'));
$matches = new backup_nested_element('matches');
$match = new backup_nested_element('match', array('id'), array(
- 'code', 'questiontext', 'questiontextformat', 'answertext'));
+ 'questiontext', 'questiontextformat', 'answertext'));
// Now the own qtype tree
$pluginwrapper->add_child($matchoptions);
$pluginwrapper->add_child($matches);
$matches->add_child($match);
// set source to populate the data
- $matchoptions->set_source_table('question_match',
- array('question' => backup::VAR_PARENTID));
+ $matchoptions->set_source_table('qtype_match_options',
+ array('questionid' => backup::VAR_PARENTID));
$match->set_source_sql('
SELECT *
- FROM {question_match_sub}
- WHERE question = :question
+ FROM {qtype_match_subquestions}
+ WHERE questionid = :questionid
ORDER BY id',
- array('question' => backup::VAR_PARENTID));
+ array('questionid' => backup::VAR_PARENTID));
// don't need to annotate ids nor files
@@ -86,6 +86,6 @@ protected function define_question_plugin_structure() {
*/
public static function get_qtype_fileareas() {
return array(
- 'subquestion' => 'question_match_sub');
+ 'subquestion' => 'qtype_match_subquestions');
}
}
View
95 question/type/match/backup/moodle2/restore_qtype_match_plugin.class.php
@@ -69,7 +69,7 @@ public function process_matchoptions($data) {
$newquestionid = $this->get_new_parentid('question');
$questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false;
- // If the question has been created by restore, we need to create its question_match too
+ // If the question has been created by restore, we need to create its qtype_match_options too
if ($questioncreated) {
// Fill in some field that were added in 2.1, and so which may be missing
// from backups made in older versions of Moodle.
@@ -90,14 +90,9 @@ public function process_matchoptions($data) {
}
// Adjust some columns
- $data->question = $newquestionid;
- // Keep question_match->subquestions unmodified
- // after_execute_question() will perform the remapping once all subquestions
- // have been created
- // Insert record
- $newitemid = $DB->insert_record('question_match', $data);
- // Create mapping
- $this->set_mapping('question_match', $oldid, $newitemid);
+ $data->questionid = $newquestionid;
+ $newitemid = $DB->insert_record('qtype_match_options', $data);
+ $this->set_mapping('qtype_match_options', $oldid, $newitemid);
}
}
@@ -117,31 +112,33 @@ public function process_match($data) {
if ($questioncreated) {
// If the question has been created by restore, we need to create its
- // question_match_sub too
+ // qtype_match_subquestions too.
// Adjust some columns
- $data->question = $newquestionid;
+ $data->questionid = $newquestionid;
// Insert record
- $newitemid = $DB->insert_record('question_match_sub', $data);
+ $newitemid = $DB->insert_record('qtype_match_subquestions', $data);
// Create mapping (there are files and states based on this)
- $this->set_mapping('question_match_sub', $oldid, $newitemid);
+ $this->set_mapping('qtype_match_subquestions', $oldid, $newitemid);
+ if (isset($data->code)) {
+ $this->set_mapping('qtype_match_subquestion_codes', $data->code, $newitemid);
+ }
} else {
- // match questions require mapping of question_match_sub, because
+ // match questions require mapping of qtype_match_subquestions, because
// they are used by question_states->answer
- // Look for matching subquestion (by question, questiontext and answertext)
- $sub = $DB->get_record_select('question_match_sub', 'question = ? AND ' .
+ // Look for matching subquestion (by questionid, questiontext and answertext)
+ $sub = $DB->get_record_select('qtype_match_subquestions', 'questionid = ? AND ' .
$DB->sql_compare_text('questiontext') . ' = ' .
$DB->sql_compare_text('?').' AND answertext = ?',
- array($newquestionid, $data->questiontext, $data->answertext),
- 'id', IGNORE_MULTIPLE);
+ array($newquestionid, $data->questiontext, $data->answertext),
+ 'id', IGNORE_MULTIPLE);
// Not able to find the answer, let's try cleaning the answertext
- // of all the question answers in DB as slower fallback. MDL-36683 / MDL-30018.
+ // of all the match subquestions in DB as slower fallback. MDL-36683 / MDL-30018.
if (!$sub) {
- $params = array('question' => $newquestionid);
- $potentialsubs = $DB->get_records('question_match_sub', array('question' => $newquestionid), '', 'id, questiontext, answertext');
+ $potentialsubs = $DB->get_records('qtype_match_subquestions', array('questionid' => $newquestionid), '', 'id, questiontext, answertext');
foreach ($potentialsubs as $potentialsub) {
// Clean in the same way than {@link xml_writer::xml_safe_utf8()}.
$cleanquestion = preg_replace('/[\x-\x8\xb-\xc\xe-\x1f\x7f]/is', '', $potentialsub->questiontext); // Clean CTRL chars.
@@ -158,43 +155,11 @@ public function process_match($data) {
// Found, let's create the mapping
if ($sub) {
- $this->set_mapping('question_match_sub', $oldid, $sub->id);
+ $this->set_mapping('qtype_match_subquestions', $oldid, $sub->id);
} else {
- throw new restore_step_exception('error_question_match_sub_missing_in_db', $data);
- }
- }
- }
-
- /**
- * This method is executed once the whole restore_structure_step,
- * more exactly ({@link restore_create_categories_and_questions})
- * has ended processing the whole xml structure. Its name is:
- * "after_execute_" + connectionpoint ("question")
- *
- * For match qtype we use it to restore the subquestions column,
- * containing one list of question_match_sub ids
- */
- public function after_execute_question() {
- global $DB;
- // Now that all the question_match_subs have been restored, let's process
- // the created question_match subquestions (list of question_match_sub ids)
- $rs = $DB->get_recordset_sql(
- "SELECT qm.id, qm.subquestions
- FROM {question_match} qm
- JOIN {backup_ids_temp} bi ON bi.newitemid = qm.question
- WHERE bi.backupid = ?
- AND bi.itemname = 'question_created'", array($this->get_restoreid()));
- foreach ($rs as $rec) {
- $subquestionsarr = explode(',', $rec->subquestions);
- foreach ($subquestionsarr as $key => $subquestion) {
- $subquestionsarr[$key] = $this->get_mappingid(
- 'question_match_sub', $subquestion);
+ throw new restore_step_exception('error_qtype_match_subquestion_missing_in_db', $data);
}
- $subquestions = implode(',', $subquestionsarr);
- $DB->set_field('question_match', 'subquestions', $subquestions,
- array('id' => $rec->id));
}
- $rs->close();
}
public function recode_response($questionid, $sequencenumber, array $response) {
@@ -212,7 +177,8 @@ public function recode_response($questionid, $sequencenumber, array $response) {
* recoded pointing to all the restored stuff for match questions
*
* answer is one comma separated list of hypen separated pairs
- * containing question_match_sub->id and question_match_sub->code
+ * containing question_match_sub->id and question_match_sub->code, which
+ * has been remapped to be qtype_match_subquestions->id, since code no longer exists.
*/
public function recode_legacy_state_answer($state) {
$answer = $state->answer;
@@ -221,8 +187,13 @@ public function recode_legacy_state_answer($state) {
$pairarr = explode('-', $pair);
$id = $pairarr[0];
$code = $pairarr[1];
- $newid = $this->get_mappingid('question_match_sub', $id);
- $resultarr[] = implode('-', array($newid, $code));
+ $newid = $this->get_mappingid('qtype_match_subquestions', $id);
+ if ($code) {
+ $newcode = $this->get_mappingid('qtype_match_subquestion_codes', $code);
+ } else {
+ $newcode = $code;
+ }
+ $resultarr[] = $newid . '-' . $newcode;
}
return implode(',', $resultarr);
}
@@ -235,7 +206,7 @@ public function recode_legacy_state_answer($state) {
protected function recode_match_sub_order($order) {
$neworder = array();
foreach (explode(',', $order) as $id) {
- if ($newid = $this->get_mappingid('question_match_sub', $id)) {
+ if ($newid = $this->get_mappingid('qtype_match_subquestions', $id)) {
$neworder[] = $newid;
}
}
@@ -249,11 +220,11 @@ public static function define_decode_contents() {
$contents = array();
- $contents[] = new restore_decode_content('question_match_sub',
- array('questiontext'), 'question_match_sub');
+ $contents[] = new restore_decode_content('qtype_match_subquestions',
+ array('questiontext'), 'qtype_match_subquestions');
$fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
- $contents[] = new restore_decode_content('question_match', $fields, 'question_match');
+ $contents[] = new restore_decode_content('qtype_match_options', $fields, 'qtype_match_options');
return $contents;
}
View
32 question/type/match/db/install.xml
@@ -1,41 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="question/type/match/db" VERSION="20120122" COMMENT="XMLDB file for Moodle question/type/match"
+<XMLDB PATH="question/type/match/db" VERSION="20130121" COMMENT="XMLDB file for Moodle question/type/match"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
- <TABLE NAME="question_match" COMMENT="Defines fixed matching questions" NEXT="question_match_sub">
+ <TABLE NAME="qtype_match_options" COMMENT="Defines the question-type specific options for matching questions" NEXT="qtype_match_subquestions">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="question"/>
- <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="subquestions"/>
- <FIELD NAME="subquestions" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="question" NEXT="shuffleanswers"/>
- <FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="subquestions" NEXT="correctfeedback"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="questionid"/>
+ <FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key link to question.id." PREVIOUS="id" NEXT="shuffleanswers"/>
+ <FIELD NAME="shuffleanswers" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="questionid" NEXT="correctfeedback"/>
<FIELD NAME="correctfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any correct response." PREVIOUS="shuffleanswers" NEXT="correctfeedbackformat"/>
<FIELD NAME="correctfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="correctfeedback" NEXT="partiallycorrectfeedback"/>
<FIELD NAME="partiallycorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any partially correct response." PREVIOUS="correctfeedbackformat" NEXT="partiallycorrectfeedbackformat"/>
<FIELD NAME="partiallycorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="partiallycorrectfeedback" NEXT="incorrectfeedback"/>
<FIELD NAME="incorrectfeedback" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Feedback shown for any incorrect response." PREVIOUS="partiallycorrectfeedbackformat" NEXT="incorrectfeedbackformat"/>
<FIELD NAME="incorrectfeedbackformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="incorrectfeedback" NEXT="shownumcorrect"/>
- <FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, then when the user gets a multiple-response question partially correct, tell them how many choices they got correct alongside the feedback." PREVIOUS="incorrectfeedbackformat"/>
+ <FIELD NAME="shownumcorrect" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If true, then when the user gets the question partially correct, tell them how many choices they got correct alongside the feedback." PREVIOUS="incorrectfeedbackformat"/>
</FIELDS>
<KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
- <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
+ <KEY NAME="questionid" TYPE="foreign-unique" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
- <TABLE NAME="question_match_sub" COMMENT="Defines the subquestions that make up a matching question" PREVIOUS="question_match">
+ <TABLE NAME="qtype_match_subquestions" COMMENT="The subquestions that make up a matching question" PREVIOUS="qtype_match_options">
<FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="code"/>
- <FIELD NAME="code" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Should this point to parent question_match-&amp;gt;id ?" PREVIOUS="id" NEXT="question"/>
- <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="code" NEXT="questiontext"/>
- <FIELD NAME="questiontext" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="question" NEXT="questiontextformat"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="questionid"/>
+ <FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key link to question.id." PREVIOUS="id" NEXT="questiontext"/>
+ <FIELD NAME="questiontext" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="questionid" NEXT="questiontextformat"/>
<FIELD NAME="questiontextformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="questiontext" NEXT="answertext"/>
<FIELD NAME="answertext" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="questiontextformat"/>
</FIELDS>
<KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
- <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
+ <KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
143 question/type/match/db/upgrade.php
@@ -36,17 +36,148 @@ function xmldb_qtype_match_upgrade($oldversion) {
$dbman = $DB->get_manager();
+ // Moodle v2.2.0 release upgrade line.
+ // Put any upgrade step following this.
- // Moodle v2.2.0 release upgrade line
- // Put any upgrade step following this
+ // Moodle v2.3.0 release upgrade line.
+ // Put any upgrade step following this.
- // Moodle v2.3.0 release upgrade line
- // Put any upgrade step following this
+ // Moodle v2.4.0 release upgrade line.
+ // Put any upgrade step following this.
+ if ($oldversion < 2013012100) {
- // Moodle v2.4.0 release upgrade line
- // Put any upgrade step following this
+ // Define table question_match to be renamed to qtype_match_options.
+ $table = new xmldb_table('question_match');
+ // Launch rename table for qtype_match_options.
+ $dbman->rename_table($table, 'qtype_match_options');
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012100, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012101) {
+
+ // Define key question (foreign) to be dropped form qtype_match_options.
+ $table = new xmldb_table('qtype_match_options');
+ $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
+
+ // Launch drop key question.
+ $dbman->drop_key($table, $key);
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012101, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012102) {
+
+ // Rename field question on table qtype_match_options to questionid.
+ $table = new xmldb_table('qtype_match_options');
+ $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
+
+ // Launch rename field question.
+ $dbman->rename_field($table, $field, 'questionid');
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012102, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012103) {
+
+ // Define key questionid (foreign-unique) to be added to qtype_match_options.
+ $table = new xmldb_table('qtype_match_options');
+ $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN_UNIQUE, array('questionid'), 'question', array('id'));
+
+ // Launch add key questionid.
+ $dbman->add_key($table, $key);
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012103, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012104) {
+
+ // Define field subquestions to be dropped from qtype_match_options.
+ $table = new xmldb_table('qtype_match_options');
+ $field = new xmldb_field('subquestions');
+
+ // Conditionally launch drop field subquestions.
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012104, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012105) {
+
+ // Define table question_match_sub to be renamed to qtype_match_subquestions.
+ $table = new xmldb_table('question_match_sub');
+
+ // Launch rename table for qtype_match_subquestions.
+ $dbman->rename_table($table, 'qtype_match_subquestions');
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012105, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012106) {
+
+ // Define key question (foreign) to be dropped form qtype_match_subquestions.
+ $table = new xmldb_table('qtype_match_subquestions');
+ $key = new xmldb_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
+
+ // Launch drop key question.
+ $dbman->drop_key($table, $key);
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012106, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012107) {
+
+ // Rename field question on table qtype_match_subquestions to questionid.
+ $table = new xmldb_table('qtype_match_subquestions');
+ $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
+
+ // Launch rename field question.
+ $dbman->rename_field($table, $field, 'questionid');
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012107, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012108) {
+
+ // Define key questionid (foreign) to be added to qtype_match_subquestions.
+ $table = new xmldb_table('qtype_match_subquestions');
+ $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, array('questionid'), 'question', array('id'));
+
+ // Launch add key questionid.
+ $dbman->add_key($table, $key);
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012108, 'qtype', 'match');
+ }
+
+ if ($oldversion < 2013012109) {
+
+ // Define field code to be dropped from qtype_match_subquestions.
+ // The field code has not been needed since the new question engine in
+ // Moodle 2.1. It should be safe to drop it now.
+ $table = new xmldb_table('qtype_match_subquestions');
+ $field = new xmldb_field('code');
+
+ // Conditionally launch drop field code.
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->drop_field($table, $field);
+ }
+
+ // Record that qtype_match savepoint was reached.
+ upgrade_plugin_savepoint(true, 2013012109, 'qtype', 'match');
+ }
return true;
}
View
2 question/type/match/db/upgradelib.php
@@ -98,7 +98,7 @@ protected function make_summary($pairs) {
protected function lookup_choice($choice) {
foreach ($this->question->options->subquestions as $matchsub) {
- if ($matchsub->code == $choice) {
+ if ($matchsub->id == $choice) {
if (array_key_exists($matchsub->id, $this->choices)) {
return $matchsub->id;
} else {
View
67 question/type/match/questiontype.php
@@ -17,10 +17,9 @@
/**
* Question type class for the matching question type.
*
- * @package qtype
- * @subpackage match
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package qtype_match
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -33,17 +32,18 @@
/**
* The matching question type class.
*
- * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_match extends question_type {
public function get_question_options($question) {
global $DB;
parent::get_question_options($question);
- $question->options = $DB->get_record('question_match', array('question' => $question->id));
- $question->options->subquestions = $DB->get_records('question_match_sub',
- array('question' => $question->id), 'id ASC');
+ $question->options = $DB->get_record('qtype_match_options',
+ array('questionid' => $question->id));
+ $question->options->subquestions = $DB->get_records('qtype_match_subquestions',
+ array('questionid' => $question->id), 'id ASC');
return true;
}
@@ -52,11 +52,8 @@ public function save_question_options($question) {
$context = $question->context;
$result = new stdClass();
- $oldsubquestions = $DB->get_records('question_match_sub',
- array('question' => $question->id), 'id ASC');
-
- // $subquestions will be an array with subquestion ids
- $subquestions = array();
+ $oldsubquestions = $DB->get_records('qtype_match_subquestions',
+ array('questionid' => $question->id), 'id ASC');
// Insert all the new question+answer pairs
foreach ($question->subquestions as $key => $questiontext) {
@@ -71,62 +68,48 @@ public function save_question_options($question) {
$subquestion = array_shift($oldsubquestions);
if (!$subquestion) {
$subquestion = new stdClass();
- // Determine a unique random code
- $subquestion->code = rand(1, 999999999);
- while ($DB->record_exists('question_match_sub',
- array('code' => $subquestion->code, 'question' => $question->id))) {
- $subquestion->code = rand(1, 999999999);
- }
- $subquestion->question = $question->id;
+ $subquestion->questionid = $question->id;
$subquestion->questiontext = '';
$subquestion->answertext = '';
- $subquestion->id = $DB->insert_record('question_match_sub', $subquestion);
+ $subquestion->id = $DB->insert_record('qtype_match_subquestions', $subquestion);
}
$subquestion->questiontext = $this->import_or_save_files($questiontext,
$context, 'qtype_match', 'subquestion', $subquestion->id);
$subquestion->questiontextformat = $questiontext['format'];
$subquestion->answertext = trim($question->subanswers[$key]);
- $DB->update_record('question_match_sub', $subquestion);
-
- $subquestions[] = $subquestion->id;
+ $DB->update_record('qtype_match_subquestions', $subquestion);
}
// Delete old subquestions records
$fs = get_file_storage();
foreach ($oldsubquestions as $oldsub) {
$fs->delete_area_files($context->id, 'qtype_match', 'subquestion', $oldsub->id);
- $DB->delete_records('question_match_sub', array('id' => $oldsub->id));
+ $DB->delete_records('qtype_match_subquestions', array('id' => $oldsub->id));
}
// Save the question options.
- $options = $DB->get_record('question_match', array('question' => $question->id));
+ $options = $DB->get_record('qtype_match_options', array('questionid' => $question->id));
if (!$options) {
$options = new stdClass();
- $options->question = $question->id;
+ $options->questionid = $question->id;
$options->correctfeedback = '';
$options->partiallycorrectfeedback = '';
$options->incorrectfeedback = '';
- $options->id = $DB->insert_record('question_match', $options);
+ $options->id = $DB->insert_record('qtype_match_options', $options);
}
- $options->subquestions = implode(',', $subquestions);
$options->shuffleanswers = $question->shuffleanswers;
$options = $this->save_combined_feedback_helper($options, $question, $context, true);
- $DB->update_record('question_match', $options);
+ $DB->update_record('qtype_match_options', $options);
$this->save_hints($question, true);
if (!empty($result->notice)) {
return $result;
}
- if (count($subquestions) < 3) {
- $result->notice = get_string('notenoughanswers', 'question', 3);
- return $result;
- }
-
return true;
}
@@ -162,8 +145,8 @@ protected function make_hint($hint) {
public function delete_question($questionid, $contextid) {
global $DB;
- $DB->delete_records('question_match', array('question' => $questionid));
- $DB->delete_records('question_match_sub', array('question' => $questionid));
+ $DB->delete_records('qtype_match_options', array('questionid' => $questionid));
+ $DB->delete_records('qtype_match_subquestions', array('questionid' => $questionid));
parent::delete_question($questionid, $contextid);
}
@@ -200,8 +183,8 @@ public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
- $subquestionids = $DB->get_records_menu('question_match_sub',
- array('question' => $questionid), 'id', 'id,1');
+ $subquestionids = $DB->get_records_menu('qtype_match_subquestions',
+ array('questionid' => $questionid), 'id', 'id,1');
foreach ($subquestionids as $subquestionid => $notused) {
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_match', 'subquestion', $subquestionid);
@@ -217,8 +200,8 @@ protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
- $subquestionids = $DB->get_records_menu('question_match_sub',
- array('question' => $questionid), 'id', 'id,1');
+ $subquestionids = $DB->get_records_menu('qtype_match_subquestions',
+ array('questionid' => $questionid), 'id', 'id,1');
foreach ($subquestionids as $subquestionid => $notused) {
$fs->delete_area_files($contextid, 'qtype_match', 'subquestion', $subquestionid);
}
View
63 question/type/match/tests/upgradelibnewqe_test.php
@@ -110,39 +110,34 @@ public function test_match_deferredfeedback_history6220() {
'maxmark' => '3',
'options' => (object) array(
'id' => '27',
- 'question' => '695',
+ 'questionid' => '695',
'subquestions' => array(
148 => (object) array(
- 'code' => '511093512',
- 'question' => '695',
+ 'questionid' => '695',
'questiontext' => 'Active adjacent system',
'answertext' => 'A system that interacts with or participates in the work.',
'id' => 148,
),
149 => (object) array(
- 'code' => '10881658',
- 'question' => '695',
+ 'questionid' => '695',
'questiontext' => 'Autonomous adjacent system',
'answertext' => 'An external entity that acts independently of the work under study.',
'id' => 149,
),
150 => (object) array(
- 'code' => '661953276',
- 'question' => '695',
+ 'questionid' => '695',
'questiontext' => 'Cooperative adjacent system',
'answertext' => 'A system that is involved in the response to a business event.',
'id' => 150,
),
151 => (object) array(
- 'code' => '786218388',
- 'question' => '695',
+ 'questionid' => '695',
'questiontext' => '',
'answertext' => 'A system which does not supply or receive data from the work.',
'id' => 151,
),
152 => (object) array(
- 'code' => '166673328',
- 'question' => '695',
+ 'questionid' => '695',
'questiontext' => '',
'answertext' => 'An external entity that performs part of the work under study.',
'id' => 152,
@@ -186,7 +181,7 @@ public function test_match_deferredfeedback_history6220() {
'question' => '695',
'originalquestion' => '0',
'seq_number' => '1',
- 'answer' => '148-511093512,149-786218388,150-166673328,151-0,152-0',
+ 'answer' => '148-148,149-151,150-152,151-0,152-0',
'timestamp' => '1177419855',
'event' => '2',
'grade' => '0',
@@ -199,7 +194,7 @@ public function test_match_deferredfeedback_history6220() {
'question' => '695',
'originalquestion' => '0',
'seq_number' => '2',
- 'answer' => '148-511093512,149-10881658,150-661953276,151-0,152-0',
+ 'answer' => '148-148,149-149,150-150,151-0,152-0',
'timestamp' => '1177419956',
'event' => '2',
'grade' => '0',
@@ -212,7 +207,7 @@ public function test_match_deferredfeedback_history6220() {
'question' => '695',
'originalquestion' => '0',
'seq_number' => '3',
- 'answer' => '148-511093512,149-10881658,150-661953276,151-0,152-0',
+ 'answer' => '148-148,149-149,150-150,151-0,152-0',
'timestamp' => '1177419956',
'event' => '6',
'grade' => '3',
@@ -360,32 +355,28 @@ public function test_match_deferredfeedback_history60() {
'maxmark' => '1',
'options' => (object) array(
'id' => '35',
- 'question' => '738',
+ 'questionid' => '738',
'subquestions' => array(
213 => (object) array(
- 'code' => '860968335',
- 'question' => '738',
+ 'questionid' => '738',
'questiontext' => 'Subject gateways provide links to sites that have been quality checked ',
'answertext' => 'True',
'id' => 213,
),
214 => (object) array(
- 'code' => '253006016',
- 'question' => '738',
+ 'questionid' => '738',
'questiontext' => 'Subject gateways offer more variety than search engines ',
'answertext' => 'False',
'id' => 214,
),
215 => (object) array(
- 'code' => '964910717',
- 'question' => '738',
+ 'questionid' => '738',
'questiontext' => 'Subject gateways index websites automatically',
'answertext' => 'False',
'id' => 215,
),
216 => (object) array(
- 'code' => '3109713',
- 'question' => '738',
+ 'questionid' => '738',
'questiontext' => 'Subject gateways can provide a more direct route to websites containing academic content ',
'answertext' => 'True',
'id' => 216,
@@ -429,7 +420,7 @@ public function test_match_deferredfeedback_history60() {
'question' => '738',
'originalquestion' => '0',
'seq_number' => '1',
- 'answer' => '213-860968335,214-253006016,215-964910717,216-3109713',
+ 'answer' => '213-213,214-214,215-215,216-216',
'timestamp' => '1168267508',
'event' => '6',
'grade' => '1',
@@ -572,32 +563,28 @@ public function test_match_deferredfeedback_history622220() {
'maxmark' => '1',
'options' => (object) array(
'id' => '279',
- 'question' => '11135',
+ 'questionid' => '11135',
'subquestions' => array(
1632 => (object) array(
- 'code' => '315604704',
- 'question' => '11135',
+ 'questionid' => '11135',
'questiontext' => 'Subject gateways provide links to sites that have been quality checked',
'answertext' => 'True',
'id' => 1632,
),
1633 => (object) array(
- 'code' => '750106618',
- 'question' => '11135',
+ 'questionid' => '11135',
'questiontext' => 'Subject gateways offer more variety than search engines',
'answertext' => 'False',
'id' => 1633,
),
1634 => (object) array(
- 'code' => '446418834',
- 'question' => '11135',
+ 'questionid' => '11135',
'questiontext' => 'Subject gateways index websites automatically',
'answertext' => 'False',
'id' => 1634,
),
1635 => (object) array(
- 'code' => '3262827',
- 'question' => '11135',
+ 'questionid' => '11135',
'questiontext' => 'Subject gateways can provide a more direct route to websites containing academic content',
'answertext' => 'True',
'id' => 1635,
@@ -641,7 +628,7 @@ public function test_match_deferredfeedback_history622220() {
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '1',
- 'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
+ 'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507025',
'event' => '2',
'grade' => '0',
@@ -654,7 +641,7 @@ public function test_match_deferredfeedback_history622220() {
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '2',
- 'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
+ 'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507125',
'event' => '2',
'grade' => '0',
@@ -667,7 +654,7 @@ public function test_match_deferredfeedback_history622220() {
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '3',
- 'answer' => '1633-750106618,1635-3262827,1634-0,1632-315604704',
+ 'answer' => '1633-1633,1635-1635,1634-0,1632-1632',
'timestamp' => '1200507172',
'event' => '2',
'grade' => '0',
@@ -680,7 +667,7 @@ public function test_match_deferredfeedback_history622220() {
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '4',
- 'answer' => '1633-750106618,1635-3262827,1634-3262827,1632-315604704',
+ 'answer' => '1633-1633,1635-1635,1634-1635,1632-1632',
'timestamp' => '1200507467',
'event' => '2',
'grade' => '0',
@@ -693,7 +680,7 @@ public function test_match_deferredfeedback_history622220() {
'question' => '11135',
'originalquestion' => '0',
'seq_number' => '5',
- 'answer' => '1633-750106618,1635-3262827,1634-3262827,1632-315604704',
+ 'answer' => '1633-1632,1635-1635,1634-1635,1632-1632',
'timestamp' => '1200507467',
'event' => '6',
'grade' => '0.75',
View
2 question/type/match/version.php
@@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_match';
-$plugin->version = 2012112900;
+$plugin->version = 2013012109;
$plugin->requires = 2012112900;

0 comments on commit 87d7673

Please sign in to comment.
Something went wrong with that request. Please try again.