aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggRelationship.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/classes/ElggRelationship.php')
-rw-r--r--engine/classes/ElggRelationship.php34
1 files changed, 21 insertions, 13 deletions
diff --git a/engine/classes/ElggRelationship.php b/engine/classes/ElggRelationship.php
index 413527df3..d2e88882a 100644
--- a/engine/classes/ElggRelationship.php
+++ b/engine/classes/ElggRelationship.php
@@ -4,15 +4,21 @@
*
* @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
{
/**
- * 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->initializeAttributes();
@@ -41,7 +47,7 @@ class ElggRelationship extends ElggData implements
* @return mixed
*/
function get($name) {
- if (isset($this->attributes[$name])) {
+ if (array_key_exists($name, $this->attributes)) {
return $this->attributes[$name];
}
@@ -65,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) {
@@ -73,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;
@@ -136,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'));
}
@@ -168,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 ////////////////////////////////////////////////////////////
@@ -220,4 +228,4 @@ class ElggRelationship extends ElggData implements
return $this->relationship;
}
-} \ No newline at end of file
+}