Hi Forum. I need your help.
I need to get users of defined group.
that’s how I get the group.
$group = $modx->getObject('modUserGroup', array ('id' => '2')); // I get the group
$users = $group->getMany('UserGroupMembers'); // I get the users of this group
Now I want to check if I get the group I need. count($users);
It prints 4. 4 users inside the group. that’s right.
Now I want to show these users on the page.
foreach ($users as $user){
$userdata = $user->toArray();
$profile = $user->getOne('Profile');
$profileData = $profile->toArray();
// username/id
$name = $user->get('username');
$uid = $user->get('id');
$isUserBlocked = $profile->get('blocked');
$extendedFields = $profile->get('extended');
$age = $extendedFields['age'];
// print
if(!preg_match("/(.*?)admin(.*)/iu", $name)){
if($isUserBlocked != '1'){
echo '
<div class="usersforu boxs">
<div class="ufuName">'.$name.'</div>
<div class="ufuAge">Age: '.$age.' '.$unitsAge.'</div>
......
</div>
';
}
}
//end for each
}
I’ve got the problem. There is no users shown on the page. foreach prints nothing; I guess I should disassemble the array $user
with another way. Could tell me how to?