]> git.mjollnir.org Git - moodle.git/commitdiff
adding idnumber field for course modules and modedit form
authortoyomoyo <toyomoyo>
Wed, 11 Apr 2007 09:19:24 +0000 (09:19 +0000)
committertoyomoyo <toyomoyo>
Wed, 11 Apr 2007 09:19:24 +0000 (09:19 +0000)
course/lib.php
course/modedit.php
course/moodleform_mod.php
lib/db/install.xml
lib/db/upgrade.php
version.php

index 466eaa77ead6f858c1f663e37fe33d1e4a9fffb1..0fca9adaf81ace829f984e01a67b65ef82edec65 100644 (file)
@@ -2037,6 +2037,9 @@ function set_coursemodule_groupmode($id, $groupmode) {
     return set_field("course_modules", "groupmode", $groupmode, "id", $id);
 }
 
+function set_coursemodule_idnumber($id, $idnumber) {
+    return set_field("course_modules", "idnumber", $idnumber, "id", $id);  
+}
 /**
 * $prevstateoverrides = true will set the visibility of the course module
 * to what is defined in visibleold. This enables us to remember the current
index 7c7c07bc15be9615c87bb3956bfc929efcc7e004..56e2b50c754ce499bad3611601ded261b952d37f 100644 (file)
 
         if (!empty($fromform->update)) {
 
-
             if (isset($fromform->name)) {
                 if (trim($fromform->name) == '') {
                     unset($fromform->name);
             if (isset($fromform->groupmode)) {
                 set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode);
             }
-
+            
+            // set cm id number
+            if (isset($fromform->idnumber)) {
+                set_coursemodule_idnumber($fromform->coursemodule, $fromform->idnumber);  
+            }
 
             add_to_log($course->id, "course", "update mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
             }
             // make sure visibility is set correctly (in particular in calendar)
             set_coursemodule_visible($fromform->coursemodule, $fromform->visible);
-
+            
+            // set cm idnumber
+            if (isset($fromform->idnumber)) {
+                set_coursemodule_idnumber($fromform->coursemodule, $fromform->idnumber);  
+            }
+            
             add_to_log($course->id, "course", "add mod",
                        "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule",
                        "$fromform->modulename $fromform->instance");
index 3a8b0482df00dd6c5c0391a12ed3e15303f1a6ac..945a105705b10efd8cd4cc3ffae29f8665c875cb 100644 (file)
@@ -68,7 +68,8 @@ class moodleform_mod extends moodleform {
             $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
         }
         $mform->addElement('modvisible', 'visible', get_string('visible'));
-
+        $mform->addElement('text', 'idnumber', get_string('idnumber'));
+        $mform->setDefault('idnumber', $this->_cm->idnumber);
         $this->standard_hidden_coursemodule_elements();
     }
 
@@ -112,7 +113,7 @@ class moodleform_mod extends moodleform {
      * @return unknown
      */
     function standard_coursemodule_elements_settings(){
-        return ($this->modgroupmode_settings() + $this->modvisible_settings());
+        return ($this->modgroupmode_settings() + $this->modvisible_settings() + $this->modidnumber_settings());
     }
     /**
      * This is called from modedit.php to load the default for the groupmode element.
@@ -124,6 +125,16 @@ class moodleform_mod extends moodleform {
         global $COURSE;
         return array('groupmode'=>groupmode($COURSE, $this->_cm));
     }
+    /**
+     * This is called from modedit.php to load the default for the groupmode element.
+     *
+     * @param object $course
+     * @param object $cm
+     */
+    function modidnumber_settings() {
+        global $COURSE;
+        return array('idnumber'=>$this->_cm->idnumber);
+    }
     /**
      *  This is called from modedit.php to set the default for modvisible form element.
      *
index f363bf11bf4ce42b47b40cbfb46ccf5804c45687..b822924617ab0a793714336a4ded4cd9bc30524e 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="lib/db" VERSION="20070322" COMMENT="XMLDB file for core Moodle tables"
+<XMLDB PATH="lib/db" VERSION="20070411" COMMENT="XMLDB file for core Moodle tables"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="module"/>
         <FIELD NAME="module" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="instance"/>
         <FIELD NAME="instance" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="module" NEXT="section"/>
-        <FIELD NAME="section" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="instance" NEXT="added"/>
-        <FIELD NAME="added" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="section" NEXT="score"/>
+        <FIELD NAME="section" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="instance" NEXT="idnumber"/>
+        <FIELD NAME="idnumber" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="customizable idnumber" PREVIOUS="section" NEXT="added"/>
+        <FIELD NAME="added" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="idnumber" NEXT="score"/>
         <FIELD NAME="score" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="added" NEXT="indent"/>
         <FIELD NAME="indent" TYPE="int" LENGTH="5" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="score" NEXT="visible"/>
         <FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="indent" NEXT="visibleold"/>
         <INDEX NAME="visible" UNIQUE="false" FIELDS="visible" NEXT="course"/>
         <INDEX NAME="course" UNIQUE="false" FIELDS="course" PREVIOUS="visible" NEXT="module"/>
         <INDEX NAME="module" UNIQUE="false" FIELDS="module" PREVIOUS="course" NEXT="instance"/>
-        <INDEX NAME="instance" UNIQUE="false" FIELDS="instance" PREVIOUS="module"/>
+        <INDEX NAME="instance" UNIQUE="false" FIELDS="instance" PREVIOUS="module" NEXT="idnumber"/>
+        <INDEX NAME="idnumber" UNIQUE="true" FIELDS="idnumber" COMMENT="Default comment for the index, please edit me" PREVIOUS="instance"/>
       </INDEXES>
     </TABLE>
     <TABLE NAME="course_sections" COMMENT="to define the sections for each course" PREVIOUS="course_modules" NEXT="course_request">
index c166459be50fc524972e1cbac6b86718deaecb55..d9920551103eea217bbdc7b7fc86707df9a4bbb3 100644 (file)
@@ -691,6 +691,27 @@ function xmldb_main_upgrade($oldversion=0) {
     /// Launch add index text
         $result = $result && add_index($table, $index);       
     }
+    
+    if ($result && $oldversion < 2007041100) {
+
+    /// Define field idnumber to be added to course_modules
+        $table = new XMLDBTable('course_modules');
+        $field = new XMLDBField('idnumber');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '100', null, null, null, null, null, null, 'section');
+    
+    /// Launch add field idnumber
+        $result = $result && add_field($table, $field);
+    
+    /// Define index idnumber (unique) to be added to course_modules
+        $table = new XMLDBTable('course_modules');
+        $index = new XMLDBIndex('idnumber');
+        $index->setAttributes(XMLDB_INDEX_UNIQUE, array('idnumber'));
+
+    /// Launch add index idnumber
+        $result = $result && add_index($table, $index);
+
+    }
+
     return $result;
 
 }
index 28e6e7f4667bf12c895e524723caced83e31fb4c..5a011f8d46f54a648a02622aea570ed807c7c9f2 100644 (file)
@@ -6,7 +6,7 @@
 // This is compared against the values stored in the database to determine
 // whether upgrades should be performed (see lib/db/*.php)
 
-   $version = 2007040400;  // YYYYMMDD = date
+   $version = 2007041100;  // YYYYMMDD = date
                            //       XY = increments within a single day
 
    $release = '1.9 dev';    // Human-friendly version name