From 1e727b299b533535ba2351a6a96d6e05f3c3a34c Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 17 Feb 2008 17:22:42 +0000 Subject: Further metadata and ElggObject updates. git-svn-id: https://code.elgg.org/elgg/trunk@47 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/objects.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/engine/lib/objects.php b/engine/lib/objects.php index 734cc2b3f..7cf58a848 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -275,6 +275,32 @@ } } + /** + * Returns the value of a particular piece of metadata on an object + * + * @param string $metadata_name The name of the metadata + * @param int $object_id The object ID + * @param int $site_id The site ID, optionally + * @return mixed The value of the metadata + */ + function get_object_metadata($metadata_name, $object_id, $site_id = 0) { + + if ($type_id = get_metadata_type_id($metadata_name)) { + + $accesslist = get_access_list(); + $object_id = (int) $objet_id; + if ($site_id == 0) $site_id = $CONFIG->site_id; + $site_id = (int) $site_id; + + if ($result = get_data_row("select mv.value from object_metadata om left join metadata_value mv on mv.id = om.value_id where om.object_id = {$object_id} and om.site_id = {$site_id} and om.metadata_type_id = {$type_id}")) { + return $result->value; + } + return false; + + } + + } + /** * Removes a piece of (or all) metadata for a particular object. * @@ -333,6 +359,20 @@ } } + /** + * Saves this object as a new object in the database. + * Note that if you use this on an already-saved object, it will create a new copy. + * + * @return true|false Depending on success. + */ + function saveNew() { + if ($id = create_object($this->title,$this->description,$this->type,$this->owner_id,$this->access_id,$this->site_id)) { + $this->id = $id; + return true; + } + return false; + } + /** * Updates an object and provides an alias to update_object * @@ -374,6 +414,19 @@ } return false; } + + /** + * Returns the value of a particular piece of metadata + * + * @param string $name The name of the metadata + * @return mixed|false The metadata value; false on failure + */ + function getMetadata($name) { + if (!empty($this->id)) { + return get_object_metadata($name, $this->id, $this->site_id); + } + return false; + } /** * Clears metadata for this object, either for a particular type or across the board -- cgit v1.2.3