diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-21 14:44:02 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-05-21 14:44:02 +0000 |
commit | 48274a3bb170696c1514db0a3e0fc9484c2d495a (patch) | |
tree | 49b8bbf0dfcb9b05a061c6d07b3d5057f8bd5d67 | |
parent | 693ef1e69a4c0903074a0344b8218b3c5739ebe7 (diff) | |
download | elgg-48274a3bb170696c1514db0a3e0fc9484c2d495a.tar.gz elgg-48274a3bb170696c1514db0a3e0fc9484c2d495a.tar.bz2 |
Metadata can now be added to before an entity is saved. It will be added to the db on save.
git-svn-id: https://code.elgg.org/elgg/trunk@667 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/entities.php | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 2cadf199c..850da0008 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -31,7 +31,8 @@ * Subclasses should add to this in their constructors. * Any field not appearing in this will be viewed as a */ - protected $attributes; + protected $attributes;
+ protected $temp_metadata; /** * Initialise the attributes array. @@ -45,6 +46,7 @@ { // Create attributes array if not already created if (!is_array($this->attributes)) $this->attributes = array(); + if (!is_array($this->temp_metadata)) $this->temp_metadata = array();
$this->attributes['guid'] = ""; $this->attributes['type'] = ""; @@ -74,10 +76,15 @@ return $this->attributes[$name]; } - // No, so see if its in the meta data for this entity - $meta = $this->getMetaData($name); - if ($meta) - return $meta; + // No, so see if its in the meta data for this entity
+ if (isset($this->guid)) { + $meta = $this->getMetaData($name); + if ($meta) + return $meta;
+ } else {
+ if (isset($this->temp_metadata[$name]))
+ return $this->temp_metadata[$name];
+ } // Can't find it, so return null return null; @@ -108,8 +115,11 @@ $this->attributes[$name] = $value; } - else - return $this->setMetaData($name, $value); + else if (isset($this->guid)) { + return $this->setMetaData($name, $value);
+ } else {
+ $this->temp_metadata[$name] = $value;
+ } return true; } @@ -371,6 +381,14 @@ { $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id']); // Create a new entity (nb: using attribute array directly 'cos set function does something special!) if (!$this->attributes['guid']) throw new IOException("Unable to save new object's base entity information!"); +
+ // Save any unsaved metadata
+ if (sizeof($this->temp_metadata) > 0) {
+ foreach($this->temp_metadata as $name => $value) {
+ $this->$name = $value;
+ unset($this->temp_metadata[$name]);
+ }
+ }
return $this->attributes['guid']; } |