Skip to content

Commit 6e72510

Browse files
committed
New Method get usersInGroup
1 parent 4f98b92 commit 6e72510

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

administrator/components/com_users/src/Model/GroupModel.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Joomla\CMS\Object\CMSObject;
2222
use Joomla\CMS\Plugin\PluginHelper;
2323
use Joomla\CMS\Table\Table;
24+
use Joomla\Database\ParameterType;
2425
use Joomla\String\StringHelper;
2526
use Joomla\Utilities\ArrayHelper;
2627

@@ -344,4 +345,44 @@ protected function generateGroupTitle($parentId, $title)
344345

345346
return $title;
346347
}
348+
349+
/**
350+
* Method to get all users in a group.
351+
*
352+
* @param integer $groupId The id of the group.
353+
*
354+
* @return array Returns an array of users on success, an empty array on failure.
355+
*
356+
* @since __DEPLOY_VERSION__
357+
*/
358+
public function getUsersInGroup($groupId)
359+
{
360+
$db = $this->getDatabase();
361+
362+
// Get the userId's in the group
363+
$db->setQuery(
364+
$db->getQuery(true)
365+
->select($db->quoteName('user_id'))
366+
->from($db->quoteName('#__user_usergroup_map'))
367+
->where($db->quoteName('group_id') . ' = :id')
368+
->bind(':id', $groupId, ParameterType::INTEGER)
369+
);
370+
371+
$group = $db->loadColumn();
372+
373+
if (empty($group)) {
374+
// No users in the group
375+
return [];
376+
}
377+
378+
// Get the users information of the users in the group
379+
$query = $db->getQuery(true)
380+
->select($db->quoteName(['id', 'name', 'username', 'email', 'block', 'sendEmail', 'params']))
381+
->from($db->quoteName('#__users'))
382+
->whereIn($db->quoteName('id'), $group);
383+
384+
$db->setQuery($query);
385+
386+
return $db->loadObjectList();
387+
}
347388
}

0 commit comments

Comments
 (0)