Skip to content

Instantly share code, notes, and snippets.

@pepebe
Created April 24, 2012 21:17
Show Gist options
  • Save pepebe/2483894 to your computer and use it in GitHub Desktop.
Save pepebe/2483894 to your computer and use it in GitHub Desktop.
MODx: Get all members of a user group in MODx Revolution.
by kairon - http://www.unchi.co.uk/author/admin/
Get all members of a user group in MODx Revolution. This can been done by accessing the database in the following way.
<?php
$usergroup = 4;
$c = $modx->newQuery('modUser');
$c->innerJoin ('modUserProfile','Profile');
$c->innerJoin ('modUserGroupMember','UserGroupMembers');
$c->innerJoin ('modUserGroup','UserGroup','`UserGroupMembers`.`user_group` = `UserGroup`.`id`');
$c->leftJoin ('modUserGroupRole','UserGroupRole','`UserGroupMembers`.`role` = `UserGroupRole`.`id`');
$c->where(array(
'active' => true,
'UserGroupMembers.user_group' => $usergroup,
'UserGroupMembers.role' => '5',
));
$users = $modx->getCollection('modUser',$c);
foreach($users as $var => $value)
{
// Here you can get profile information e.g. $profile = $user->getOne('Profile');
}
@jpdevries
Copy link

shouldn't it be this?
foreach ($users as $user)

@whatafunc
Copy link

it can be as is then $profile = $value->getOne('Profile');
or in order to be it more consistent the foreach should iterate as you suggest.
just tested and confirmed.
Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment