]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Improved initializeAttributes implementations
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 31 Oct 2010 00:33:58 +0000 (00:33 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sun, 31 Oct 2010 00:33:58 +0000 (00:33 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7159 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggAnnotation.php
engine/classes/ElggData.php
engine/classes/ElggEntity.php
engine/classes/ElggExtender.php
engine/classes/ElggMetadata.php
engine/classes/ElggRelationship.php

index cdcfe363f30e13e318f3d3c772020a3d280e4ed4..d99f5fc9a6af135137b08d2bd2db54f15ab0e110 100644 (file)
  */
 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";
                        }
                }
        }
index fbc11881a22512ef82095735e4f4562260900a56..e465913ef4756fc910ccdb39c8a41ad2bc17aed5 100644 (file)
@@ -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.
         *
index 86bf0727f7173707c203b71b53511df50b60e668..571ef890f22a889bc3b18da20c20403db4f19535 100644 (file)
@@ -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";
index d9a6a52ef6fd191e898059442a8cc71de0bfa09c..380ba48f5c3500fd1c582371638208c427650cd6 100644 (file)
 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.
         *
index 851397a930c164c8f0f8d3baa9f147e5f4bfd631..24365d4d929ad2b29f0b60d8383ae9df51e01a08 100644 (file)
@@ -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";
                        }
                }
        }
index 4dcdb6297bfeb481c8a960b1b445f7486e02bcf0..c14319d358273236d39694d7a078f885c574af3e 100644 (file)
@@ -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) {