1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
themepicker.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Integration\Intranet;
4
5use Bitrix\Intranet\Integration\Templates\Bitrix24;
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\Loader;
8
10{
11 public static function getDefaultPortalThemeId(): ?string
12 {
13 if (!self::isAvaliable())
14 {
15 return null;
16 }
17
18 return Bitrix24\ThemePicker::getInstance()?->getDefaultThemeId();
19 }
20
21 public static function getThemePicker(
22 int $groupId,
23 int $userId,
24 string $siteId = SITE_ID,
25 string $templateId = SITE_TEMPLATE_ID,
26
28 {
29 if (!self::isAvaliable())
30 {
31 return null;
32 }
33
34 try
35 {
36 return new Bitrix24\ThemePicker(
38 $siteId,
39 $userId,
40 Bitrix24\ThemePicker::ENTITY_TYPE_SONET_GROUP,
41 $groupId
42 );
43 }
44 catch (ArgumentException)
45 {
46 return null;
47 }
48 }
49
50 public static function applyUserTheme(): void
51 {
52 if (!self::isAvaliable())
53 {
54 return;
55 }
56
57 $themePicker = self::getUserThemePicker();
58
59 self::applyTheme($themePicker);
60 }
61
62 public static function applyGroupTheme(int $groupId): void
63 {
64 if (!self::isAvaliable())
65 {
66 return;
67 }
68
69 $themePicker = self::getGroupThemePicker($groupId);
70
71 self::applyTheme($themePicker);
72 }
73
74 public static function getUserTheme(): array
75 {
76 if (!self::isAvaliable())
77 {
78 return [];
79 }
80
81 return self::getUserThemePicker()->getCurrentTheme();
82 }
83
84 public static function getGroupTheme(int $groupId): array
85 {
86 if (!self::isAvaliable())
87 {
88 return [];
89 }
90
91 return self::getGroupThemePicker($groupId)->getCurrentTheme();
92 }
93
94 protected static function getUserThemePicker(): Bitrix24\ThemePicker
95 {
96 return new Bitrix24\ThemePicker(
97 SITE_TEMPLATE_ID,
98 SITE_ID,
99 self::getUserId(),
100 Bitrix24\ThemePicker::ENTITY_TYPE_USER,
101 self::getUserId(),
102 );
103 }
104
105 protected static function getGroupThemePicker(int $groupId): Bitrix24\ThemePicker
106 {
107 return new Bitrix24\ThemePicker(
108 SITE_TEMPLATE_ID,
109 SITE_ID,
110 self::getUserId(),
111 Bitrix24\ThemePicker::ENTITY_TYPE_SONET_GROUP,
112 $groupId,
113 );
114 }
115
116 protected static function isAvaliable(): bool
117 {
118 return Loader::includeModule('intranet') && Bitrix24\ThemePicker::isAvailable();
119 }
120
121 protected static function applyTheme(Bitrix24\ThemePicker $themePicker)
122 {
123 $themePicker->showHeadAssets();
124 $themePicker->showBodyAssets();
125
126 $baseTheme = $themePicker->getCurrentBaseThemeId();
127 echo <<<JS
128<script>
129 BX.ready(() => {
130 document.body.className = document.body.className.replace(/bitrix24-[^\s]*-theme/, '');
131 document.body.classList.add("bitrix24-$baseTheme-theme");
132 });
133</script>
134JS;
135 }
136
137 protected static function getUserId(): int
138 {
139 global $USER;
140
141 return (int)$USER->getId();
142 }
143}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static applyGroupTheme(int $groupId)
Определения themepicker.php:62
static applyTheme(Bitrix24\ThemePicker $themePicker)
Определения themepicker.php:121
static getGroupThemePicker(int $groupId)
Определения themepicker.php:105
static getThemePicker(int $groupId, int $userId, string $siteId=SITE_ID, string $templateId=SITE_TEMPLATE_ID,)
Определения themepicker.php:21
static getGroupTheme(int $groupId)
Определения themepicker.php:84
$templateId
Определения component_props2.php:51
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
global $USER
Определения csv_new_run.php:40
$siteId
Определения ajax.php:8
const SITE_ID
Определения sonet_set_content_view.php:12