aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggExtender.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes/ElggExtender.php')
-rw-r--r--engine/classes/ElggExtender.php191
1 files changed, 62 insertions, 129 deletions
diff --git a/engine/classes/ElggExtender.php b/engine/classes/ElggExtender.php
index 577207c06..25aba354f 100644
--- a/engine/classes/ElggExtender.php
+++ b/engine/classes/ElggExtender.php
@@ -3,54 +3,70 @@
* 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.
*
* @tip Plugin authors would probably want to extend either ElggAnnotation
* or ElggMetadata instead of this class.
*
- * @package Elgg.Core
+ * @package Elgg.Core
* @subpackage DataModel.Extender
- * @see ElggAnnotation
- * @see ElggMetadata
- * @link http://docs.elgg.org/DataModel/Extenders
+ * @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 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
*
- * @param string $name
+ * @param string $name Name
+ *
* @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') {
+ if ($name == 'value') {
switch ($this->attributes['value_type']) {
case 'integer' :
return (int)$this->attributes['value'];
+ break;
//case 'tag' :
//case 'file' :
case 'text' :
return ($this->attributes['value']);
+ break;
default :
- throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $this->attributes['value_type']));
+ $msg = elgg_echo('InstallationException:TypeNotSupported', array(
+ $this->attributes['value_type']));
+
+ throw new InstallationException($msg);
+ break;
}
}
@@ -62,9 +78,10 @@ abstract class ElggExtender implements
/**
* Set an attribute
*
- * @param string $name
- * @param mixed $value
- * @param string $value_type
+ * @param string $name Name
+ * @param mixed $value Value
+ * @param string $value_type Value type
+ *
* @return boolean
*/
protected function set($name, $value, $value_type = "") {
@@ -77,60 +94,54 @@ abstract class ElggExtender 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.
- */
- abstract public function save();
-
- /**
- * Delete this data.
+ * Get the entity this describes.
+ *
+ * @return ElggEntity The entity
*/
- abstract public function delete();
+ public function getEntity() {
+ return get_entity($this->entity_guid);
+ }
/**
* Returns if a user can edit this extended data.
*
* @param int $user_guid The GUID of the user (defaults to currently logged in user)
+ *
* @return bool
*/
public function canEdit($user_guid = 0) {
- return can_edit_extender($this->id,$this->type,$user_guid);
+ return can_edit_extender($this->id, $this->type, $user_guid);
}
- /**
- * Return a url for this extender.
- *
- * @return string
- */
- public abstract function getURL();
-
/*
* EXPORTABLE INTERFACE
*/
@@ -160,7 +171,8 @@ abstract class ElggExtender implements
public function export() {
$uuid = get_uuid_from_object($this);
- $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 = 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));
return $meta;
@@ -181,24 +193,6 @@ abstract class ElggExtender 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
@@ -217,65 +211,4 @@ abstract class ElggExtender 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;
-
- function rewind() {
- $this->valid = (FALSE !== reset($this->attributes));
- }
-
- function current() {
- return current($this->attributes);
- }
-
- function key() {
- return key($this->attributes);
- }
-
- function next() {
- $this->valid = (FALSE !== next($this->attributes));
- }
-
- 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
- */
- function offsetSet($key, $value) {
- if ( array_key_exists($key, $this->attributes) ) {
- $this->attributes[$key] = $value;
- }
- }
-
- function offsetGet($key) {
- if ( array_key_exists($key, $this->attributes) ) {
- return $this->attributes[$key];
- }
- }
-
- function offsetUnset($key) {
- if ( array_key_exists($key, $this->attributes) ) {
- // Full unsetting is dangerious for our objects
- $this->attributes[$key] = "";
- }
- }
-
- function offsetExists($offset) {
- return array_key_exists($offset, $this->attributes);
- }
}