diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-14 15:55:04 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-14 15:55:04 +0000 |
commit | 27b6c185a2dbe731d308991e268f6d7b4264a71b (patch) | |
tree | 94bfe122b70a0edd887b55e80d786591f4d47047 /engine/lib/relationships.php | |
parent | 41b4ba7841604b910599dd473c5009525a95dd0f (diff) | |
download | elgg-27b6c185a2dbe731d308991e268f6d7b4264a71b.tar.gz elgg-27b6c185a2dbe731d308991e268f6d7b4264a71b.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Relationships export
git-svn-id: https://code.elgg.org/elgg/trunk@444 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/relationships.php')
-rw-r--r-- | engine/lib/relationships.php | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 5af01044a..7d71adb0a 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -111,11 +111,15 @@ */ public function export() { - $tmp = new stdClass; - $tmp->attributes = $this->attributes; - $tmp->attributes['uuid_one'] = guid_to_uuid($this->guid_one); - $tmp->attributes['uuid_two'] = guid_to_uuid($this->guid_two); - return $tmp; + $verb = get_verb_from_relationship($this->relationship); + if (!$verb) + throw new ExportException("There is no verb mapping for '{$this->relationship}'."); + + return new ODDRelationship( + guid_to_uuid($this->guid_one), + $verb, + guid_to_uuid($this->guid_two) + ); } /** @@ -239,7 +243,7 @@ $relationship = sanitise_string($relationship); $guid_two = (int)$guid_two; - return insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships (guid_one, relationship, guid_two) values ($guid_one, 'relationship', $guid_two)"); + return insert_data("INSERT into {$CONFIG->dbprefix}entity_relationships (guid_one, relationship, guid_two) values ($guid_one, '$relationship', $guid_two)"); } /** @@ -283,6 +287,22 @@ } /** + * Get all the relationships for a given guid. + * + * @param int $guid + */ + function get_entity_relationships($guid) + { + global $CONFIG; + + $guid = (int)$guid; + + $query = "SELECT * from {$CONFIG->dbprefix}entity_relationships where guid_one=$guid"; + + return get_data($query, "row_to_elggrelationship"); + } + + /** * Return entities matching a given query joining against a relationship. * * @param string $relationship The relationship eg "friends_of" @@ -338,7 +358,6 @@ return get_data($query, "entity_row_to_elggstar"); } - /** * Handler called by trigger_plugin_hook on the "import" event. */ @@ -363,7 +382,7 @@ { global $CONFIG; -/* // Sanity check values + // Sanity check values if ((!is_array($params)) && (!isset($params['guid']))) throw new InvalidParameterException("GUID has not been specified during export, this should never happen."); @@ -372,14 +391,14 @@ $guid = (int)$params['guid']; - $result = get_data("SELECT * from {$CONFIG->dbprefix}entity_relationships where guid_one = $guid"); + $result = get_entity_relationships($guid); if ($result) { foreach ($result as $r) - $returnvalue[] = $r; + $returnvalue[] = $r->export(); } -*/ + return $returnvalue; } |