diff options
Diffstat (limited to 'engine/classes/ElggRelationship.php')
| -rw-r--r-- | engine/classes/ElggRelationship.php | 199 |
1 files changed, 26 insertions, 173 deletions
diff --git a/engine/classes/ElggRelationship.php b/engine/classes/ElggRelationship.php index c072e1cc6..d2e88882a 100644 --- a/engine/classes/ElggRelationship.php +++ b/engine/classes/ElggRelationship.php @@ -4,27 +4,24 @@ * * @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 extends ElggData 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; + 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 ElggRelationship 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) { @@ -49,8 +46,8 @@ class ElggRelationship extends ElggData implements * * @return mixed */ - function __get($name) { - if (isset($this->attributes[$name])) { + function get($name) { + if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } @@ -65,7 +62,7 @@ class ElggRelationship extends ElggData implements * * @return mixed */ - function __set($name, $value) { + function set($name, $value) { $this->attributes[$name] = $value; return true; } @@ -74,6 +71,7 @@ class ElggRelationship extends ElggData implements * Save the relationship * * @return int the relationship id + * @throws IOException */ public function save() { if ($this->id > 0) { @@ -82,7 +80,7 @@ class ElggRelationship extends ElggData 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; @@ -145,14 +143,13 @@ class ElggRelationship extends ElggData implements /** * Import a relationship * - * @param array $data ODD data - * - * @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')); } @@ -177,12 +174,14 @@ class ElggRelationship extends ElggData 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 //////////////////////////////////////////////////////////// @@ -198,15 +197,6 @@ class ElggRelationship extends ElggData implements } /** - * Return the class name of the object. - * - * @return string - */ - 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. @@ -220,15 +210,6 @@ class ElggRelationship extends ElggData implements } /** - * Return the GUID of the owner of this object. - * - * @return int - */ - public function getObjectOwnerGUID() { - return $this->owner_guid; - } - - /** * Return a type of the object - eg. object, group, user, relationship, metadata, annotation etc * * @return string 'relationship' @@ -247,132 +228,4 @@ class ElggRelationship extends ElggData implements 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; - - /** - * 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)) { - $this->attributes[$key] = ""; // Full unsetting is dangerious for our objects - } - } - - /** - * Array access interface - * - * @see ArrayAccess::offsetExists() - * - * @param int $offset Offset - * - * @return int - */ - function offsetExists($offset) { - return array_key_exists($offset, $this->attributes); - } -}
\ No newline at end of file +} |
