]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19519 , MDL-1728 Adding database question_calculated_options
authorpichetp <pichetp>
Sat, 22 Aug 2009 14:54:36 +0000 (14:54 +0000)
committerpichetp <pichetp>
Sat, 22 Aug 2009 14:54:36 +0000 (14:54 +0000)
question/type/calculated/db/install.xml
question/type/calculated/db/upgrade.php
question/type/calculated/edit_calculated_form.php
question/type/calculated/version.php

index 8e1135b3361a8fc84d55afc5cf84375fb104ac8d..84bca655d15277229b41bf7894ea18f64a553ab3 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="question/type/calculated/db" VERSION="20060812" COMMENT="XMLDB file for Moodle question/type/calculated. This question type also relies on the question_numerical_units table created by the numerical question type, and the tables created by the datasetdependent question type base class.">
+<XMLDB PATH="question/type/calculated/db" VERSION="20090819" COMMENT="XMLDB file for Moodle question/type/calculated. This question type also relies on the question_numerical_units table created by the numerical question type, and the tables created by the datasetdependent question type base class.">
   <TABLES>
-    <TABLE NAME="question_calculated" COMMENT="Options for questions of type calculated" NEXT="question_dataset_definitions">
+    <TABLE NAME="question_calculated" COMMENT="Options for questions of type calculated" NEXT="question_calculated_options">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
         <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="answer"/>
         <INDEX NAME="answer" UNIQUE="false" FIELDS="answer"/>
       </INDEXES>
     </TABLE>
-    <TABLE NAME="question_dataset_definitions" COMMENT="Organises and stores properties for dataset items" PREVIOUS="question_calculated" NEXT="question_dataset_items">
+    <TABLE NAME="question_calculated_options" COMMENT="Options for questions of type calculated" PREVIOUS="question_calculated" NEXT="question_dataset_definitions">
+      <FIELDS>
+        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="question"/>
+        <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="synchronize"/>
+        <FIELD NAME="synchronize" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="question"/>
+      </FIELDS>
+      <KEYS>
+        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="question"/>
+        <KEY NAME="question" TYPE="foreign" FIELDS="question" REFTABLE="question" REFFIELDS="id" PREVIOUS="primary"/>      
+      </KEYS>
+    </TABLE>
+    <TABLE NAME="question_dataset_definitions" COMMENT="Organises and stores properties for dataset items" PREVIOUS="question_calculated_options" NEXT="question_dataset_items">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="category"/>
         <FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="name"/>
index 78f3b2e206409b36c2900011c5f5bbaf70fe32fc..6dbe8b9caf142f16745e9c9ddcc4e03837f8aaed 100644 (file)
@@ -27,13 +27,34 @@ function xmldb_qtype_calculated_upgrade($oldversion) {
     $result = true;
 
     // MDL-16505.
-    if ($result && $oldversion < 2008091700) { //New version in version.php
+    if ($result && $oldversion < 2008091700 ) { //New version in version.php
         if (get_config('qtype_datasetdependent', 'version')) {
             $result = $result && unset_config('version', 'qtype_datasetdependent');
         }
         upgrade_plugin_savepoint($result, 2008091700, 'qtype', 'calculated');
     }
 
+//    let if ($dbman->table_exists()) replace the normal $oldversion test
+//    as in any case the question question_calculated_options should be created
+
+    /// Define table question_calculated_options to be created
+        $table = new xmldb_table('question_calculated_options');
+
+    /// Adding fields to table question_calculated_options
+        $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+        $table->add_field('question', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+        $table->add_field('synchronize', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
+
+    /// Adding keys to table question_calculated_options
+        $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+        $table->add_key('question', XMLDB_KEY_FOREIGN, array('question'), 'question', array('id'));
+
+    /// Conditionally launch create table for question_calculated_options
+        if (!$dbman->table_exists($table)) {
+            $result = $dbman->create_table($table);
+        }
+
+/// calculated savepoint reached
 /// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
 ///     $result = result of database_manager methods
 ///     upgrade_plugin_savepoint($result, YYYYMMDD00, 'qtype', 'calculated');
index 13c0e9a67aab45d4d58980fd4b008403a0f03895..b7fc93d133631e5b6ad87b147fa61a869961116e 100644 (file)
@@ -91,6 +91,12 @@ class question_edit_calculated_form extends question_edit_form {
             $firstunit->setPersistantFreeze(true);
         }
         //hidden elements
+        $mform->addElement('hidden', 'synchronize', '');
+        if (isset($this->question->options)&& isset($this->question->options->synchronize) ){
+            $mform->setDefault("synchronize", $this->question->options->synchronize);
+        } else {
+            $mform->setDefault("synchronize", 0 );
+        }
         $mform->addElement('hidden', 'wizard', 'datasetdefinitions');
         $mform->setType('wizard', PARAM_ALPHA);
 
index d576aac75a32278b352b77817d91a9eb9dbfd25d..add73d0b3faac566d9b8f52c07a98e0642393391 100644 (file)
@@ -1,5 +1,5 @@
 <?PHP // $Id$
 
-$plugin->version  = 2008091700;
+$plugin->version  = 2009082000;
 $plugin->requires = 2007101000;
 ?>