diff options
author | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-05 17:11:31 +0000 |
---|---|---|
committer | cash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-05 17:11:31 +0000 |
commit | 1ad3a9ab1696958ffe513d915047d2962c0144ef (patch) | |
tree | 49381c7257efd8cafd63e0c34f8e32ec0d9c8392 | |
parent | 43e89eedf4faff3ee13973caebc2714736d5b362 (diff) | |
download | elgg-1ad3a9ab1696958ffe513d915047d2962c0144ef.tar.gz elgg-1ad3a9ab1696958ffe513d915047d2962c0144ef.tar.bz2 |
supporting private settings before an entity is saved
git-svn-id: http://code.elgg.org/elgg/trunk@8032 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/classes/ElggEntity.php | 37 |
1 files 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 @@ -55,6 +55,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']); |