1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
RequestParametersBuilder.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Helpdesk;
4
5use Bitrix\ImBot\Bot\Network;
6use Bitrix\ImBot\Bot\Partner24;
7use Bitrix\ImBot\Bot\Support24;
8use Bitrix\ImBot\Bot\SupportBox;
9use Bitrix\Main\Application;
10use Bitrix\Main\Config\Option;
11use Bitrix\Main\Context;
12use Bitrix\Main\Engine\CurrentUser;
13use Bitrix\Main\Event;
14use Bitrix\Main\Loader;
15use Bitrix\Intranet;
16use Bitrix\Bitrix24;
17
19{
20 private CurrentUser $currentUser;
24 private array $parameters = [];
25 private bool $isCloud;
26
27 public function __construct()
28 {
29 $this->currentUser = CurrentUser::get();
30 $this->isCloud = Loader::includeModule('bitrix24');
31 }
32
33 public function build(): array
34 {
35 $this->buildPortalInformation();
36 $this->buildUserCharacteristics();
37 $this->buildSupportConfiguration();
38 $this->buildKeyConfiguration();
39 $this->buildExternalParameters();
40 $this->buildHeadInformation();
41
42 return $this->parameters;
43 }
44
45 private function buildSupportConfiguration(): void
46 {
47 if (!Loader::includeModule('imbot'))
48 {
49 return;
50 }
51
52 $this->parameters += [
53 'support_partner_code' => Partner24::getBotCode(),
54 'support_partner_name' => Partner24::getPartnerName(),
55 ];
56 $supportBotId = 0;
57
58 if (Support24::getSupportLevel() === Network::SUPPORT_LEVEL_PAID && Support24::isEnabled())
59 {
60 $supportBotId = Support24::getBotId();
61 }
62 elseif (SupportBox::isEnabled())
63 {
64 $supportBotId = SupportBox::getBotId();
65 }
66
67 $this->parameters['support_bot'] = $supportBotId;
68 }
69
70 private function buildExternalParameters(): void
71 {
72 $method = '\\' . __METHOD__;
73 $event = (new Event('ui', $method, $this->parameters));
74 $event->send();
75
76 foreach ($event->getResults() as $eventResult)
77 {
78 if (($eventParameters = $eventResult->getParameters()) && is_array($eventParameters))
79 {
80 $this->parameters = array_merge($this->parameters, $eventParameters);
81 }
82 }
83 }
84
85 private function buildKeyConfiguration(): void
86 {
87 if ($this->isCloud)
88 {
89 $this->parameters['key'] = \CBitrix24::requestSign($this->getHostName() . $this->currentUser->getId());
90 }
91 else
92 {
93 $this->parameters['head'] = md5('BITRIX' . Application::getInstance()->getLicense()->getKey() . 'LICENCE');
94 $this->parameters['key'] = md5($this->getHostName() . $this->currentUser->getId() . $this->parameters['head']);
95 }
96 }
97
98 private function buildUserCharacteristics(): void
99 {
100 $userId = $this->currentUser->getId();
101 $this->parameters += [
102 'is_admin' => ($this->isCloud && \CBitrix24::isPortalAdmin($userId))
103 || (!$this->isCloud && $this->currentUser->isAdmin()) ? 1 : 0,
104 'is_integrator' => (int)($this->isCloud && \CBitrix24::isIntegrator($userId)),
105 'user_id' => $userId,
106 'user_email' => $this->currentUser->getEmail(),
107 'user_name' => $this->currentUser->getFirstName(),
108 'user_last_name' => $this->currentUser->getLastName(),
109 ];
110
111 if (Loader::includeModule('intranet'))
112 {
113 $this->parameters['user_date_register'] = \Bitrix\Intranet\CurrentUser::get()->getDateRegister()?->getTimestamp();
114
115 if (method_exists(Intranet\User::class, 'getUserRole'))
116 {
117 $this->parameters['user_type'] = (new Intranet\User())->getUserRole()->value;
118 }
119 }
120 }
121
122 private function buildPortalInformation(): void
123 {
124 $this->parameters += [
125 'tariff' => Option::get('main', '~controller_group_name', ''),
126 'is_cloud' => $this->isCloud ? '1' : '0',
127 'host' => $this->getHostName(),
128 'languageId' => LANGUAGE_ID,
129 'demoStatus' => $this->getDemoStatus(),
130 'isAutoPay' => $this->isCloud && \CBitrix24::isAutoPayLicense(),
131 ];
132
133 if ($this->isCloud)
134 {
135 $this->parameters += [
136 'portal_date_register' => Option::get('main', '~controller_date_create', ''),
137 'canAllUsersBuyTariff' => \CBitrix24::canAllBuyLicense(),
138 'isSidePanelDemoLicense' => Option::get('bitrix24', 'isSidePanelDemoLicense') === 'Y',
139 ];
140 }
141 }
142
143 private function buildHeadInformation(): void
144 {
145 if (!Loader::includeModule('intranet'))
146 {
147 return;
148 }
149
150 $currentUser = Intranet\CurrentUser::get();
151 $heads = \CIntranetUtils::GetDepartmentManager($currentUser->getDepartmentIds(), $currentUser->getId(), true);
152
153 if (empty($heads))
154 {
155 $this->parameters['isSubordinate'] = 0;
156
157 return;
158 }
159
160 foreach ($heads as $head)
161 {
162 if (!empty($head) && isset($head['ID']))
163 {
164 $this->parameters += [
165 'tools' => [
166 'isSubordinate' => 1,
167 'head' => [
168 'id' => (int)$head['ID'],
169 'name' => \CUser::FormatName(\CSite::GetNameFormat(false), $head),
170 'avatar' => $this->prepareUserPhoto($head),
171 ],
172 ],
173 ];
174
175 return;
176 }
177 }
178 }
179
180 private function prepareUserPhoto(array $headData): ?string
181 {
182 return $headData['PERSONAL_PHOTO'] ? (string)Intranet\Component\UserProfile::getUserPhoto($headData['PERSONAL_PHOTO']) : '';
183 }
184
185 private function getHostName(): ?string
186 {
187 if ($this->isCloud && defined('BX24_HOST_NAME'))
188 {
189 return BX24_HOST_NAME;
190 }
191
192 return Context::getCurrent()?->getRequest()->getHttpHost();
193 }
194
195 private function getDemoStatus(): string
196 {
197 if (Loader::includeModule('bitrix24'))
198 {
199 if (\CBitrix24::IsDemoLicense())
200 {
201 return 'ACTIVE';
202 }
203
204 if (Bitrix24\Feature::isEditionTrialable('demo'))
205 {
206 return 'AVAILABLE';
207 }
208
209 return 'EXPIRED';
210 }
211
212 return 'UNKNOWN';
213 }
214}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
getUserRole(int $collabId, int $userId)
Определения GetRoleTrait.php:11
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$method
Определения index.php:27