Snippet- Entering Exiting Groups

Permalink
Heres my little contribution in dealing with adding and/or removing users from groups. This function will remove from all groups and add to the group that the function is called with. Pretty simple I know but I spent a few dealing with how to do this properly..


private function ChangeGroup($newgroup)
    {
       $user = User::getByUserID($this->user_id);
       $groups = $user->getUserGroups() ;
        foreach ($groups as $gID => $groupname)
        {   
            $group = Group::getByID($gID);
            $user->exitGroup($group);
        }
        Loader::model('search/group'); 
        $gs = new GroupSearch($_GET);
        $gResults = $gs->getResult("");  //blank to get all... 
        foreach ($gResults as $g) {
         if ($g['gName'] == $newgroup)
         {

DavidMIRV
 
dstew99 replied on at Permalink Reply
dstew99
Can you please explain how you implemented it?
thebogdan replied on at Permalink Reply
thebogdan
Yes, do you have an example of how to implement it into the website. I am looking for functionality to allow users ability to add/remove themselves to/from any existing group. Any help is welcome, I'm not very savvy with C5 yet.