Answer the question
In order to leave comments, you need to log in
Modx Revo API how to parse array of received users?
This is how I define the desired user group (there are only 4 of them)
$group = $modx->getObject('modUserGroup', array ('id' => '2'));
$users = $group->getMany('UserGroupMembers');
$users
we have users from the group we need. Did a check count($users)
showed 4 - 4 users in this group. Correctly. foreach ($users as $user){
// получаем имя и id пользователя
$name = $user->get('username'); //name
$uid = $user->get('id'); //id
// связь с профилем пользователя
$profile = $user->getOne('Profile');
$isUserBlocked = $profile->get('blocked'); // заблокирован ли юзер
$extendedFields = $profile->get('extended'); // доп поля
$age = $extendedFields['age']; // возраст получили из доп полей
$unitsAge = $modx->runSnippet("units", array('input' => $age, 'options' => 'год|года|лет')); //компонент units
// выводим данные
if(!preg_match("/(.*?)admin(.*)/iu", $name)){ //не выводим админа
if($isUserBlocked != '1'){ // не выводим заблокированых юзеров
echo '
<div class="usersforu boxs">
<div class="ufuName">'.$name.'</div>
<div class="ufuAge">Возраст: '.$age.' '.$unitsAge.'</div>
...
</div>
';
}
}
//end for each
}
Answer the question
In order to leave comments, you need to log in
Did it like this:
$group = $modx->getObject('modUserGroup', array ('id' => '5'));
$members = $group->getMany('UserGroupMembers');
foreach ($members as $member){
$user = $member->getOne('User'); // важно
// получаем имя пользователя
$name = $user->get('username');
$uid = $user->get('id');
// связь с профилем пользователя
$profile = $user->getOne('Profile');
....
}
It's very simple, $user is not the object you expect. The UserGroupMembers object is associated with the modUser object via the member field, so you need to do this
foreach ($users as $user){
// получаем id пользователя
$uid = $user->get('member');
// получаем объект пользователя
$user = $modx->getObject('modUser', $uid);
// получаем имя пользователя
$name = $user->get('username');
// получаем профиль пользователя
$profile = $user->getOne('Profile');
/****тут остальной код*****/
//end for each
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question