From 693c78e16e51b80f0eaba5d8c27c3d942924b398 Mon Sep 17 00:00:00 2001 From: cash Date: Fri, 4 Mar 2011 02:45:14 +0000 Subject: Refs #1926 made 'access:collections:add_user', 'collection' plugin hook more useful git-svn-id: http://code.elgg.org/elgg/trunk@8576 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/access.php | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'engine/lib/access.php') diff --git a/engine/lib/access.php b/engine/lib/access.php index 68a01dfad..30febb799 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -592,31 +592,41 @@ function add_user_to_access_collection($user_guid, $collection_id) { return false; } - if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0) - && $user = get_user($user_guid)) { - global $CONFIG; + $user = get_user($user_guid); + if (!$user) { + return false; + } - $params = array( - 'collection_id' => $collection_id, - 'user_guid' => $user_guid - ); + // to add someone to a collection, the user must be a member of the collection or + // no one must own it + if ((array_key_exists($collection_id, $collections) || $collection->owner_guid == 0)) { + $result = true; + } else { + $result = false; + } + + $params = array( + 'collection_id' => $collection_id, + 'collection' => $collection, + 'user_guid' => $user_guid + ); - if (!elgg_trigger_plugin_hook('access:collections:add_user', 'collection', $params, true)) { - return false; - } + $result = elgg_trigger_plugin_hook('access:collections:add_user', 'collection', $params, $result); + if ($result == false) { + return false; + } - try { - $query = "insert into {$CONFIG->dbprefix}access_collection_membership" + try { + global $CONFIG; + $query = "insert into {$CONFIG->dbprefix}access_collection_membership" . " set access_collection_id = {$collection_id}, user_guid = {$user_guid}"; - insert_data($query); - } catch (DatabaseException $e) { - // nothing. - } - return true; - + insert_data($query); + } catch (DatabaseException $e) { + // nothing. + return false; } - return false; + return true; } /** -- cgit v1.2.3