Forum


Calc Builder Support

Calc Builder support
Forums
Public write access is disabled. Please login

Codes for retrieving group information of logged in users 11.11.2018 19:55

In your tutorial https://www.moonsoft.es/easyblog/entry/61-code-tip-accesing-joomla-user-data you mention the next code.

$usergroups= $user->groups; // List of Joomla groups this user belongs to (is an array)

Can you help me with the right code to retrieve or recover the data of this array of the list of groups the user belongs to.

We have assigned our customers who have registered on our site to different groups like customergroup1, customergroup2 .. ectera. Each customergroup has a different discount percentage. I am looking for the right code to find out to which group the logged-in user belongs to after the code $usergroups= $user->groups; and give him/her a certain discountpercentage when he/she uses our calculator.

Which PHP code do I have to use? Do I need column or row names? And if yes how to find these names in the array.

Best regards
AdK

Re: Codes for retrieving group information of logged in users 12.11.2018 10:01

Hi,
that specific code will give you a collection of identifiers of the groups the actual user belongs to. So you will have at

$usergroups[0]

, the group number of the first group assigned, at $usergroups[1]
the id number of the second group assigned, etc.
You can check if the user belongs, for ex, to group 8, using in_array function

$searchgroup=8;
if(in_array($searchgroup,$usergroups)){
//the user belongs to group 8
}

you could also loop through all array values using for/foreach expressions

foreach($usergroup as $group){

//code here for the group id $group
}

Hope this helps, regards
Moonsoft Team
www.moonsoft.es
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect

Our clients' feedback