Username styling and removeSecondaryGroupFromUsers

Moturdrn

Member
Hi all,

I've got a system I'm using whereby Guilds can get registered within a listing. When a guild is initially listed and approved, any members which request to join get added to an approved group.

PHP:
private function addSecondaryGroup($userId, $groupId)
    {
        $userModel = $this->_getUserModel();
        $userGroupModel = $this->_getUserGroupModel();

        $user = $userModel->getUserById($userId);
        $userGroup = $userGroupModel->getUserGroupById($groupId);

        if($user && $userGroup)
        {
            if(!$userModel->isMemberOfUserGroup($user, $groupId))
            {
                $secondaryGroups = explode(",", $user['secondary_group_ids']);
                $secondaryGroups[] = $groupId;
                $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
                $writer->setExistingData($user['user_id']);
                $writer->setSecondaryGroups($secondaryGroups);
                $writer->save();
            }
        }
    }

When a user is removed from a Guild listing, the system first checks to see if they are a member of any other approved Guilds. If they are, it does nothing. If they aren't, the system should remove them from this group.

PHP:
$this->_getUserGroupModel()->removeSecondaryGroupFromUsers(array($userId), $groupId);

Removing the user from the group is working. However, this group also contains username css styling. This styling persists and I have to run the user caches update within the AdminCP to remove it.

Any hints? :) (Ignore, please see below)


Edit:

Just had a thought that hadn't yet occurred to me, do the same as the addSecondaryGroups but to remove.

PHP:
private function removeSecondaryGroup($userId, $groupId)
    {
        $userModel = $this->_getUserModel();
        $userGroupModel = $this->_getUserGroupModel();

        $user = $userModel->getUserById($userId);
        $userGroup = $userGroupModel->getUserGroupById($groupId);

        if($user && $userGroup)
        {
            if($userModel->isMemberOfUserGroup($user, $groupId))
            {
                $secondaryGroups = explode(",", $user['secondary_group_ids']);
                if(($key = array_search($groupId, $secondaryGroups)) !== false)
                {
                    unset($secondaryGroups[$key]);
                }
                $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
                $writer->setExistingData($user['user_id']);
                $writer->setSecondaryGroups($secondaryGroups);
                $writer->save();
            }
        }
    }

Please ignore my early morning ramblings before coffee :D
 
Last edited:
Back
Top Bottom