Question

I have assigned a field in the user database of my Joomla site to hold a value for a users experience (userxp). When a new user registers, they are assigned a default userxp value of 0. I'm going to be developing a system where a user completes quests and earns XP. Once a user gains a certain amount of XP, I want Joomla to automatically assign them to a new user group. I've set up custom user groups (Level 1, Level 2, Level 3, etc).

What I'd like to do is get the users XP value, and then assign them to the appropriate user group. For instance, if the XP value is 0, do nothing - the user group is level 1 by default. But if the userxp value is 10, remove the user from user group Level 1 and add them to user group Level 2. If the userxp value is 100, remove the user from user group Level 2 and assign them to user group Level 3. You get the gist, a standard leveling system like any RPG ever.

I've done some research that suggests editing the helper.php file and making use of the addUserToGroup and removeUserFromGroup methods. I am a total greenhorn when it comes to PHP so I'm wondering if anyone could help me out here.

Was it helpful?

Solution

Don't edit the core file. What you probably want to do is create a plugin that uses either the login event or the logout event to change the user's group memberships. The Joomla documentation site has information on how to make a plugin and you can also copy the structure and naming patterns from one of the core plugins.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top