From 7b31a94e08f818a4eed4e90a6b195929951bc5ce Mon Sep 17 00:00:00 2001 From: stronk7 Date: Wed, 6 Sep 2006 19:31:03 +0000 Subject: [PATCH] Now fields are able to return their PHP specs. --- lib/xmldb/classes/XMLDBField.class.php | 116 ++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 3 deletions(-) diff --git a/lib/xmldb/classes/XMLDBField.class.php b/lib/xmldb/classes/XMLDBField.class.php index 089f6af166..35a3d20dda 100644 --- a/lib/xmldb/classes/XMLDBField.class.php +++ b/lib/xmldb/classes/XMLDBField.class.php @@ -89,7 +89,7 @@ class XMLDBField extends XMLDBObject { /// trim each value quotes $value = trim($value, "'"); /// add them back - $valus = "'" . $value . "'"; + $value = "'" . $value . "'"; $this->enumvalues[] = $value; } } @@ -209,10 +209,19 @@ class XMLDBField extends XMLDBObject { } /** - * Set the field enumvalues + * Set the field enumvalues, quoting unquoted values */ function setEnumValues($enumvalues) { - $this->enumvalues = $enumvalues; + if (is_array($enumvalues)) { + $this->enumvalues = array(); + foreach ($enumvalues as $value) { + /// trim each value quotes + $value = trim($value, "'"); + /// add them back + $value = "'" . $value . "'"; + $this->enumvalues[] = $value; + } + } } /** @@ -708,6 +717,107 @@ class XMLDBField extends XMLDBObject { $this->changed = true; } + /** + * Returns the PHP code needed to define one XMLDBField + */ + function getPHP($includeprevious=true) { + + $result = ''; + + /// The XMLDBTYPE + switch ($this->getType()) { + case XMLDB_TYPE_INTEGER: + $result .= 'XMLDB_TYPE_INTEGER' . ', '; + break; + case XMLDB_TYPE_NUMBER: + $result .= 'XMLDB_TYPE_NUMBER' . ', '; + break; + case XMLDB_TYPE_FLOAT: + $result .= 'XMLDB_TYPE_FLOAT' . ', '; + break; + case XMLDB_TYPE_CHAR: + $result .= 'XMLDB_TYPE_CHAR' . ', '; + break; + case XMLDB_TYPE_TEXT: + $result .= 'XMLDB_TYPE_TEXT' . ', '; + break; + case XMLDB_TYPE_BINARY: + $result .= 'XMLDB_TYPE_BINARY' . ', '; + break; + case XMLDB_TYPE_DATETIME: + $result .= 'XMLDB_TYPE_DATETIME' . ', '; + break; + case XMLDB_TYPE_TIMESTAMP: + $result .= 'XMLDB_TYPE_TIMESTAMP' . ', '; + break; + } + /// The length + $length = $this->getLength(); + $decimals = $this->getDecimals(); + if (!empty($length)) { + $result .= "'" . $length; + if (!empty($decimals)) { + $result .= ', ' . $decimals; + } + $result .= "', "; + } else { + $result .= 'null, '; + } + /// Unsigned + $unsigned = $this->getUnsigned(); + if (!empty($unsigned)) { + $result .= 'XMLDB_UNSIGNED' . ', '; + } else { + $result .= 'null, '; + } + /// Not Null + $notnull = $this->getNotnull(); + if (!empty($notnull)) { + $result .= 'XMLDB_NOTNULL' . ', '; + } else { + $result .= 'null, '; + } + /// Sequence + $sequence = $this->getSequence(); + if (!empty($sequence)) { + $result .= 'XMLDB_SEQUENCE' . ', '; + } else { + $result .= 'null, '; + } + /// Enum + $enum = $this->getEnum(); + if (!empty($enum)) { + $result .= 'XMLDB_ENUM' . ', '; + } else { + $result .= 'null, '; + } + /// Enumvalues + $enumvalues = $this->getEnumValues(); + if (!empty($enumvalues)) { + $result .= 'array(' . implode(', ', $enumvalues) . '), '; + } else { + $result .= 'null, '; + } + /// Default + $default = $this->getDefault(); + if (!$default !== null & !$this->getSequence()) { + $result .= "'" . $default . "'"; + } else { + $result .= 'null'; + } + /// Previous (decided by parameter) + if ($includeprevious) { + $previous = $this->getPrevious(); + if (!empty($previous)) { + $result .= ", '" . $previous . "'"; + } else { + $result .= ', null'; + } + } + /// Return result + return $result; + } + /** * Shows info in a readable format */ -- 2.39.5