From faf7ee8690c1ede38c4bd85c722de8e3012eb584 Mon Sep 17 00:00:00 2001 From: icewing Date: Tue, 8 Apr 2008 17:34:21 +0000 Subject: Marcus Povey * Simplified extender types, now only supports integer and text - types deamed not to be necessary (yet), also simplifies import and export. * Types better detected. git-svn-id: https://code.elgg.org/elgg/trunk@424 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/annotations.php | 21 --------------------- engine/lib/extender.php | 34 ++++++++++++++++++++++++++++++---- engine/lib/metadata.php | 22 +--------------------- engine/schema/mysql.sql | 4 ++-- 4 files changed, 33 insertions(+), 48 deletions(-) (limited to 'engine') diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index c71d235f8..68c9bfc22 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -116,27 +116,6 @@ return new ElggAnnotation($row); } - /** - * Detect the value_type for a given value. - * Currently this is very crude. - * - * TODO: Make better! - * - * @param mixed $value - * @param string $value_type If specified, overrides the detection. - * @return string - */ - function detect_annotation_valuetype($value, $value_type = "") - { - if ($value_type!="") - return $value_type; - - // This is crude - if (is_int($value)) return 'integer'; - - return 'tag'; - } - /** * Get a specific annotation. * diff --git a/engine/lib/extender.php b/engine/lib/extender.php index 26166a225..5a5d29e08 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -41,9 +41,9 @@ switch ($this->attributes['value_type']) { case 'integer' : return (int)$this->attributes['value']; - case 'tag' : - case 'text' : - case 'file' : return sanitise_string($this->attributes['value']); + //case 'tag' : + //case 'file' : + case 'text' : return sanitise_string($this->attributes['value']); default : throw new InstallationException("Type {$this->attributes['value_type']} is not supported. This indicates an error in your installation, most likely caused by an incomplete upgrade."); } @@ -59,10 +59,14 @@ * * @param string $name * @param mixed $value + * @param string $value_type * @return boolean */ - protected function set($name, $value) { + protected function set($name, $value, $value_type = "") { + $this->attributes[$name] = $value; + $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type); + return true; } @@ -162,6 +166,28 @@ } } + /** + * Detect the value_type for a given value. + * Currently this is very crude. + * + * TODO: Make better! + * + * @param mixed $value + * @param string $value_type If specified, overrides the detection. + * @return string + */ + function detect_extender_valuetype($value, $value_type = "") + { + if ($value_type!="") + return $value_type; + + // This is crude + if (is_int($value)) return 'integer'; + if (is_numeric($value)) return 'integer'; + + return 'text'; + } + /** * Handler called by trigger_plugin_hook on the "import" event. */ diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 65b2a9d40..76c953c85 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -112,27 +112,7 @@ return new ElggMetadata($row); } - - /** - * Detect the value_type for a given value. - * Currently this is very crude. - * - * TODO: Make better! - * - * @param mixed $value - * @param string $value_type If specified, overrides the detection. - * @return string - */ - function detect_metadata_valuetype($value, $value_type = "") - { - if ($value_type!="") - return $value_type; - - // This is crude - if (is_int($value)) return 'integer'; - - return 'tag'; - } + /** * Get a specific item of metadata. diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index ea10ccf6c..9cd51c30e 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -147,7 +147,7 @@ CREATE TABLE `prefix_annotations` ( `name_id` int(11) NOT NULL, `value_id` int(11) NOT NULL, - `value_type` enum ('integer','tag','text','file') NOT NULL, + `value_type` enum ('integer','text') NOT NULL, `owner_guid` bigint(20) unsigned NOT NULL, `access_id` int(11) NOT NULL, @@ -165,7 +165,7 @@ CREATE TABLE `prefix_metadata` ( `name_id` int(11) NOT NULL, `value_id` int(11) NOT NULL, - `value_type` enum ('integer','tag','text','file') NOT NULL, + `value_type` enum ('integer','text') NOT NULL, `owner_guid` bigint(20) unsigned NOT NULL, `access_id` int(11) NOT NULL, -- cgit v1.2.3