diff options
Diffstat (limited to 'engine/classes/ElggExtender.php')
| -rw-r--r-- | engine/classes/ElggExtender.php | 238 |
1 files changed, 42 insertions, 196 deletions
diff --git a/engine/classes/ElggExtender.php b/engine/classes/ElggExtender.php index 707906bac..25aba354f 100644 --- a/engine/classes/ElggExtender.php +++ b/engine/classes/ElggExtender.php @@ -3,8 +3,7 @@ * The base class for ElggEntity extenders. * * Extenders allow you to attach extended information to an - * ElggEntity. Core supports two: ElggAnnotation, ElggMetadata, - * and ElggRelationship + * ElggEntity. Core supports two: ElggAnnotation and ElggMetadata. * * Saving the extender data to database is handled by the child class. * @@ -16,19 +15,29 @@ * @link http://docs.elgg.org/DataModel/Extenders * @see ElggAnnotation * @see ElggMetadata + * + * @property string $type annotation or metadata (read-only after save) + * @property int $id The unique identifier (read-only) + * @property int $entity_guid The GUID of the entity that this extender describes + * @property int $access_id Specifies the visibility level of this extender + * @property string $name The name of this extender + * @property mixed $value The value of the extender (int or string) + * @property int $time_created A UNIX timestamp of when the extender was created (read-only, set on first save) */ -abstract class ElggExtender extends ElggData implements - Exportable, - Loggable, // Can events related to this object class be logged - Iterator, // Override foreach behaviour - ArrayAccess // Override for array access -{ +abstract class ElggExtender extends ElggData { + /** - * Holds attributes to save to database + * (non-PHPdoc) + * + * @see ElggData::initializeAttributes() * - * @var array + * @return void */ - protected $attributes; + protected function initializeAttributes() { + parent::initializeAttributes(); + + $this->attributes['type'] = NULL; + } /** * Returns an attribute @@ -38,7 +47,7 @@ abstract class ElggExtender extends ElggData implements * @return mixed */ protected function get($name) { - if (isset($this->attributes[$name])) { + if (array_key_exists($name, $this->attributes)) { // Sanitise value if necessary if ($name == 'value') { switch ($this->attributes['value_type']) { @@ -53,8 +62,8 @@ abstract class ElggExtender extends ElggData implements break; default : - $msg = sprintf(elgg_echo('InstallationException:TypeNotSupported'), - $this->attributes['value_type']); + $msg = elgg_echo('InstallationException:TypeNotSupported', array( + $this->attributes['value_type'])); throw new InstallationException($msg); break; @@ -85,46 +94,42 @@ abstract class ElggExtender extends ElggData implements } /** - * Return the owner guid of this extender. + * Get the GUID of the extender's owner entity. * - * @return int + * @return int The owner GUID */ - public function getOwner() { + public function getOwnerGUID() { return $this->owner_guid; } /** - * Return the owner entity. + * Return the guid of the entity's owner. * - * @return ElggEntity|false - * @since 1.7.0 + * @return int The owner GUID + * @deprecated 1.8 Use getOwnerGUID */ - public function getOwnerEntity() { - return get_user($this->owner_guid); + public function getOwner() { + elgg_deprecated_notice("ElggExtender::getOwner deprecated for ElggExtender::getOwnerGUID", 1.8); + return $this->getOwnerGUID(); } /** - * Return the entity this describes. + * Get the entity that owns this extender * - * @return ElggEntity The enttiy + * @return ElggEntity */ - public function getEntity() { - return get_entity($this->entity_guid); + public function getOwnerEntity() { + return get_entity($this->owner_guid); } /** - * Save this data to the appropriate database table. + * Get the entity this describes. * - * @return bool + * @return ElggEntity The entity */ - abstract public function save(); - - /** - * Delete this data. - * - * @return bool - */ - abstract public function delete(); + public function getEntity() { + return get_entity($this->entity_guid); + } /** * Returns if a user can edit this extended data. @@ -137,13 +142,6 @@ abstract class ElggExtender extends ElggData implements return can_edit_extender($this->id, $this->type, $user_guid); } - /** - * Return a url for this extender. - * - * @return string - */ - public abstract function getURL(); - /* * EXPORTABLE INTERFACE */ @@ -173,7 +171,7 @@ abstract class ElggExtender extends ElggData implements public function export() { $uuid = get_uuid_from_object($this); - $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], + $meta = new ODDMetaData($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid)); $meta->setAttribute('published', date("r", $this->time_created)); @@ -195,24 +193,6 @@ abstract class ElggExtender extends ElggData implements } /** - * Return the class name of the object. - * - * @return string - */ - public function getClassName() { - return get_class($this); - } - - /** - * Return the GUID of the owner of this object. - * - * @return int - */ - public function getObjectOwnerGUID() { - return $this->owner_guid; - } - - /** * Return a type of extension. * * @return string @@ -231,138 +211,4 @@ abstract class ElggExtender extends ElggData implements return $this->name; } - - /* - * ITERATOR INTERFACE - */ - - /* - * This lets an entity's attributes be displayed using foreach as a normal array. - * Example: http://www.sitepoint.com/print/php5-standard-library - */ - private $valid = FALSE; - - /** - * Iterator interface - * - * @see Iterator::rewind() - * - * @return void - */ - function rewind() { - $this->valid = (FALSE !== reset($this->attributes)); - } - - /** - * Iterator interface - * - * @see Iterator::current() - * - * @return void - */ - function current() { - return current($this->attributes); - } - - /** - * Iterator interface - * - * @see Iterator::key() - * - * @return void - */ - function key() { - return key($this->attributes); - } - - /** - * Iterator interface - * - * @see Iterator::next() - * - * @return void - */ - function next() { - $this->valid = (FALSE !== next($this->attributes)); - } - - /** - * Iterator interface - * - * @see Iterator::valid() - * - * @return void - */ - function valid() { - return $this->valid; - } - - /* - * ARRAY ACCESS INTERFACE - */ - - /* - * This lets an entity's attributes be accessed like an associative array. - * Example: http://www.sitepoint.com/print/php5-standard-library - */ - - /** - * Array access interface - * - * @see ArrayAccess::offsetSet() - * - * @param mixed $key Name - * @param mixed $value Value - * - * @return void - */ - function offsetSet($key, $value) { - if (array_key_exists($key, $this->attributes)) { - $this->attributes[$key] = $value; - } - } - - /** - * Array access interface - * - * @see ArrayAccess::offsetGet() - * - * @param mixed $key Name - * - * @return void - */ - function offsetGet($key) { - if (array_key_exists($key, $this->attributes)) { - return $this->attributes[$key]; - } - } - - /** - * Array access interface - * - * @see ArrayAccess::offsetUnset() - * - * @param mixed $key Name - * - * @return void - */ - function offsetUnset($key) { - if (array_key_exists($key, $this->attributes)) { - // Full unsetting is dangerious for our objects - $this->attributes[$key] = ""; - } - } - - /** - * Array access interface - * - * @see ArrayAccess::offsetExists() - * - * @param int $offset Offset - * - * @return int - */ - function offsetExists($offset) { - return array_key_exists($offset, $this->attributes); - } } |
