From 4311996b40c039a647e00d3fde15d9c1c1ee8551 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 7 Jul 2008 16:49:45 +0000 Subject: Introducing canEditMetadata git-svn-id: https://code.elgg.org/elgg/trunk@1318 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 34 ++++++++++++++++++++++++++++++++++ engine/lib/metadata.php | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'engine') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 32be24775..abbd67bab 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -337,6 +337,16 @@ */ function canEdit($user_guid = 0) { return can_edit_entity($this->getGUID(),$user_guid); + } + + /** + * Determines whether or not the specified user (by default the current one) can edit metadata on the entity + * + * @param int $user_guid The user GUID, optionally (defaults to the currently logged in user) + * @return true|false + */ + function canEditMetadata($user_guid = 0) { + return can_edit_entity_metadata($this->getGUID(), $user_guid); } /** @@ -1329,6 +1339,30 @@ } + } + + /** + * Determines whether or not the specified user can edit metadata on 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_metadata($entity_guid, $user_guid = 0) { + + if ($entity = get_entity($entity_guid)) { + $return = can_edit_entity($entity_guid, $user_guid); + $return = trigger_plugin_hook('permissions_check:metadata',$entity->type,null,$return); + return $return; + } else { + return false; + } + } /** diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 36c2e65c7..130749bdd 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -77,7 +77,7 @@ function canEdit() { if ($entity = get_entity($this->get('entity_guid'))) { - return $entity->canEdit(); + return $entity->canEditMetadata(); } return false; -- cgit v1.2.3