| Current Path : /var/www/consult-e-syn/public_html/plugins/ats/usergroups/ |
| Current File : /var/www/consult-e-syn/public_html/plugins/ats/usergroups/usergroups.php |
<?php
/**
* @package ats
* @copyright Copyright (c)2011-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
defined('_JEXEC') or die();
use FOF40\Container\Container;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\User\User as JUser;
class plgAtsUsergroups extends CMSPlugin
{
/** @var array Joomla groups per user ID */
private static $groupsPerUser = [];
private static $groupNames = [];
public function __construct(&$subject, $config = [])
{
parent::__construct($subject, $config);
if (!defined('FOF40_INCLUDED') && !@include_once(JPATH_LIBRARIES . '/fof40/include.php'))
{
throw new RuntimeException('This extension requires FOF 4.', 500);
}
// Prime the cache for group names
$container = Container::getInstance('com_ats');
$db = $container->db;
$query = $db->getQuery(true)
->select([$db->qn('id'), $db->qn('title')])
->from($db->qn('#__usergroups'));
self::$groupNames = $db->setQuery($query)->loadObjectList('id');
}
/**
* Get a list of Joomla groups for a particular user account.
*
* @param JUser $user The user to check
*
* @return array An object with arrays for user groups
*/
public function onAtsGetUserGroupsList(JUser $user = null)
{
if ($user->username == 'system')
{
return [];
}
if (!array_key_exists($user->id, self::$groupsPerUser) && ($user->id <= 0))
{
self::$groupsPerUser[$user->id] = [];
}
if (!array_key_exists($user->id, self::$groupsPerUser))
{
$groups = [];
foreach ($user->groups as $group)
{
if (!isset(self::$groupNames[$group]))
{
continue;
}
$groups[] = self::$groupNames[$group]->title;
}
self::$groupsPerUser[$user->id] = $groups;
}
return self::$groupsPerUser[$user->id];
}
}