aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backup/moodle1/lib.php2
-rw-r--r--backup/moodle2/backup_qtype_algebra_plugin.class.php2
-rw-r--r--backup/moodle2/restore_qtype_algebra_plugin.class.php4
-rw-r--r--db/install.xml38
-rw-r--r--db/upgrade.php42
-rw-r--r--questiontype.php12
-rw-r--r--version.php2
7 files changed, 70 insertions, 32 deletions
diff --git a/backup/moodle1/lib.php b/backup/moodle1/lib.php
index 9ffe528..31a544d 100644
--- a/backup/moodle1/lib.php
+++ b/backup/moodle1/lib.php
@@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
/**
- * Multichoice question type conversion handler
+ * Algebra question type conversion handler.
*/
class moodle1_qtype_algebra_handler extends moodle1_qtype_handler {
diff --git a/backup/moodle2/backup_qtype_algebra_plugin.class.php b/backup/moodle2/backup_qtype_algebra_plugin.class.php
index 4f7708f..099a41c 100644
--- a/backup/moodle2/backup_qtype_algebra_plugin.class.php
+++ b/backup/moodle2/backup_qtype_algebra_plugin.class.php
@@ -63,7 +63,7 @@ class backup_qtype_algebra_plugin extends backup_qtype_plugin {
// Set source to populate the data.
$algebra->set_source_table('qtype_algebra_options', array('questionid' => backup::VAR_PARENTID));
- $algebravariable->set_source_table('qtype_algebra_variables', array('question' => backup::VAR_PARENTID));
+ $algebravariable->set_source_table('qtype_algebra_variables', array('questionid' => backup::VAR_PARENTID));
// Don't need to annotate ids nor files.
diff --git a/backup/moodle2/restore_qtype_algebra_plugin.class.php b/backup/moodle2/restore_qtype_algebra_plugin.class.php
index 013b70c..a4b4c70 100644
--- a/backup/moodle2/restore_qtype_algebra_plugin.class.php
+++ b/backup/moodle2/restore_qtype_algebra_plugin.class.php
@@ -62,7 +62,7 @@ class restore_qtype_algebra_plugin extends restore_qtype_plugin {
$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 qtype_algebra too.
+ // If the question has been created by restore, we need to create its qtype_algebra_options too.
if ($questioncreated) {
// Adjust some columns.
$data->questionid = $newquestionid;
@@ -91,7 +91,7 @@ class restore_qtype_algebra_plugin extends restore_qtype_plugin {
// If the question has been created by restore, we need to create its qtype_algebra_variables too.
if ($questioncreated) {
// Adjust some columns.
- $data->question = $newquestionid;
+ $data->questionid = $newquestionid;
// Insert record.
$newitemid = $DB->insert_record('qtype_algebra_variables', $data);
// Create mapping.
diff --git a/db/install.xml b/db/install.xml
index 5e2802c..b612af2 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -4,33 +4,33 @@
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
- <TABLE NAME="qtype_algebra_options" COMMENT="Options for algebra questions" NEXT="qtype_algebra_variables">
+ <TABLE NAME="qtype_algebra_options" COMMENT="Options for algebra questions">
<FIELDS>
- <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" PREVIOUS="id" NEXT="compareby"/>
- <FIELD NAME="compareby" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="evaluated" SEQUENCE="false" PREVIOUS="questionid" NEXT="nchecks"/>
- <FIELD NAME="nchecks" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="10" SEQUENCE="false" PREVIOUS="compareby" NEXT="tolerance"/>
- <FIELD NAME="tolerance" TYPE="float" NOTNULL="true" SEQUENCE="false" PREVIOUS="nchecks" NEXT="disallow"/>
- <FIELD NAME="disallow" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="tolerance" NEXT="allowedfuncs"/>
- <FIELD NAME="allowedfuncs" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="disallow" NEXT="answerprefix"/>
- <FIELD NAME="answerprefix" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="allowedfuncs"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+ <FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+ <FIELD NAME="compareby" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="evaluated" SEQUENCE="false"/>
+ <FIELD NAME="nchecks" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="10" SEQUENCE="false"/>
+ <FIELD NAME="tolerance" TYPE="float" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="disallow" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="allowedfuncs" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="answerprefix" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="questionid"/>
- <KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>
+ <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
+ <KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
</KEYS>
</TABLE>
- <TABLE NAME="qtype_algebra_variables" COMMENT="Variables for algebra questions" PREVIOUS="qtype_algebra_options">
+ <TABLE NAME="qtype_algebra_variables" COMMENT="Variables for algebra questions">
<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="name"/>
- <FIELD NAME="name" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" PREVIOUS="question" NEXT="min"/>
- <FIELD NAME="min" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="-" SEQUENCE="false" PREVIOUS="name" NEXT="max"/>
- <FIELD NAME="max" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="-" SEQUENCE="false" PREVIOUS="min"/>
+ <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
+ <FIELD NAME="questionid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
+ <FIELD NAME="name" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false"/>
+ <FIELD NAME="min" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="-" SEQUENCE="false"/>
+ <FIELD NAME="max" TYPE="char" LENGTH="30" NOTNULL="true" DEFAULT="-" SEQUENCE="false"/>
</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"/>
+ <KEY NAME="questionid" TYPE="foreign" FIELDS="questionid" REFTABLE="question" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
diff --git a/db/upgrade.php b/db/upgrade.php
index 48cc159..f1db600 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -80,6 +80,48 @@ function xmldb_qtype_algebra_upgrade($oldversion=0) {
}
upgrade_plugin_savepoint(true, 2012061702, 'qtype', 'algebra');
}
+
+ if ($oldversion < 2019042705) {
+
+ // Define key question (foreign) to be dropped form qtype_algebra_variables.
+ $table = new xmldb_table('qtype_algebra_variables');
+ $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_algebra savepoint was reached.
+ upgrade_plugin_savepoint(true, 2019042705, 'qtype', 'algebra');
+ }
+
+ if ($oldversion < 2019042706) {
+
+ // Rename field question on table qtype_algebra_variables to questionid.
+ $table = new xmldb_table('qtype_algebra_variables');
+ $field = new xmldb_field('question', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'id');
+
+ // Launch rename field question.
+ if ($dbman->field_exists($table, $field)) {
+ $dbman->rename_field($table, $field, 'questionid');
+ }
+
+ // Record that qtype_algebra savepoint was reached.
+ upgrade_plugin_savepoint(true, 2019042706, 'qtype', 'algebra');
+ }
+
+ if ($oldversion < 2019042707) {
+
+ // Define key questionid (foreign-unique) to be added to qtype_algebra_variables.
+ $table = new xmldb_table('qtype_algebra_variables');
+ $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_algebra savepoint was reached.
+ upgrade_plugin_savepoint(true, 2019042707, 'qtype', 'algebra');
+ }
+
return true;
}
diff --git a/questiontype.php b/questiontype.php
index 01f86c4..c3a0674 100644
--- a/questiontype.php
+++ b/questiontype.php
@@ -54,10 +54,6 @@ class qtype_algebra extends question_type {
);
}
- public function questionid_column_name() {
- return 'questionid';
- }
-
public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
@@ -73,7 +69,7 @@ class qtype_algebra extends question_type {
public function delete_question($questionid, $contextid) {
global $DB;
$DB->delete_records('qtype_algebra_options', array('questionid' => $questionid));
- $DB->delete_records('qtype_algebra_variables', array('question' => $questionid));
+ $DB->delete_records('qtype_algebra_variables', array('questionid' => $questionid));
parent::delete_question($questionid, $contextid);
}
@@ -94,7 +90,7 @@ class qtype_algebra extends question_type {
// Create the results class.
$result = new stdClass;
// Get all the old answers from the database as an array.
- if (!$oldvars = $DB->get_records('qtype_algebra_variables', array('question' => $question->id), 'id ASC')) {
+ if (!$oldvars = $DB->get_records('qtype_algebra_variables', array('questionid' => $question->id), 'id ASC')) {
$oldvars = array();
}
// Create an array of the variable IDs for the question.
@@ -122,7 +118,7 @@ class qtype_algebra extends question_type {
// This is a completely new variable so we have to create a new record.
$var = new stdClass;
$var->name = trim($varname);
- $var->question = $question->id;
+ $var->questionid = $question->id;
$var->min = trim($question->varmin[$key]);
$var->max = trim($question->varmax[$key]);
// Insert a new record into the database table.
@@ -305,7 +301,7 @@ class qtype_algebra extends question_type {
return false;
}
// Now get the variables from the database as well.
- $question->options->variables = $DB->get_records('qtype_algebra_variables', array('question' => $question->id));
+ $question->options->variables = $DB->get_records('qtype_algebra_variables', array('questionid' => $question->id));
// Check that we have variables and if not then bail since this question type requires variables.
if (count($question->options->variables) == 0) {
diff --git a/version.php b/version.php
index 7a28488..41195e0 100644
--- a/version.php
+++ b/version.php
@@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qtype_algebra';
-$plugin->version = 2019020201;
+$plugin->version = 2019042707;
$plugin->requires = 2016052300;
$plugin->release = '1.8 for Moodle 3.0 ... 3.6';