]> git.mjollnir.org Git - moodle.git/commitdiff
Added one-pass-setters for fields/keys/indexes.
authorstronk7 <stronk7>
Sat, 2 Sep 2006 23:51:39 +0000 (23:51 +0000)
committerstronk7 <stronk7>
Sat, 2 Sep 2006 23:51:39 +0000 (23:51 +0000)
lib/xmldb/classes/XMLDBField.class.php
lib/xmldb/classes/XMLDBIndex.class.php
lib/xmldb/classes/XMLDBKey.class.php

index 1f484d70a93f4323cebc546c1cdd363dc6b9af3f..089f6af166c467f14ade5c2928eb3bf7d4b6b9fa 100644 (file)
@@ -54,6 +54,48 @@ class XMLDBField extends XMLDBObject {
         $this->decimals = NULL;
     }
 
+    /**
+     * Set all the attributes of one XMLDBField
+     *
+     * @param string type XMLDB_TYPE_INTEGER, XMLDB_TYPE_NUMBER, XMLDB_TYPE_CHAR, XMLDB_TYPE_TEXT, XMLDB_TYPE_BINARY
+     * @param string precision length for integers and chars, two-comma separated numbers for numbers and 'small', 'medium', 'big' for texts and binaries
+     * @param string unsigned XMLDB_UNSIGNED or null (or false)
+     * @param string notnull XMLDB_NOTNULL or null (or false)
+     * @param string sequence XMLDB_SEQUENCE or null (or false)
+     * @param string enum XMLDB_ENUM or null (or false)
+     * @param array enumvalues an array of possible values if XMLDB_ENUM is set
+     * @param string default meaningful default o null (or false)
+     */
+    function setAttributes($type, $precision=null, $unsigned=null, $notnull=null, $sequence=null, $enum=null, $enumvalues=null, $default=null, $previous=null) {
+        $this->type = $type;
+    /// Try to split the precision into length and decimals and apply
+    /// each one as needed
+        $precisionarr = explode(',', $precision);
+        if (isset($precisionarr[0])) {
+            $this->length = trim($precisionarr[0]);
+        }
+        if (isset($precisionarr[1])) {
+            $this->decimals = trim($precisionarr[1]);
+        }
+        $this->precision = $type;
+        $this->unsigned = !empty($unsigned) ? true : false;
+        $this->notnull = !empty($notnull) ? true : false;
+        $this->sequence = !empty($secuence) ? true : false;
+        $this->enum = !empty($enum) ? true : false;
+    /// Accept both quoted and non-quoted vales (quoting them)a
+        if (is_array($enumvalues)) {
+            $this->enumvalues = array();
+            foreach ($enumvalues as $value) {
+            /// trim each value quotes
+                $value = trim($value, "'");
+            /// add them back
+                $valus = "'" . $value . "'";
+                $this->enumvalues[] = $value;
+            }
+        }
+        $this->default = $default;
+    }
+
     /**
      * Get the type
      */
index 2fa8947e1f27c0f398ae9fbc07ca5ddad0ae7729..33d5e18f1fa00209464adca54f5b55586bab0ced 100644 (file)
@@ -40,19 +40,30 @@ class XMLDBIndex extends XMLDBObject {
         $this->fields = array();
     }
 
-     /**
-      * Get the index unique
-      */
-     function getUnique() {
-         return $this->unique;
-     }
-
-     /**
-      * Set the index unique
-      */
-     function setUnique($unique = true) {
-         $this->unique = $unique;
-     }
+    /**
+     * Set all the attributes of one XMLDBIndex
+     *
+     * @param string type XMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
+     * @param array fields an array of fieldnames to build the index over
+     */
+    function setAttributes($type, $fields) {
+        $this->type = !empty($type) ? true : false;
+        $this->fields = $fields;
+    }
+
+    /**
+     * Get the index unique
+     */
+    function getUnique() {
+        return $this->unique;
+    }
+
+    /**
+     * Set the index unique
+     */
+    function setUnique($unique = true) {
+        $this->unique = $unique;
+    }
 
     /**
      * Set the index fields
index 61f74d63094766cf02f09c875297bab1f1db8e49..8607f4025d547f583cf3bc99dae5009e4fd02f2f 100644 (file)
@@ -44,6 +44,21 @@ class XMLDBKey extends XMLDBObject {
         $this->reffields = array();
     }
 
+    /**
+     * Set all the attributes of one XMLDBKey
+     *
+     * @param string type XMLDB_KEY_PRIMARY, XMLDB_KEY_UNIQUE, XMLDB_KEY_FOREIGN
+     * @param array fields an array of fieldnames to build the key over
+     * @param string reftable name of the table the FK points to or null
+     * @param array reffields an array of fieldnames in the FK table or null
+     */
+    function setAttributes($type, $fields, $reftable=null, $reffields=null) {
+        $this->type = $type;
+        $this->fields = $fields;
+        $this->reftable = $reftable;
+        $this->reffields = $reffields;
+    }
+
     /**
      * Get the key type
      */