diff options
Diffstat (limited to 'engine/classes/ElggRelationship.php')
| -rw-r--r-- | engine/classes/ElggRelationship.php | 150 |
1 files changed, 48 insertions, 102 deletions
diff --git a/engine/classes/ElggRelationship.php b/engine/classes/ElggRelationship.php index f90c1bb50..d2e88882a 100644 --- a/engine/classes/ElggRelationship.php +++ b/engine/classes/ElggRelationship.php @@ -2,29 +2,26 @@ /** * Relationship class. * - * @package Elgg.Core + * @package Elgg.Core * @subpackage Core + * + * @property int $id The unique identifier (read-only) + * @property int $guid_one The GUID of the subject of the relationship + * @property string $relationship The name of the relationship + * @property int $guid_two The GUID of the object of the relationship + * @property int $time_created A UNIX timestamp of when the relationship was created (read-only, set on first save) */ -class ElggRelationship implements - Importable, - Exportable, - Loggable, // Can events related to this object class be logged - Iterator, // Override foreach behaviour - ArrayAccess // Override for array access - { - /** - * This contains the site's main properties (id, etc) - * @var array - */ - protected $attributes; +class ElggRelationship extends ElggData implements + Importable +{ /** - * Construct a new site object, optionally from a given id value or row. + * Create a relationship object, optionally from a given id value or row. * - * @param mixed $id + * @param mixed $id ElggRelationship id, database row, or null for new relationship */ function __construct($id = null) { - $this->attributes = array(); + $this->initializeAttributes(); if (!empty($id)) { if ($id instanceof stdClass) { @@ -35,7 +32,7 @@ class ElggRelationship implements if ($relationship) { $objarray = (array) $relationship; - foreach($objarray as $key => $value) { + foreach ($objarray as $key => $value) { $this->attributes[$key] = $value; } } @@ -45,11 +42,12 @@ class ElggRelationship implements /** * Class member get overloading * - * @param string $name + * @param string $name Name + * * @return mixed */ - function __get($name) { - if (isset($this->attributes[$name])) { + function get($name) { + if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } @@ -59,11 +57,12 @@ class ElggRelationship implements /** * Class member set overloading * - * @param string $name - * @param mixed $value + * @param string $name Name + * @param mixed $value Value + * * @return mixed */ - function __set($name, $value) { + function set($name, $value) { $this->attributes[$name] = $value; return true; } @@ -72,6 +71,7 @@ class ElggRelationship implements * Save the relationship * * @return int the relationship id + * @throws IOException */ public function save() { if ($this->id > 0) { @@ -80,7 +80,7 @@ class ElggRelationship implements $this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two); if (!$this->id) { - throw new IOException(sprintf(elgg_echo('IOException:UnableToSaveNew'), get_class())); + throw new IOException(elgg_echo('IOException:UnableToSaveNew', array(get_class()))); } return $this->id; @@ -88,6 +88,8 @@ class ElggRelationship implements /** * Delete a given relationship. + * + * @return bool */ public function delete() { return delete_relationship($this->id); @@ -106,6 +108,8 @@ class ElggRelationship implements /** * Return an array of fields which can be exported. + * + * @return array */ public function getExportableValues() { return array( @@ -139,13 +143,13 @@ class ElggRelationship implements /** * Import a relationship * - * @param array $data - * @param int $version - * @return ElggRelationship - * @throws ImportException + * @param ODD $data ODD data + + * @return bool + * @throws ImportException|InvalidParameterException */ public function import(ODD $data) { - if (!($element instanceof ODDRelationship)) { + if (!($data instanceof ODDRelationship)) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:UnexpectedODDClass')); } @@ -170,12 +174,14 @@ class ElggRelationship implements // save $result = $this->save(); if (!$result) { - throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), get_class())); + throw new ImportException(elgg_echo('ImportException:ProblemSaving', array(get_class()))); } - return $this; + return true; } } + + return false; } // SYSTEM LOG INTERFACE //////////////////////////////////////////////////////////// @@ -191,95 +197,35 @@ class ElggRelationship implements } /** - * Return the class name of the object. - */ - public function getClassName() { - return get_class($this); - } - - /** * For a given ID, return the object associated with it. * This is used by the river functionality primarily. * This is useful for checking access permissions etc on objects. + * + * @param int $id ID + * + * @return ElggRelationship */ public function getObjectFromID($id) { return get_relationship($id); } /** - * Return the GUID of the owner of this object. - */ - public function getObjectOwnerGUID() { - return $this->owner_guid; - } - - /** * Return a type of the object - eg. object, group, user, relationship, metadata, annotation etc + * + * @return string 'relationship' */ public function getType() { return 'relationship'; } /** - * Return a subtype. For metadata & annotations this is the 'name' and for relationship this is the relationship type. + * Return a subtype. For metadata & annotations this is the 'name' and for relationship this + * is the relationship type. + * + * @return string */ public function getSubtype() { return $this->relationship; } - // 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) ) { - $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects - } - } - - function offsetExists($offset) { - return array_key_exists($offset, $this->attributes); - } -}
\ No newline at end of file +} |
