/** * Get a relationship by its ID * * @param int $id The relationship ID * * @return ElggRelationship|false False if not found */ function get_relationship($id) { $row = _elgg_get_relationship_row($id); if (!$row) { return false; } return new ElggRelationship($row); }
/** * Create a relationship object * * @param \stdClass $row Database row or null for new relationship * @throws InvalidArgumentException */ public function __construct($row = null) { $this->initializeAttributes(); if ($row === null) { elgg_deprecated_notice('Passing null to constructor is deprecated. Use add_entity_relationship()', 1.9); return; } if (!$row instanceof \stdClass) { if (!is_numeric($row)) { throw new \InvalidArgumentException("Constructor accepts only a \\stdClass or null."); } $id = (int) $row; elgg_deprecated_notice('Passing an ID to constructor is deprecated. Use get_relationship()', 1.9); $row = _elgg_get_relationship_row($id); if (!$row) { throw new \InvalidArgumentException("Relationship not found with ID {$id}"); } } foreach ((array) $row as $key => $value) { $this->attributes[$key] = $value; } }