• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/integration/templates/bitrix24/themepicker.php
  • Класс: BitrixIntranetIntegrationTemplatesBitrix24ThemePicker
  • Вызов: ThemePicker::__construct
public function __construct($templateId, $siteId = false, $userId = 0, $entityType = self::ENTITY_TYPE_USER, $entityId = 0, $params = [])
{
	if (!static::isValidTemplateId($templateId))
	{
		throw new ArgumentException("The given argument 'templateId' is incorrect.");
	}

	$this->templateId = $templateId;
	$this->templatePath = getLocalPath("templates/".$templateId, BX_PERSONAL_ROOT);
	$this->siteId = is_string($siteId)? mb_substr(preg_replace("/[^a-z0-9_]/i", "", $siteId), 0, 2) : SITE_ID;
	if (in_array($entityType, self::VALID_ENTITY_TYPE_LIST))
	{
		$this->entityType = $entityType;
	}

	if (
		isset($params['behaviour'])
		&& in_array((string)$params['behaviour'], self::VALID_BEHAVIOUR_LIST)
	)
	{
		$this->behaviour = (string)$params['behaviour'];
	}

	if (is_numeric($userId) && $userId > 0)
	{
		$this->userId = $userId;
	}
	else
	{
		$user = &$GLOBALS['USER'];
		if ($user instanceof CUser)
		{
			$this->userId = (int)$user->getId();
		}
	}

	if (is_numeric($entityId) && $entityId > 0)
	{
		$this->entityId = $entityId;
	}
	elseif ($entityType === self::ENTITY_TYPE_USER)
	{
		$this->entityId = $this->userId;
	}

	if (Loader::includeModule('bitrix24'))
	{
		$this->zoneId = CBitrix24::getPortalZone();
	}
	else
	{
		$context = Context::getCurrent();
		$this->zoneId = $context !== null ? $context->getLanguage() : "en";
	}

	$res = ThemeTable::getList([
		'filter' => [
			'=ENTITY_TYPE' => $this->getEntityType(),
			'ENTITY_ID' => $this->getEntityId(),
			'=CONTEXT' => $this->getContext(),
		],
		'select' => [ 'THEME_ID', 'ENTITY_TYPE', 'USER_ID' ],
		'cache' => static::getSelectCacheParams(),
	]);

	if (
		($themeFields = $res->fetch())
		&& $this->isValidTheme($themeFields['THEME_ID'], ($themeFields['ENTITY_TYPE'] === self::ENTITY_TYPE_SONET_GROUP ? (int)$themeFields['USER_ID'] : false))
	)
	{
		$this->currentTheme = $this->getTheme($themeFields['THEME_ID'], ($themeFields['ENTITY_TYPE'] === self::ENTITY_TYPE_SONET_GROUP ? $themeFields['USER_ID'] : false));
	}
	else
	{
		$this->currentTheme = $this->getDefaultTheme();
	}
}