|
21 | 21 | use Joomla\CMS\Object\CMSObject; |
22 | 22 | use Joomla\CMS\Plugin\PluginHelper; |
23 | 23 | use Joomla\CMS\Table\Table; |
| 24 | +use Joomla\Database\ParameterType; |
24 | 25 | use Joomla\String\StringHelper; |
25 | 26 | use Joomla\Utilities\ArrayHelper; |
26 | 27 |
|
@@ -344,4 +345,44 @@ protected function generateGroupTitle($parentId, $title) |
344 | 345 |
|
345 | 346 | return $title; |
346 | 347 | } |
| 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 | + } |
347 | 388 | } |
0 commit comments