News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Show link only if user belong to a specific group

Started by Cmely, April 18, 2014, 03:42:37 PM

Previous topic - Next topic

Cmely

Hi,

On my memberlist (here), I show a link ("view picture") under the avatar of the member. For the moment this link is shown for any member of the forum.

What would be the code to add in order to show the same link only if the member belong to a given group ?

Thank you for your help :)

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Cmely

Thank you for your answer Krash :)

What the ['0'] is for ?

Cmely

We're progressing  ;D ...

I've been able to check if the member belongs to a primary membergroup, but what I really need is to test if the member belong to a group but not a primary one (and not postcount based ones too).

I've tried something like this :
if (in_array(36, $member['groups']['id'] ))
echo '
<a href="' . $scripturl .  '?action=gallery;sa=myimages;u=',$member['id'], '">', $txt['smfgallery_profilelink'], '</a><br />';


('36' being the id_group)

...but I guess I'm not on the good track... :o

maximus23


Verify members groups.

Simple Examples :



global $user_info ,$context ;

if(in_array(1, $user_info['groups']))

{

echo' User : '. $user_info['id'] .' Name : ' . $context['user']['name'];

}


1 = id group

:)

Pas de support par PM ou Courrier...Veuillez utiliser le forum pour vous avoir une réponse rapide à votre demande d'aide. Merci.
Amitiés et à Bientôt...
No support by PM or Mail...You will get better and faster responses in the support forums. Thank you.
Have a nice day...

Cmely

Thank you for your help Maximus  :)

Just to be sure and also because I'm afraid I may have not been very clear  in my first post  :o ;D : if I understand correctly the code in your answer, it check if the logged in user belongs to membergroup '1'. Is that correct ?

What I rather wish is something to test if the member from whom I displays information  belongs to this group. If you have a look on my memberlist, it will be easier to understand. I'm showing member's informations like Name, avatar, email,  ... and it would like to add some extra information only if this member belongs to membergroup 'X'.


maximus23


Verify action by group id for add extra information by user :



if ($member['group_id'] == 1)
{
  echo'Action for Administrator group';
}

if ($member['group_id'] == 2)
{
  echo'Action for Moderator group';
}

if ($member['group_id'] == 36)

{
echo '
<a href="' . $scripturl .  '?action=gallery;sa=myimages;u=',$member['id'], '">', $txt['smfgallery_profilelink'], '</a>';
}


:)
Pas de support par PM ou Courrier...Veuillez utiliser le forum pour vous avoir une réponse rapide à votre demande d'aide. Merci.
Amitiés et à Bientôt...
No support by PM or Mail...You will get better and faster responses in the support forums. Thank you.
Have a nice day...

Dzonny

I would try to print_r member variable somewhere, just to see what can be used for what...
Think that $member['group_id'] should do the trick? There's also post_group which can be used, but like I sad try to print_r it, and you'll see what I'm talking about.

Cmely

the problem with member['group_id'] is that it refer only to the primary membergroups, but not to additional group...and of course (because it wouldn't be fun otherwise  ;D ) I need to check also in additionnal groups...

the field "additional_group" in smf_member table is an array, this is why I was trying with "if(in_array...."

Cmely

Quote from: Dzonny on April 19, 2014, 10:44:21 AM
I would try to print_r member variable somewhere, just to see what can be used for what...
Think that $member['group_id'] should do the trick? There's also post_group which can be used, but like I sad try to print_r it, and you'll see what I'm talking about.

Dzonny, this is what I get when I do a print_r (I show the relevant part) :
[group] => [group_color] => [group_id] => 0 [post_group] => Newborn Baby [post_group_color] => [group_stars] => * [warning] => 0 [warning_status] => [additional_groups] => Array ( [id] => Array ( [0] => 33 [1] => 35 ) [stars] => Array ( [0] => * [1] => * ) [count_based_stars] => * )

margarett

The best way is to merge together the "group_id" and the additional groups in a single array, then you can check if the membergroup you want is present.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Cmely

Quote from: margarett on April 19, 2014, 12:13:07 PM
The best way is to merge together the "group_id" and the additional groups in a single array, then you can check if the membergroup you want is present.

Ok... :o...and how do I merge them together ? As you may already have noticed it, I'm not a great expert in this domain  ;D

margarett

Actually.... Where did you get this from?
[group] => [group_color] => [group_id] => 0 [post_group] => Newborn Baby [post_group_color] => [group_stars] => * [warning] => 0 [warning_status] => [additional_groups] => Array ( [id] => Array ( [0] => 33 [1] => 35 ) [stars] => Array ( [0] => * [1] => * ) [count_based_stars] => * )

In a clean SMF install, the additional membergroups are not fetched for display anywhere...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair


margarett

In which file? Memberlist.template.php?

Can you point me your list of MODs, please?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair


Cmely

Here is the list of mods. Maybe what you're looking for is the mod 'Multiple Stars' (allow you to show several membergroups in your post profile)

Kays

Here's a slightly different approach to this subject.

http://custom.simplemachines.org/mods/index.php?mod=2930

Create a custom permission, assign it only to that group and use that as your check. ;)


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

margarett

Quote from: Cmely on April 19, 2014, 01:19:39 PM
Maybe what you're looking for is the mod 'Multiple Stars' (allow you to show several membergroups in your post profile)
Yup, that should be the one, yes.

Quote from: Kays on April 19, 2014, 01:30:27 PM
Here's a slightly different approach to this subject.
http://custom.simplemachines.org/mods/index.php?mod=2930
Create a custom permission, assign it only to that group and use that as your check. ;)
Probably also a nice idea ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Cmely

Quote from: Kays on April 19, 2014, 01:30:27 PM
Here's a slightly different approach to this subject.

http://custom.simplemachines.org/mods/index.php?mod=2930

Create a custom permission, assign it only to that group and use that as your check. ;)

Thanks for the idea. But I'm afraid it won't work : those custom permission will apply only to the logged in user, right ? And, based on your example, will check if the logged in user belong to that group ?

Advertisement: