]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #1926 made 'access:collections:add_user', 'collection' plugin hook more useful
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 4 Mar 2011 02:45:14 +0000 (02:45 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 4 Mar 2011 02:45:14 +0000 (02:45 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8576 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/access.php

index 68a01dfad8dd1e22042a83e814af3c077b464dc0..30febb7990afe4de42711b253d6e1ac3053aa000 100644 (file)
@@ -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;
 }
 
 /**