• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/util/user.php
  • Класс: Bitrix\Tasks\Util\User
  • Вызов: User::isAdmin
static function isAdmin($userId = 0)
{
	global $USER;
	static $arCache = array();

	if($userId === 0 || $userId === false)
	{
		$userId = null;
	}

	$isAdmin = false;
	$loggedInUserId = null;

	if ($userId === null)
	{
		if (is_object($USER) && method_exists($USER, 'GetID'))
		{
			$loggedInUserId = (int) $USER->GetID();
			$userId = $loggedInUserId;
		}
		else
		{
			$loggedInUserId = false;
		}
	}

	if ($userId > 0)
	{
		if ( ! isset($arCache[$userId]) )
		{
			if ($loggedInUserId === null)
			{
				if (is_object($USER) && method_exists($USER, 'GetID'))
				{
					$loggedInUserId = (int) $USER->GetID();
				}
			}

			if ((int)$userId === $loggedInUserId)
			{
				$arCache[$userId] = (bool)$USER->isAdmin();
			}
			else
			{

				$ar = \CUser::GetUserGroup($userId);
				if (in_array(1, $ar, true) || in_array('1', $ar, true))
					$arCache[$userId] = true;	// user is admin
				else
					$arCache[$userId] = false;	// user isn't admin
			}
		}

		$isAdmin = $arCache[$userId];
	}

	return ($isAdmin);
}