diff options
Diffstat (limited to 'engine/classes/ElggData.php')
| -rw-r--r-- | engine/classes/ElggData.php | 133 |
1 files changed, 102 insertions, 31 deletions
diff --git a/engine/classes/ElggData.php b/engine/classes/ElggData.php index 97c33bbb5..4f843cde4 100644 --- a/engine/classes/ElggData.php +++ b/engine/classes/ElggData.php @@ -1,11 +1,21 @@ <?php +/** + * A generic class that contains shared code b/w + * ElggExtender, ElggEntity, and ElggRelationship + * + * @package Elgg.Core + * @subpackage DataModel + * + * @property int $owner_guid + * @property int $time_created + */ abstract class ElggData implements Loggable, // Can events related to this object class be logged Iterator, // Override foreach behaviour ArrayAccess, // Override for array access Exportable { - + /** * The main attributes of an entity. * Holds attributes to save to database @@ -15,7 +25,28 @@ abstract class ElggData implements * Any field not appearing in this will be viewed as a */ protected $attributes = array(); - + + // @codingStandardsIgnoreStart + /** + * Initialise the attributes array. + * + * This is vital to distinguish between metadata and base parameters. + * + * @param bool $pre18_api Compatibility for subclassing in 1.7 -> 1.8 change. + * Passing true (default) emits a deprecation notice. + * Passing false returns false. Core constructors always pass false. + * Does nothing either way since attributes are initialized by the time + * this is called. + * @return void + * @deprecated 1.8 Use initializeAttributes() + */ + protected function initialise_attributes($pre18_api = true) { + if ($pre18_api) { + elgg_deprecated_notice('initialise_attributes() is deprecated by initializeAttributes()', 1.8); + } + } + // @codingStandardsIgnoreEnd + /** * Initialize the attributes array. * @@ -28,17 +59,72 @@ abstract class ElggData implements if (!is_array($this->attributes)) { $this->attributes = array(); } - - $this->attributes['time_created'] = ''; + + $this->attributes['time_created'] = NULL; } - + + /** + * Return an attribute or a piece of metadata. + * + * @param string $name Name + * + * @return mixed + */ + public function __get($name) { + return $this->get($name); + } + + /** + * Set an attribute or a piece of metadata. + * + * @param string $name Name + * @param mixed $value Value + * + * @return mixed + */ + public function __set($name, $value) { + return $this->set($name, $value); + } + + /** + * Test if property is set either as an attribute or metadata. + * + * @tip Use isset($entity->property) + * + * @param string $name The name of the attribute or metadata. + * + * @return bool + */ + function __isset($name) { + return $this->$name !== NULL; + } + + /** + * Fetch the specified attribute + * + * @param string $name The attribute to fetch + * + * @return mixed The attribute, if it exists. Otherwise, null. + */ + abstract protected function get($name); + + /** + * Set the specified attribute + * + * @param string $name The attribute to set + * @param mixed $value The value to set it to + * + * @return bool The success of your set function? + */ + abstract protected function set($name, $value); + /** * Get a URL for this object - * + * * @return string */ abstract public function getURL(); - + /** * Save this data to the appropriate database table. * @@ -52,26 +138,8 @@ abstract class ElggData implements * @return bool */ abstract public function delete(); - - /** - * Return the guid of the entity's owner. - * - * @return int The owner GUID - */ - public function getOwner() { - return $this->owner_guid; - } /** - * Returns the ElggEntity or child object of the owner of the entity. - * - * @return ElggEntity The owning user - */ - public function getOwnerEntity() { - return get_entity($this->owner_guid); - } - - /** * Returns the UNIX epoch time that this entity was created * * @return int UNIX epoch time @@ -79,7 +147,7 @@ abstract class ElggData implements public function getTimeCreated() { return $this->time_created; } - + /* * SYSTEM LOG INTERFACE */ @@ -97,8 +165,10 @@ abstract class ElggData implements * Return the GUID of the owner of this object. * * @return int + * @deprecated 1.8 Use getOwnerGUID() instead */ public function getObjectOwnerGUID() { + elgg_deprecated_notice("getObjectOwnerGUID() was deprecated. Use getOwnerGUID().", 1.8); return $this->owner_guid; } @@ -128,7 +198,7 @@ abstract class ElggData implements * * @see Iterator::current() * - * @return void + * @return mixed */ public function current() { return current($this->attributes); @@ -139,7 +209,7 @@ abstract class ElggData implements * * @see Iterator::key() * - * @return void + * @return string */ public function key() { return key($this->attributes); @@ -161,7 +231,7 @@ abstract class ElggData implements * * @see Iterator::valid() * - * @return void + * @return bool */ public function valid() { return $this->valid; @@ -199,12 +269,13 @@ abstract class ElggData implements * * @param mixed $key Name * - * @return void + * @return mixed */ public function offsetGet($key) { if (array_key_exists($key, $this->attributes)) { return $this->attributes[$key]; } + return null; } /** @@ -235,4 +306,4 @@ abstract class ElggData implements public function offsetExists($offset) { return array_key_exists($offset, $this->attributes); } -}
\ No newline at end of file +} |
