aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/entities.php81
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