From 8587c6d80aed5e978b52325f80175392c3961eea Mon Sep 17 00:00:00 2001 From: kevinjardine Date: Wed, 4 Mar 2009 13:17:20 +0000 Subject: Added has_access_to_entity function git-svn-id: https://code.elgg.org/elgg/trunk@3068 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/access.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'engine') diff --git a/engine/lib/access.php b/engine/lib/access.php index 8f8373524..ecdcaad3b 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -259,6 +259,33 @@ END; return '('.$sql.')'; } + /** + * Determines whether the given user has access to the given entity + * + * @param ElggEntity $entity The entity to check access for. + * @param ElggUser $user Optionally the user to check access for. + * + * @return boolean True if the user can access the entity + */ + + function has_access_to_entity($entity,$user = null) { + global $CONFIG; + + if (!isset($user)) { + $access_bit = get_access_sql_suffix("e"); + } else { + $access_bit = get_access_sql_suffix("e",$user->getGUID()); + } + + $query = "SELECT guid from {$CONFIG->dbprefix}entities e WHERE e.guid = ".$entity->getGUID(); + $query .= " AND ".$access_bit; // Add access controls + if (get_data($query)) { + return true; + } else { + return false; + } + } + /** * Returns an array of access permissions that the specified user is allowed to save objects with. * Permissions are of the form ('id' => 'Description') -- cgit v1.2.3