From 7c8bad89d27b18668622db2a36752653d3f3789c Mon Sep 17 00:00:00 2001 From: ewinslow Date: Sun, 31 Oct 2010 00:33:58 +0000 Subject: Improved initializeAttributes implementations git-svn-id: http://code.elgg.org/elgg/trunk@7159 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggAnnotation.php | 10 +++++++--- engine/classes/ElggData.php | 28 +++++++++++++++++++++++++++- engine/classes/ElggEntity.php | 5 ----- engine/classes/ElggExtender.php | 19 +++++-------------- engine/classes/ElggMetadata.php | 10 ++++++++-- engine/classes/ElggRelationship.php | 2 +- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/engine/classes/ElggAnnotation.php b/engine/classes/ElggAnnotation.php index cdcfe363f..d99f5fc9a 100644 --- a/engine/classes/ElggAnnotation.php +++ b/engine/classes/ElggAnnotation.php @@ -14,13 +14,19 @@ */ class ElggAnnotation extends ElggExtender { + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['type'] = 'annotation'; + } + /** * Construct a new annotation, optionally from a given id value or db object. * * @param mixed $id The annotation ID */ function __construct($id = null) { - $this->attributes = array(); + $this->initializeAttributes(); if (!empty($id)) { if ($id instanceof stdClass) { @@ -35,8 +41,6 @@ class ElggAnnotation extends ElggExtender { foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } - - $this->attributes['type'] = "annotation"; } } } diff --git a/engine/classes/ElggData.php b/engine/classes/ElggData.php index fbc11881a..e465913ef 100644 --- a/engine/classes/ElggData.php +++ b/engine/classes/ElggData.php @@ -15,8 +15,20 @@ abstract class ElggData implements */ protected $attributes = array(); + /** + * Initialize the attributes array. + * + * This is vital to distinguish between metadata and base parameters. + * + * @return void + */ protected function initializeAttributes() { - $this->attributes['time_created'] = time(); + // Create attributes array if not already created + if (!is_array($this->attributes)) { + $this->attributes = array(); + } + + $this->attributes['time_created'] = ''; } /** @@ -26,6 +38,20 @@ abstract class ElggData implements */ abstract public function getURL(); + /** + * Save this data to the appropriate database table. + * + * @return bool + */ + abstract public function save(); + + /** + * Delete this data. + * + * @return bool + */ + abstract public function delete(); + /** * Return the guid of the entity's owner. * diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 86bf0727f..571ef890f 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -86,10 +86,6 @@ abstract class ElggEntity extends ElggData implements protected function initializeAttributes() { initialise_entity_cache(); - // 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(); } @@ -109,7 +105,6 @@ abstract class ElggEntity extends ElggData implements $this->attributes['site_guid'] = 0; $this->attributes['access_id'] = ACCESS_PRIVATE; - $this->attributes['time_created'] = ""; $this->attributes['time_updated'] = ""; $this->attributes['last_action'] = ''; $this->attributes['enabled'] = "yes"; diff --git a/engine/classes/ElggExtender.php b/engine/classes/ElggExtender.php index d9a6a52ef..380ba48f5 100644 --- a/engine/classes/ElggExtender.php +++ b/engine/classes/ElggExtender.php @@ -20,6 +20,11 @@ abstract class ElggExtender extends ElggData implements Exportable { + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['type'] = ''; + } /** * Returns an attribute @@ -84,20 +89,6 @@ abstract class ElggExtender extends ElggData implements return get_entity($this->entity_guid); } - /** - * Save this data to the appropriate database table. - * - * @return bool - */ - abstract public function save(); - - /** - * Delete this data. - * - * @return bool - */ - abstract public function delete(); - /** * Returns if a user can edit this extended data. * diff --git a/engine/classes/ElggMetadata.php b/engine/classes/ElggMetadata.php index 851397a93..24365d4d9 100644 --- a/engine/classes/ElggMetadata.php +++ b/engine/classes/ElggMetadata.php @@ -8,6 +8,13 @@ * @subpackage Metadata */ class ElggMetadata extends ElggExtender { + + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['type'] = "metadata"; + } + /** * Construct a new site object, optionally from a given id value or row. * @@ -16,7 +23,7 @@ class ElggMetadata extends ElggExtender { * @return void */ function __construct($id = null) { - $this->attributes = array(); + $this->initializeAttributes(); if (!empty($id)) { // Create from db row @@ -31,7 +38,6 @@ class ElggMetadata extends ElggExtender { foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } - $this->attributes['type'] = "metadata"; } } } diff --git a/engine/classes/ElggRelationship.php b/engine/classes/ElggRelationship.php index 4dcdb6297..c14319d35 100644 --- a/engine/classes/ElggRelationship.php +++ b/engine/classes/ElggRelationship.php @@ -16,7 +16,7 @@ class ElggRelationship extends ElggData implements * @param mixed $id ElggRelationship id */ function __construct($id = null) { - $this->attributes = array(); + $this->initializeAttributes(); if (!empty($id)) { if ($id instanceof stdClass) { -- cgit v1.2.3