diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-18 14:02:11 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-07-18 14:02:11 +0000 |
commit | fefa3a1bdc56cd0e015fee96a9c39b9b60e1d84a (patch) | |
tree | 19b0fb5616855755c15dd2e4439178080c3f32bd | |
parent | 1e864cad815ab1a8e587e36f16e4857daa5e52d1 (diff) | |
download | elgg-fefa3a1bdc56cd0e015fee96a9c39b9b60e1d84a.tar.gz elgg-fefa3a1bdc56cd0e015fee96a9c39b9b60e1d84a.tar.bz2 |
Closes #166
git-svn-id: https://code.elgg.org/elgg/trunk@1471 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r-- | engine/lib/group.php | 10 | ||||
-rw-r--r-- | mod/groups/languages/en.php | 3 | ||||
-rw-r--r-- | mod/groups/start.php | 84 |
3 files changed, 94 insertions, 3 deletions
diff --git a/engine/lib/group.php b/engine/lib/group.php index cc488ab0d..b0c6d3346 100644 --- a/engine/lib/group.php +++ b/engine/lib/group.php @@ -729,7 +729,15 @@ return remove_entity_relationship($user_guid, 'member', $group_guid); } - + /** + * Return all groups a user is a member of. + * + * @param unknown_type $user_guid + */ + function get_users_membership($user_guid) + { + return get_entities_from_relationship('member', $user_guid, true); + } ?>
\ No newline at end of file diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php index 4aafe7b57..d13568bd4 100644 --- a/mod/groups/languages/en.php +++ b/mod/groups/languages/en.php @@ -14,7 +14,7 @@ /** * Menu items and titles */ - + 'groups' => "Groups", 'groups:yours' => "Your groups", 'groups:user' => "%s's groups", @@ -42,6 +42,7 @@ 'groups:inviteto' => "Invite friends to '%s'", 'groups:nofriends' => "You have no friends left who have not been invited to this group.", + 'groups:group' => "Group", 'groups:privategroup' => 'This group is private, requesting membership.', 'groups:notitle' => 'Groups must have a title', diff --git a/mod/groups/start.php b/mod/groups/start.php index 04e211e80..38d1cc7d7 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -67,7 +67,7 @@ // where key is the array key below $CONFIG->group = array( - 'title' => 'text', + 'name' => 'text', 'description' => 'longtext', //'location' => 'tags', 'interests' => 'tags', @@ -150,6 +150,88 @@ } + /** + * Groups created, so add users to access lists. + */ + function groups_create_event_listener($event, $object_type, $object) + { + if (($event == 'create') && ($object_type == 'group') && ($object instanceof ElggGroup)) + { + $group_id = create_access_collection(elgg_echo('groups:group') . ": " . $object->name); + if ($group_id) + { + $object->group_acl = $group_id; + } + else + return false; + } + + return true; + } + + /** + * Hook to listen to read access control requests and return all the groups you are a member of. + */ + function groups_read_acl_plugin_hook($hook, $entity_type, $returnvalue, $params) + { + //error_log("READ: " . var_export($returnvalue)); + $user = $_SESSION['user']; + if ($user) + { + $membership = get_users_membership($user->guid); + + if ($membership) + { + foreach ($membership as $group) + $returnvalue[$user->guid][$group->group_acl] = elgg_echo('groups:group') . ": " . $group->name; + + return $returnvalue; + } + } + } + + /** + * Return the write access for the current group if the user has write access to it. + */ + function groups_write_acl_plugin_hook($hook, $entity_type, $returnvalue, $params) + { + $group_guid = get_input('group_guid'); + + if ($group_guid) + { + $group = get_entity($group_guid); + + if (($group) && ($group->can_write_to_container($_SESSION['user']->guid))) + { + $returnvalue[$group->group_acl] = elgg_echo('groups:group') . ": " . $group->name; + + return $returnvalue; + } + } + } + + /** + * Groups deleted, so remove access lists. + */ + function groups_delete_event_listener($event, $object_type, $object) + { + delete_access_collection($object->access_id); + + return true; + } + + // Register a handler for create groups + register_elgg_event_handler('create', 'group', 'groups_create_event_listener'); + + // Register a handler for delete groups + register_elgg_event_handler('delete', 'group', 'groups_delete_event_listener'); + + // Read access permissions + register_plugin_hook('access:collections', 'all', 'groups_read_acl_plugin_hook'); + + // Write access permissions + register_plugin_hook('access:collections:write', 'all', 'groups_write_acl_plugin_hook'); + // Make sure the groups initialisation function is called on initialisation register_elgg_event_handler('init','system','groups_init'); ?>
\ No newline at end of file |