helper.php
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @package Joomla.Site
* @subpackage mod_users_latest
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Helper for mod_users_latest
*
* @since 1.6
*/
class ModUsersLatestHelper
{
/**
* Get users sorted by activation date
*
* @param \Joomla\Registry\Registry $params module parameters
*
* @return array The array of users
*
* @since 1.6
*/
public static function getUsers($params)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName(array('a.id', 'a.name', 'a.username', 'a.registerDate')))
->order($db->quoteName('a.registerDate') . ' DESC')
->from('#__users AS a');
$user = JFactory::getUser();
if (!$user->authorise('core.admin') && $params->get('filter_groups', 0) == 1)
{
$groups = $user->getAuthorisedGroups();
if (empty($groups))
{
return array();
}
$query->join('LEFT', '#__user_usergroup_map AS m ON m.user_id = a.id')
->join('LEFT', '#__usergroups AS ug ON ug.id = m.group_id')
->where('ug.id in (' . implode(',', $groups) . ')')
->where('ug.id <> 1');
}
$db->setQuery($query, 0, $params->get('shownumber', 5));
try
{
return (array) $db->loadObjectList();
}
catch (RuntimeException $e)
{
JFactory::getApplication()->enqueueMessage(JText::_('JERROR_AN_ERROR_HAS_OCCURRED'), 'error');
return array();
}
}
}