From 0030fe2d63684b6612316b5162d34bfaa5dbfee1 Mon Sep 17 00:00:00 2001 From: cash Date: Mon, 21 Feb 2011 02:35:43 +0000 Subject: fixes #2885 #2569 likes controlled by canAnnotate() with plugin hook git-svn-id: http://code.elgg.org/elgg/trunk@8382 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/classes/ElggEntity.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'engine/classes/ElggEntity.php') diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 0298d6d6e..69401a7e5 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -935,9 +935,9 @@ abstract class ElggEntity extends ElggData implements } /** - * Can a user comment on an entity + * Can a user comment on an entity? * - * @tip Can be overridden vy registering for the permissions_check:comment, + * @tip Can be overridden by registering for the permissions_check:comment, * plugin hook. * * @param int $user_guid User guid (default is logged in user) @@ -956,6 +956,39 @@ abstract class ElggEntity extends ElggData implements return elgg_trigger_plugin_hook('permissions_check:comment', $this->type, $params, null); } + /** + * Can a user annotate an entity? + * + * @tip Can be overridden by registering for the permissions_check:annotate, + * plugin hook. + * + * @tip If you want logged out users to annotate an object, do not call + * canAnnotate(). It's easier than using the plugin hook. + * + * @param int $user_guid User guid (default is logged in user) + * @param string $annotation_name The name of the annotation (default is unspecified) + * + * @return bool + */ + public function canAnnotate($user_guid = 0, $annotation_name = '') { + if ($user_guid == 0) { + $user_guid = elgg_get_logged_in_user_guid(); + } + $user = get_entity($user_guid); + + $return = true; + if (!$user) { + $return = false; + } + + $params = array( + 'entity' => $this, + 'user' => $user, + 'annotation_name' => $annotation_name, + ); + return elgg_trigger_plugin_hook('permissions_check:annotate', $this->type, $params, $return); + } + /** * Returns the access_id. * -- cgit v1.2.3