From 4e08e618308d7dedfd3983d015950c81e7403e29 Mon Sep 17 00:00:00 2001 From: icewing Date: Tue, 1 Apr 2008 17:15:12 +0000 Subject: Marcus Povey * Moved common functionality of metadata and annotations into superclass. git-svn-id: https://code.elgg.org/elgg/trunk@323 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metadata.php | 70 ++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 56 deletions(-) (limited to 'engine/lib/metadata.php') diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 82ca71bdd..573ea8f4f 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -16,14 +16,9 @@ * This class describes metadata that can be attached to ElggEntities. * @author Marcus Povey */ - class ElggMetadata implements Exportable + class ElggMetadata extends ElggExtender { - /** - * This contains the site's main properties (id, etc) - * @var array - */ - private $attributes; - + /** * Construct a new site object, optionally from a given id value or row. * @@ -50,40 +45,11 @@ } function __get($name) { - if (isset($this->attributes[$name])) { - - // Sanitise value if necessary - if ($name=='value') - { - switch ($this->attributes['value_type']) - { - case 'integer' : return (int)$this->attributes['value']; - case 'tag' : - case 'text' : - case 'file' : 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."); - } - } - - return $this->attributes[$name]; - } - return null; + return $this->get($name); } function __set($name, $value) { - $this->attributes[$name] = $value; - return true; - } - - /** - * Return the owner of this metadata. - * - * @return mixed - */ - function getOwner() - { - return get_user($this->owner_guid); + return $this->set($name, $value); } function save() @@ -107,13 +73,6 @@ return delete_metadata($this->id); } - public function export() - { - $tmp = new stdClass; - $tmp->attributes = $this->attributes; - $tmp->attributes['owner_uuid'] = guid_to_uuid($this->owner_guid); - return $tmp; - } } @@ -394,22 +353,21 @@ if (!is_array($returnvalue)) throw new InvalidParameterException("Entity serialisation function passed a non-array returnvalue parameter"); - - $guid = (int)$params['guid']; - // Get the metadata for the entity - $metadata = get_metadata_for_entity($guid); + $guid = (int)$params['guid']; + $name = $params['name']; - if ($metadata) + $result = get_metadata_for_entity($guid); + + if ($result) { - foreach ($metadata as $m) - $returnvalue[] = $m; - } - + foreach ($result as $r) + $returnvalue[] = $r; + } + return $returnvalue; } - /** Register the hook, ensuring entities are serialised first */ + /** Register the hook */ register_plugin_hook("export", "all", "export_metadata_plugin_hook", 2); - ?> \ No newline at end of file -- cgit v1.2.3