User assign to group and accept by an admin? and feedback on plan?

Permalink
Hi,

Is there a way to assign people to groups by script and let group admins "accept" people to "their" group?
also maybe people have good ideas here about my idea?
What i want to make:
Users can register themselves on the site. A site for clubs. You can search clubs by province > city. Each club can be added by a user. Creation of a club will create a usergroup. I thought of writing a script myself what creates the usergroup, and make the user that creates the club, the admin of the group. When an other member of the club becomes a member of my site, he can choose to join the usergroup of that club, but that first has to be accepted by the group admin.
Any better/other ideas about this?

Bart

 
5fly replied on at Permalink Reply
5fly
Hi Bart,

You could write a block or single page that would allow site users to add groups and then add other registered users to that group, you'd need to use a few bits of code:

If you need to add your new group to a group set you could get by ID or find it by name

$yourGroupSet = GroupSet::getByID($gsID);


If you want to create a group set on the fly

if(!is_object($yourGroupSet)) $yourGroupSet = GroupSet::add('Group Set Handle', $pkg);


You should then check if group exists and create

if(!is_object(Group::getByName('New Group Name'))) {
        $g = Group::add('New Group Name', 'New Group description');
        $yourGroupSet->addGroup($g);
}


Once the group is added you can then add users to it

$u = new User(); //get the current user
//check the user is logged in as you cant assign groups to people who dont have an account
if($u->isLoggedIn()){
        //if user not already in new group
        if(!$u->inGroup(Group::getByName('New Group Name'))){
                $u->enterGroup('New Group Name');
        }
}


You can also remove people from groups with

$u->exitGroup('New Group Name');


You could (and probably not really recommended but we've had to do it before) add non-logged in users to a group temporarily for that session... I can dig the code out if you'd like that - its not very nice! ;)

For your idea the idea of groups is something worth considering but only if your planning on using the permissions to control access and maybe users can be in more than one group etc otherwise a custom user attribute would probably be easier to do and less overhead...
VolgensBartjes replied on at Permalink Reply
thanks, i thought about this also, only one part is missing now, how you discribe it, a user must add a user to the group. what i want is to let the user adds himself to the group (possible with same code offcourse) but not directly accepted. the admin of that group/club had firstly to accept that user on that group.
if there is no such option (what i think is so), i would create an other table with pending requests, when a group admin accept a pending request, the script to add the user to the group is triggered.
But would be better if such a option is allready available.
Bart