AlexT
Well-known member
I understand you can change someone's secondary usergroup by directly accessing the datawriter like this:
What I don't understand yet is how xF uses the xf_user_group_change, specifically when changing someone's secondary usergroup through the addUserGroupChange/removeUserGroupChange user model methods. How is that different from using the datawriter as outlined above? Any ideas?
PHP:
$userDw = XenForo_DataWriter::create('XenForo_DataWriter_User');
$userDw->setExistingData($visitor['user_id']);
if ($userDw->get('secondary_group_ids'))
{
$existingGroups = array_fill_keys(explode(',', $userDw->get('secondary_group_ids')), true);
}
else
{
$existingGroups = array();
}
$existingGroups[self::NEW_GROUP_ID] = true; // the new group
$userDw->setSecondaryGroups(array_keys($existingGroups));
$userDw->save();
What I don't understand yet is how xF uses the xf_user_group_change, specifically when changing someone's secondary usergroup through the addUserGroupChange/removeUserGroupChange user model methods. How is that different from using the datawriter as outlined above? Any ideas?