<![CDATA[ How to check user is in group [Revolution]? - MODX Community Forums]]> https://forums.modx.com/thread/?thread=31541 <![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170635
Glad you got is sorted. Thanks for reporting back. smiley]]>
BobRay Aug 13, 2010, 09:48 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170635
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170634 noff Aug 13, 2010, 04:27 AM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170634 <![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170633
/* get the user and group objects (unless you already have them) */
$user = $modx->getObject('modUser',array('name'=>'JoeBlow'));
$groupr = $modx->getObject('modUserGroup',array('name'=>'Editors'));

$userId = $user->get('id');
$groupId = $group->get('id');

$groupMember = $modx->getObject('modUserGroupMember', array('user_group'->$groupId,'member'=>$userId));

BobRay Aug 12, 2010, 11:51 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170633
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170632 So I will hope.

One more question.

Your code (adding user to existing group):
$member = $modx->newObject('modUserGroupMember');


How to remove user from group using same syntax?

noff Aug 12, 2010, 02:04 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170632
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170631
I’m going to guess that your real problem is that you need to create the usergroup and the user objects properly using xPDO so that they have the proper relations. And you need to add the members to the user groups properly too. Something like this:

/* create a user group */
$groupName = 'SomeName';

$alreadyExists = $modx->getObject('modUserGroup',array('name' => $groupName));
if ($alreadyExists) return $modx->error->failure($modx->lexicon('user_group_err_already_exists'));

/* create group */
$usergroup = $modx->newObject('modUserGroup');

/* add current user as a member */

$member = $modx->newObject('modUserGroupMember');


/* save usergroup */
if ($usergroup->save() == false) {
    return $modx->error->failure($modx->lexicon('user_group_err_create'));

Writing to the DB directly without going through xPDO is always risky and you can end up with confused relationships. Note: The stuff you did earlier may have left the DB in an unreliable state. It would be best to start with a fresh install.]]>
BobRay Aug 12, 2010, 12:43 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution?page=2#dis-post-170631
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170630
I have site hackday.ru

At site I have Events (HackDay’s):

Every HackDay is a single event with separate auditory.

Every user can join to any event.

Membership of user in event I checking by:
1. For every event there is unique usergroup: http://s3.amazonaws.com/floomby/8_11_2010/z2oTGNAuZk2KpTdnuJLGIw.jpg
2. If user is in the group, he is a member of event.

So, if he is not a member of event/group, he can join it. Else he can leave this event/group.

I can check current group/event. It works. In my code I know group name - I got it from database.

But when I trying to use $modx->user->isMember() it telling me, that user is not in this group. But I see in database, he is member of this group.

PS: I am telling about webusers, registered buy "Login" snippet.
PPS: I am trying to use groups because I see this is single method to use native MODX features without creating additional tables in database.]]>
noff Aug 11, 2010, 03:48 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170630
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170629 Quote from: noff at Aug 11, 2010, 09:02 AM

So, result of isMember is wrong. Why?

Let’s back up.

I’m having trouble figuring out why you want to know if a user is a member of a group you don’t know the name of.

Can you explain exactly what you are trying to do and why, without mentioning any MODx methods? In Revolution, there’s a very good chance that you can solve the problem with no code at all by using the Access Control system.]]>
BobRay Aug 11, 2010, 12:04 PM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170629
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170628 Quote from: noff at Aug 11, 2010, 09:28 AM

Bob has typo in his code

Fixed. Thanks.]]>
BobRay Aug 11, 2010, 11:37 AM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170628
<![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170627 noff Aug 11, 2010, 04:28 AM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170627 <![CDATA[Re: How to check user is in group [Revolution]?]]> https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170626
Not sure if this can help, but if I compare your code and the Bob’s one there’s a difference in the get group part

YOUR code
// Get group
$group = $modx->GetObject('modUserGroup', array ('id' => $eventGroup));

BOB's code
$modx->GetObject('modUserGroup', array ('id')=>$event) ); 

=> parenthesis in Bob’s code are around (’id’), in your code parenthesis begins before ’id’ but is closed after $eventGroup ... However, no idea if it can explain your problem...
anso Aug 11, 2010, 04:13 AM https://forums.modx.com/thread/31541/how-to-check-user-is-in-group-revolution#dis-post-170626