From 1ad3a9ab1696958ffe513d915047d2962c0144ef Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 5 Feb 2011 17:11:31 +0000 Subject: supporting private settings before an entity is saved git-svn-id: http://code.elgg.org/elgg/trunk@8032 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggEntity.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 100d882e5..21aa72561 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -54,6 +54,12 @@ abstract class ElggEntity extends ElggData implements */ protected $temp_annotations = array(); + /** + * Holds private settings until entity is saved. Once the entity is saved, + * private settings are written immediately to the database. + */ + protected $temp_private_settings = array(); + /** * Volatile data structure for this object, allows for storage of data * in-memory that isn't sync'd back to the metadata table. @@ -438,7 +444,12 @@ abstract class ElggEntity extends ElggData implements * @link http://docs.elgg.org/DataModel/Entities/PrivateSettings */ function setPrivateSetting($name, $value) { - return set_private_setting($this->getGUID(), $name, $value); + if ((int) $this->guid > 0) { + return set_private_setting($this->getGUID(), $name, $value); + } else { + $this->temp_private_settings[$name] = $value; + return true; + } } /** @@ -449,7 +460,14 @@ abstract class ElggEntity extends ElggData implements * @return mixed */ function getPrivateSetting($name) { - return get_private_setting($this->getGUID(), $name); + if ((int) ($this->guid) > 0) { + return get_private_setting($this->getGUID(), $name); + } else { + if (isset($this->temp_private_settings[$name])) { + return $this->temp_private_settings[$name]; + } + } + return null; } /** @@ -861,9 +879,9 @@ abstract class ElggEntity extends ElggData implements } /** - * Save attributes to the entities table. + * Save an entity. * - * @return bool + * @return bool/int * @throws IOException */ public function save() { @@ -898,8 +916,7 @@ abstract class ElggEntity extends ElggData implements } } - // Save any unsaved annotations metadata. - // @todo How to capture extra information (access id etc) + // Save any unsaved annotations. if (sizeof($this->temp_annotations) > 0) { foreach ($this->temp_annotations as $name => $value) { $this->annotate($name, $value); @@ -907,6 +924,14 @@ abstract class ElggEntity extends ElggData implements } } + // Save any unsaved private settings. + if (sizeof($this->temp_private_settings) > 0) { + foreach ($this->temp_private_settings as $name => $value) { + $this->setPrivateSetting($name, $value); + unset($this->temp_private_settings[$name]); + } + } + // set the subtype to id now rather than a string $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']); -- cgit v1.2.3