1
Bizzware
$xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2005/3/10 21:07

  • Bizzware

  • Friend of XOOPS

  • Posts: 36

  • Since: 2005/1/11


Are the groups that a logged in user belongs to passed to modules in a variable? I know you can test for admin ($xoops_isadmin) and registered users ($xoops_isuser), but if a custom group is created like 'subscribed', can you test a variable to see if a user belongs to it?

is. <{if $xoops_issubscribed}>...<{else}>...<{/if}>

2
m0nty
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2005/3/10 21:16

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


as far as i'm aware no.. but i'm no expert when it comes down to actual coding..

as everyone may have differnt groups i think it isn't possible like that as no module developer can predict what groups you actually use..

altho i think but not entirely sure the next version of XOOPS might have better group control and linking so it may be possible then..

if you're creating a custom module for yourself tho that will be unique to your site then you could possibly use an sql query to determine the group a member belongs to (as you will already have that group made) so you could do it that way but it'll add extra querys to the page.. you'll have to weigh up the odds..

3
pod
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2005/5/17 0:20

  • pod

  • Quite a regular

  • Posts: 301

  • Since: 2003/4/19


Quote:
as far as i'm aware no.. but i'm no expert when it comes down to actual coding..


Can anyone confirm this?

If m0nty is right, is there a way at least to set the variable somewhere in the php files so it might be used?

4
kaotik
Re: $xoops_isadmin, $xoops_isuser, but $xoops_<custom group>?
  • 2005/5/17 1:20

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Use this code to test if current user belongs to specific group:

//Compare 2 groups through a user uid. 1 user stored in db, other is current. I have to thank Mithrandir for giving me this code.
$db_uid = $row['uid'];
$userid = $xoopsUser->uid();
if ($userid != $db_uid) {
$member_handler =& xoops_gethandler('member');
$db_groups = $member_handler->getGroupsByUser($db_uid);
$current_groups = $xoopsUser->getGroups();
$common_groups = array_intersect($current_groups, $db_groups);
}
if ($userid==$db_uid || !empty($common_groups)){
//do something
}

5
Dave_L
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2005/5/17 1:29

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


This may help. I haven't tested it.

/**
 * Check whether current user is in specified group.
 *
 * @param string $group_name Name of group
 * @return bool True if user is in group, otherwise false
 */
function in_group($group_name) {
   global 
$xoopsUser;
   if (!
is_object($xoopsUser)) {
      return 
false;
   }
   
$member_handler =& xoops_gethandler('member');
   
$groups =& $member_handler->getGroupsByUser($xoopsUser->getVar('uid'), true);
   
$in_group false;
   foreach (
$groups as $group) {
      if (
$group->getVar('name') == $group_name) {
         
$in_group true;
         break;
      }
   }
   return 
$in_group;
}


Then you could assign a template variable:

$xoopsTpl->assign('in_subscribed_group'in_group('subscribed'));


Then in the template:

<{if $in_subscribed_group}>
   ...
<{/if}>

6
pod
Re: Dave_L Rocks Hard
  • 2005/5/17 3:43

  • pod

  • Quite a regular

  • Posts: 301

  • Since: 2003/4/19


Like a friggin dream. Beautiful.

Thanks so much Resized Image

7
khuhner
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2006/6/30 1:20

  • khuhner

  • Quite a regular

  • Posts: 232

  • Since: 2006/1/6 3


DaveL:

Thanks for the solution. This is what I'm looking for as well.

However I dont know where to put it

Can you assist?

Kurt

8
leostotch
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2006/6/30 1:58

  • leostotch

  • Just popping in

  • Posts: 76

  • Since: 2006/4/1 1


Wow !
Why do simple when we can do complicated ?

1st step, insert this in footer.php (if you just need this feature in one of your theme templates), or better: in class/template.php (to make it available in every template).

footer.php version
define("XOOPS_FOOTER_INCLUDED",1);
[
color=FF6666]    if ( @$xoopsUser && is_object($xoopsUser) ) {
        
$xoopsTpl->assign'xoops_usergroups'$xoopsUser->getGroups() );
    }[/
color]


class/template.php version
$this->Smarty();
[
color=FF6666]    global $xoopsUser;
    if ( @
$xoopsUser && is_object($xoopsUser) ) {
        
$this->assign'xoops_usergroups'$xoopsUser->getGroups() );
    }[/
color]


Now you can test if the user is a member of a specific group using something like this in your templates:
Quote:
<{if 1|in_array:$xoops_usergroups}>User is a member of group 1<{/if}>
<{if 2|in_array:$xoops_usergroups}>User is a member of group 2<{/if}>


To use the group name instead of its ID/number isn't recommended: the groupd Id will always stay the same, while you may want to change its display name in the future, whitout having to change all your templates.

9
Shine
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2006/6/30 7:03

  • Shine

  • Just can't stay away

  • Posts: 822

  • Since: 2002/7/22


One word: WOW great tuut ! This is what i was looking for sometime but never knew how to phrase the question (let alone knowing the answer!).
This piece of explanation should be placed within the faq or on the docs website!

Added this topic to my favorites!

10
khuhner
Re: $xoops_isadmin, $xoops_isuser, but $xoops_?
  • 2006/7/2 17:11

  • khuhner

  • Quite a regular

  • Posts: 232

  • Since: 2006/1/6 3


Leostotch:

This code ROCKS! This is the best, streamlined snippet of code I have ever used from xoops.org!

I'm still coming up to speed on XOOPS coding (it takes a while!) so I appreciate the step by step instructions and the fact it worked the first time!

Thanks again for your contribution. I think this code could be integrated into XOOPS as many people could make use of it.

Kurt

Login

Who's Online

361 user(s) are online (315 user(s) are browsing Support Forums)


Members: 0


Guests: 361


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits