From 2af331994f9aae9c2d80cda57ef822c226f180ab Mon Sep 17 00:00:00 2001 From: ben Date: Fri, 4 Apr 2008 17:20:14 +0000 Subject: Added $entity->canEdit() (true|false) git-svn-id: https://code.elgg.org/elgg/trunk@405 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'engine/lib') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 92b658ef2..eba5b8a4d 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -241,6 +241,16 @@ { return get_annotations_max($this->getGUID(), "","",$name); } + + /** + * Determines whether or not the specified user (by default the current one) can edit the entity + * + * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user) + * @return true|false + */ + function canEdit($user_guid = 0) { + return can_edit_entity($this->getGUID(),$user_guid); + } public function getAccessID() { return $this->get('access_id'); } public function getGUID() { return $this->get('guid'); } @@ -728,6 +738,34 @@ return $tmp; } } + + /** + * Determines whether or not the specified user can edit the specified entity. + * + * This is extendible by registering a plugin hook taking in the parameters 'entity' and 'user', + * which are the entity and user entities respectively + * + * @see register_plugin_hook + * + * @param int $entity_guid The GUID of the entity + * @param int $user_guid The GUID of the user + * @return true|false Whether the specified user can edit the specified entity. + */ + function can_edit_entity($entity_guid, $user_guid = 0) { + + if ($user_guid == 0) { + $user = $_SESSION['user']; + } else { + $user = get_entity($user_guid); + } + $entity = get_entity($entity_guid); + + if ($entity->getOwner() == $user->getGUID()) return true; + if ($entity->type == "user" && $entity->getGUID() == $user->getGUID()) return true; + + return trigger_plugin_hook('permissions_check',$entity->type,array('entity' => $entity, 'user' => $user),false); + + } /** Register the import hook */ register_plugin_hook("import", "all", "import_entity_plugin_hook", 0); -- cgit v1.2.3