From e9d468a10843ab5841ae7ad40eafba0ee0f1363e Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 00:25:29 +0000 Subject: making sure ElggEntity::getAnnotations() returns an array, check if temporary annotation exists before returning, and added a warning about annotating unsaved entities git-svn-id: http://code.elgg.org/elgg/trunk@8990 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggEntity.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'engine/classes/ElggEntity.php') diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index cfdaede71..31885ad25 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -717,6 +717,9 @@ abstract class ElggEntity extends ElggData implements * * @warning By default, annotations are private. * + * @warning Annotating an unsaved entity more than once with the same name + * will only save the last annotation. + * * @param string $name Annotation name * @param mixed $value Annotation value * @param int $access_id Access ID @@ -761,8 +764,10 @@ abstract class ElggEntity extends ElggData implements } return elgg_get_annotations($options); + } else if (isset($this->temp_annotations[$name])) { + return array($this->temp_annotations[$name]); } else { - return $this->temp_annotations[$name]; + return array(); } } -- cgit v1.2.3 From 77f5fce955ecdd66782252c63c1b81e032bd0ee6 Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 14 Apr 2011 00:35:59 +0000 Subject: fixes warnings in ElggEntity::getMetadata() (hellekin) git-svn-id: http://code.elgg.org/elgg/trunk@8992 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggEntity.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'engine/classes/ElggEntity.php') diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 31885ad25..79b8c2a4e 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -246,18 +246,20 @@ abstract class ElggEntity extends ElggData implements * @return mixed The value, or NULL if not found. */ public function getMetaData($name) { - if ((int) ($this->guid) > 0) { - $md = elgg_get_metadata(array( - 'guid' => $this->getGUID(), - 'metadata_name' => $name, - 'limit' => 0, - )); - } else { + if ((int) ($this->guid) == 0) { if (isset($this->temp_metadata[$name])) { return $this->temp_metadata[$name]; + } else { + return null; } } + $md = elgg_get_metadata(array( + 'guid' => $this->getGUID(), + 'metadata_name' => $name, + 'limit' => 0, + )); + if ($md && !is_array($md)) { return $md->value; } elseif (count($md) == 1) { -- cgit v1.2.3