]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2814 can now check if an entity exists indepedent of access permissions
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 15 Mar 2011 11:36:39 +0000 (11:36 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Tue, 15 Mar 2011 11:36:39 +0000 (11:36 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8720 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/entities.php

index 85ab527e719c9cf65cd20b2366347350074f060b..7f07f7359e90c62797cbdefa958a706d611583f4 100644 (file)
@@ -681,6 +681,33 @@ function get_entity($guid) {
        return entity_row_to_elggstar(get_entity_as_row($guid));
 }
 
+/**
+ * Does an entity exist?
+ *
+ * This function checks for the existence of an entity independent of access
+ * permissions. It is useful for situations when a user cannot access an entity
+ * and it must be determined whether entity has been deleted or the access level
+ * has changed.
+ *
+ * @param int $guid The GUID of the entity
+ *
+ * @return bool
+ * @since 1.8.0
+ */
+function elgg_entity_exists($guid) {
+       global $CONFIG;
+
+       $guid = sanitize_int($guid);
+
+       $query = "SELECT count(*) as total FROM {$CONFIG->dbprefix}entities WHERE guid = $guid";
+       $result = get_data_row($query);
+       if ($result->total == 0) {
+               return false;
+       } else {
+               return true;
+       }
+}
+
 /**
  * Returns an array of entities with optional filtering.
  *