• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/lib/integration/templates/bitrix24/themepicker.php
  • Класс: BitrixIntranetIntegrationTemplatesBitrix24ThemePicker
  • Вызов: ThemePicker::setCurrentThemeId
public function setCurrentThemeId($themeId, $currentUserId = 0): bool
{
	$contextList = [ $this->getContext() ];
	$entityId = (int)$this->getEntityId();
	if ($entityId <= 0)
	{
		return false;
	}

	if (
		$this->getEntityType() === self::ENTITY_TYPE_SONET_GROUP
		&& Loader::includeModule('socialnetwork')
	)
	{
		$contextList = [];
		$res = WorkgroupSiteTable::getList([
			'filter' => [
				'GROUP_ID' => $entityId
			],
			'select' => [ 'SITE_ID' ]
		]);
		while ($workgroupSiteFields = $res->fetch())
		{
			$contextList[] = $this->getTemplateId() . '_' . $workgroupSiteFields['SITE_ID'];
		}
	}

	if ($this->isValidTheme($themeId))
	{
		//Standard or Custom Own Themes
		if ($themeId !== $this->getDefaultThemeId())
		{
			$currentUserId = (int)$currentUserId;
			if ($currentUserId <= 0)
			{
				$currentUserId = (is_object($GLOBALS["USER"]) ? (int)$GLOBALS["USER"]->getID() : 0);
			}

			foreach ($contextList as $context)
			{
				ThemeTable::set([
					'USER_ID' => $currentUserId,
					'THEME_ID' => $themeId,
					'ENTITY_TYPE' => $this->getEntityType(),
					'ENTITY_ID' => $entityId,
					'CONTEXT' => $context,
				]);
			}
		}
		else
		{
			foreach ($contextList as $context)
			{
				$res = ThemeTable::getList([
					'filter' => [
						'=ENTITY_TYPE' => $this->getEntityType(),
						'ENTITY_ID' => $entityId,
						'=CONTEXT' => $context,
					],
					'select' => [ 'ID' ],
					'cache' => static::getSelectCacheParams(),
				]);
				while ($themeFields = $res->fetch())
				{
					ThemeTable::delete($themeFields['ID']);
				}
			}
		}

		$this->currentTheme = $this->getTheme($themeId);
		$this->setLastUsage($themeId);
		return true;
	}

	if ($themeId === $this->getDefaultThemeId())
	{
		//Custom Admin Theme
		$res = ThemeTable::getList([
			'filter' => [
				'=ENTITY_TYPE' => $this->getEntityType(),
				'ENTITY_ID' => $entityId,
				'=CONTEXT' => $this->getContext(),
			],
			'select' => [ 'ID' ],
			'cache' => static::getSelectCacheParams(),
		]);
		while($themeFields = $res->fetch())
		{
			ThemeTable::delete($themeFields['ID']);
		}

		return true;
	}

	return false;
}