How to: If var = x , set usergroup to 4.

arcaneex

Active member
@Title. basically , I have a plugin which gets the data from a XML , and outputs text. I want to take the text and check for a certain word , if the word is there then put the user in a group. Help?
 
This isn't especially straight forward.

The best I can think of is making use of custom fields.

So actually this may be a rewrite of what you've done so far - or at least a rethink of how to achieve it.

One thing I notice is that the steam ID is hard coded into the PHP script and your require once will only pull the data once per page.

So eventually you're going to need a way of passing each person's Steam ID so maybe using custom user fields is the way to capture that and feed it into your script.

Then, you could set up a user group promotion that puts people in different user groups based on the data returned?

Just thinking aloud but should work.
 
This isn't especially straight forward.

The best I can think of is making use of custom fields.

So actually this may be a rewrite of what you've done so far - or at least a rethink of how to achieve it.

One thing I notice is that the steam ID is hard coded into the PHP script and your require once will only pull the data once per page.

So eventually you're going to need a way of passing each person's Steam ID so maybe using custom user fields is the way to capture that and feed it into your script.

Then, you could set up a user group promotion that puts people in different user groups based on the data returned?

Just thinking aloud but should work.
I want to avoid regular registrations , as right now my setup simply kills unwanted people and spammers. The Steam ID number which you saw was used as an example , and will be changed to a variable which contains each user steam ID.
 
@Title. basically , I have a plugin which gets the data from a XML , and outputs text. I want to take the text and check for a certain word , if the word is there then put the user in a group. Help?

The easiest, though not the correct way, would be to simply extend the user model and write a function which accepts the user id as a parameter and updates xf_user table with $db->query().
 
Why isn't it correct?

Never a good idea writing updates directly. The correct way would be that you look at XF's user controller and model and see how which method is responsible for usergroup update. You should then see if you can call that method with whatever input parameters it requires in your code.
 
I tried the custom field approach , four problems:
Only new registered people will fill that field , and I need all the users to have this field. Unless I can force them on their next visit to input it - won't work.
User can enter any random numbers - no use for me.
Still , User group promotions option doesn't let me promote using the data that it gets , custom user field , same as my $rep variable - is a variable. Which just creates more problems when I have the same variable but without the other three problems.
Somewhy I can't input the custom field variable in the listener , but okay.

So yeah, I really suck at coding and would be awesome if anyone could help me out.
 
@Title. basically , I have a plugin which gets the data from a XML , and outputs text. I want to take the text and check for a certain word , if the word is there then put the user in a group. Help?
Does the xml file come from an external site? Do you need to set the group as soon as the user registers (otherwise you could do it in a cron entry)? If so, what do you do if the site is unavailable?
 
Does the xml file come from an external site? Do you need to set the group as soon as the user registers (otherwise you could do it in a cron entry)? If so, what do you do if the site is unavailable?
The XML comes from an external site , I need the group set every 24 hours ( check the variable for any changes )
If you mean the external site , then it wouldn't set any group ( or update them )
 
Okay guys , I have small progression , atleast I think so.
I found this:
* Gets the user group model.
*
* @return XenForo_Model_UserGroup
*/
protected function _getUserGroupModel()
{
return $this->getModelFromCache('XenForo_Model_UserGroup');
}
But does it somehow help me? How do I check against that $rep variable , and then upgrade if the output is what I want?
 
I think I found what I need , but still unsure.
First this: XenForo_Model_UserGroup::changePrimaryUserGroupForUsers not sure if this will work , but basically from what I understood it changes the usergroup of the users I specify. I'm not even sure it's correct , I just figured as XenForo_Model_Usergroup is the class and the other part is a function , so yeah.
Aside from this , I was thinking of setting something like this:
if $myvar = mystring {
use the thing I mentioned above }
else { don't do anything }
I need help translating this to xenforo though.
 
I think I found what I need , but still unsure.
First this: XenForo_Model_UserGroup::changePrimaryUserGroupForUsers not sure if this will work , but basically from what I understood it changes the usergroup of the users I specify. I'm not even sure it's correct , I just figured as XenForo_Model_Usergroup is the class and the other part is a function , so yeah.
Aside from this , I was thinking of setting something like this:
if $myvar = mystring {
use the thing I mentioned above }
else { don't do anything }
I need help translating this to xenforo though.

This approach is correct. However you will need a lot of familiarization with Xenforo's manner of extension and coding. You should read and follow some of the basic addon creation tutorials on this site.
 
You should use custom user fields. Make it required and everyone will have to fill it in once they've visited their profile AFAIK.
You can pass a validation callback to ensure they're entering a valid Steam ID (and whatever else you need to check), you may also be able to do the usergroup updating in the validation callback.
 
You should use custom user fields. Make it required and everyone will have to fill it in once they've visited their profile AFAIK.
You can pass a validation callback to ensure they're entering a valid Steam ID (and whatever else you need to check), you may also be able to do the usergroup updating in the validation callback.
Well the problem is I already have a steam ID variable , and if I use customField I'll need a way to use it's variable in the listener.
 
This approach is correct. However you will need a lot of familiarization with Xenforo's manner of extension and coding. You should read and follow some of the basic addon creation tutorials on this site.
Could you possibly link me to a guide which will help be set this?
 
Alright , well I got few things:

PHP:
public function changePrimaryUserGroupForUsers(array $userIds, $newPrimaryGroupId)
{
if (!$userIds)
{
return;
}
 
$db = $this->_getDb();
 
$userIdsQuoted = $db->quote($userIds);
 
XenForo_Db::beginTransaction($db);
 
$db->update('xf_user',
array('user_group_id' => $newPrimaryGroupId),
'user_id IN (' . $userIdsQuoted . ')'
);
$db->delete('xf_user_group_relation',
'user_id IN (' . $userIdsQuoted . ') AND user_group_id = ' . $db->quote($newPrimaryGroupId)
. ' AND is_primary = 0'
);
$db->update('xf_user_group_relation',
array('user_group_id' => $newPrimaryGroupId),
'user_id IN (' . $userIdsQuoted . ') AND is_primary = 1'
);
 
$this->_getPermissionModel()->updateUserPermissionCombinations($userIds);
 
XenForo_Db::commit($db);
}
This is what , I think I could use to change the usergroup.
Now , I found out that what I kinda need is in the database too , it's under xf_user_profile , column name steam_auth_id
What will hopefully hopefully help me end this , is if I get a way to use steam_auth_id , put it in this link: http://steamrep.com/api/beta/reputation/steam_auth_id ( example link: http://steamrep.com/api/beta/reputation/76561197971691194 ) (or add ?json=1 to make it in json )
get the contents and if the content is equal to SCAMMER , set the usergroup.
Main problem is , I have no damn idea how to do that. Anyone care to help? Ready to pay up to 20 bucks if needed , really need help.
 
Top Bottom