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... Get in touch if you need a hand with that - its not pretty!
Loading Conversation