diff options
author | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-16 15:03:15 +0000 |
---|---|---|
committer | ben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-16 15:03:15 +0000 |
commit | 11f62409f3e96e36d1e0ff6907439e850ebb109f (patch) | |
tree | a0a5f440500250ce24e3f43e10d678f1ee250532 /engine | |
parent | cdabdd5951626da5b1bd184dca50716248f32c31 (diff) | |
download | elgg-11f62409f3e96e36d1e0ff6907439e850ebb109f.tar.gz elgg-11f62409f3e96e36d1e0ff6907439e850ebb109f.tar.bz2 |
Added the getURL and getOwnerUser methods to ElggEntity (gets the URL to display the current entity and the ElggUser entity that represents the owner respectively)
git-svn-id: https://code.elgg.org/elgg/trunk@475 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r-- | engine/lib/entities.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 2cbdc2e73..2752b4a08 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -281,6 +281,13 @@ * @todo document me */ public function getOwner() { return $this->get('owner_guid'); } +
+ /**
+ * Returns the actual entity of the user who owns this entity, if any
+ *
+ * @return ElggEntity The owning user
+ */
+ public function getOwnerUser() { return get_entity($this->get('owner_guid')); }
/** * Enter description here... @@ -313,6 +320,13 @@ * @todo document me */ public function getTimeUpdated() { return $this->get('time_updated'); } +
+ /**
+ * Gets the display URL for this entity
+ *
+ * @return string The URL
+ */
+ public function getURL() { return get_entity_url($this->getGUID()); }
/** * Save generic attributes to the entities table. @@ -902,6 +916,73 @@ }
/**
+ * Gets the URL for an entity, given a particular GUID
+ *
+ * @param int $entity_guid The GUID of the entity
+ * @return string The URL of the entity
+ */
+ function get_entity_url($entity_guid) {
+
+ global $CONFIG;
+ if ($entity = get_entity($entity_guid)) {
+
+ $url = "";
+
+ if (isset($CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()])) {
+ $function = $CONFIG->entity_url_handler[$entity->getType()][$entity->getSubType()];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ }
+ if (isset($CONFIG->entity_url_handler[$entity->getType()]['all'])) {
+ $function = $CONFIG->entity_url_handler[$entity->getType()]['all'];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ }
+ if (isset($CONFIG->entity_url_handler['all']['all'])) {
+ $function = $CONFIG->entity_url_handler['all']['all'];
+ if (is_callable($function)) {
+ $url = $function($entity);
+ }
+ }
+
+ if ($url == "") {
+ $url = $CONFIG->url . "view/" . $entity_guid;
+ }
+ return $url;
+
+ }
+ return false;
+
+ }
+
+ /**
+ * Sets the URL handler for a particular entity type and subtype
+ *
+ * @param string $function_name The function to register
+ * @param string $entity_type The entity type
+ * @param string $entity_subtype The entity subtype
+ * @return true|false Depending on success
+ */
+ function register_entity_url_handler($function_name, $entity_type = "all", $entity_subtype = "all") {
+ global $CONFIG;
+
+ if (!is_callable($function_name)) return false;
+
+ if (!isset($CONFIG->entity_url_handler)) {
+ $CONFIG->entity_url_handler = array();
+ }
+ if (!isset($CONFIG->entity_url_handler[$entity_type])) {
+ $CONFIG->entity_url_handler[$entity_type] = array();
+ }
+ $CONFIG->entity_url_handler[$entity_type][$entity_subtype] = $function_name;
+
+ return true;
+
+ }
+
+ /**
* Page handler for generic entities view system
*
* @param array $page Page elements from pain page handler
|