diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-30 13:54:45 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-30 13:54:45 +0000 |
commit | 5c13b26a250c5bd8cc18790d5b39fc46c86020f8 (patch) | |
tree | 233ef4a9828f45a9438709cd306a427f02ca6ef6 /engine/lib/relationships.php | |
parent | 07cd0838215d49e0029e818d5e6d904548a0b175 (diff) | |
download | elgg-5c13b26a250c5bd8cc18790d5b39fc46c86020f8.tar.gz elgg-5c13b26a250c5bd8cc18790d5b39fc46c86020f8.tar.bz2 |
Refs #186: Get URL for relationships
git-svn-id: https://code.elgg.org/elgg/trunk@1601 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/relationships.php')
-rw-r--r-- | engine/lib/relationships.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 8e9768a8c..ffb2d1ee4 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -107,6 +107,16 @@ { return delete_relationship($this->id); } + + /** + * Get a URL for this relationship. + * + * @return string + */ + public function getURL() + { + return get_relationship_url($this->id); + } // EXPORTABLE INTERFACE //////////////////////////////////////////////////////////// @@ -532,6 +542,73 @@ } + /** + * Sets the URL handler for a particular relationship type + * + * @param string $function_name The function to register + * @param string $relationship_type The relationship type. + * @return true|false Depending on success + */ + function register_relationship_url_handler($function_name, $relationship_type = "all") { + global $CONFIG; + + if (!is_callable($function_name)) return false; + + if (!isset($CONFIG->relationship_url_handler)) { + $CONFIG->relationship_url_handler = array(); + } + + $CONFIG->relationship_url_handler[$relationship_type] = $function_name; + + return true; + + } + + /** + * Get the url for a given relationship. + * + * @param unknown_type $id + * @return unknown + */ + function get_relationship_url($id) + { + global $CONFIG; + + $id = (int)$id; + + if ($relationship = get_relationship($id)) + { + $view = elgg_get_viewtype(); + + $guid = $relationship->guid_one; + $type = $relationship->relationship; + + $url = ""; + + $function = ""; + if (isset($CONFIG->relationship_url_handler[$type])) + $function = $CONFIG->relationship_url_handler[$type]; + if (isset($CONFIG->relationship_url_handler['all'])) + $function = $CONFIG->relationship_url_handler['all']; + + if (is_callable($function)) { + $url = $function($relationship); + } + + if ($url == "") { + + $nameid = $relationship->id; + + $url = $CONFIG->wwwroot . "export/$view/$guid/relationship/$nameid/"; + } + + return $url; + + } + + return false; + } + /**** HELPER FUNCTIONS FOR RELATIONSHIPS OF TYPE 'ATTACHED' ****/ /** |