1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
feedbackform.php
См. документацию.
1<?php
2
3namespace Bitrix\UI\Form;
4
5use Bitrix\Main;
6use Bitrix\Main\Application;
7use Bitrix\Main\ArgumentException;
8use Bitrix\Main\License\UrlProvider;
9use Bitrix\Main\Loader;
10use Bitrix\Main\Localization\Loc;
11use Bitrix\Main\Config\Option;
12
14{
15 protected string $id;
16 protected bool $isCloud;
18 protected array $presets = [];
19 protected string $title;
20 protected string $portalUri;
21
22 public function __construct(string $id)
23 {
24 if ($id === '')
25 {
26 throw new ArgumentException(' Feedback form id can not be empty');
27 }
28 $this->id = $id;
29 $this->isCloud = Loader::includeModule('bitrix24');
30 $this->title = Loc::getMessage('UI_FEEDBACK_FORM_BUTTON');
31 $this->portalUri = 'https://' . (new UrlProvider())->getFeedbackDomain();
32 }
33
34 public function getId(): string
35 {
36 return $this->id;
37 }
38
39 public function getCurrentForm(): ?array
40 {
41 return $this->currentForm?->toArray();
42 }
43
44 public function setPresets(array $presets = []): void
45 {
46 $this->presets = $presets;
47 }
48
49 public function getPresets(): array
50 {
52 $presets['b24_plan'] = $this->isCloud ? \CBitrix24::getLicenseType() : '';
53 $presets['b24_plan_date_to'] = (
54 $this->isCloud
55 ? ConvertTimeStamp(Option::get('main', '~controller_group_till', time()))
56 : ''
57 );
58 $presets['b24_partner_id'] = (
59 ($this->isCloud && method_exists('CBitrix24', 'getPartnerId'))
60 ? \CBitrix24::getPartnerId()
61 : ''
62 );
63
64 $presets['hosturl'] = Main\Engine\UrlManager::getInstance()->getHostUrl();
65 $presets['hostname'] = parse_url($presets['hosturl'], PHP_URL_HOST);
66
67 global $USER;
68 $name = '';
69 $email = '';
70 if (is_object($USER))
71 {
72 $name = $USER->GetFirstName();
73 if (!$name)
74 {
75 $name = $USER->GetLogin();
76 }
77 $email = $USER->GetEmail();
78 }
79 $presets['c_name'] = $name;
80 $presets['c_email'] = $email;
81
82 $business = Option::get('bitrix24', 'CJM-business', null);
83 if (isset($business))
84 {
85 $presets['business'] = $business;
86 }
87
88 return $presets;
89 }
90
91 public function setTitle(string $title): void
92 {
93 $this->title = $title;
94 }
95
96 public function getTitle(): ?string
97 {
98 return $this->title;
99 }
100
101 public function setPortalUri(string $portalUri): void
102 {
103 $this->portalUri = $portalUri;
104 }
105
106 public function getPortalUri(): string
107 {
108 return $this->portalUri;
109 }
110
111 public function getJsObjectParams(): array
112 {
113 return [
114 'id' => $this->getId(),
115 'form' => $this->getCurrentForm() ?? [],
116 'presets' => $this->getPresets(),
117 'title' => $this->getTitle(),
118 'portal' => $this->getPortalUri(),
119 ];
120 }
121
122 public function setFormParams(array $params): void
123 {
124 $forms = [];
125
126 foreach ($params as $item)
127 {
128 if (!isset($item['id'], $item['sec']))
129 {
130 continue;
131 }
132
133 $form = new FeedbackFormParams();
134 $form->id = (int)$item['id'];
135 $form->sec = (string)$item['sec'];
136 $form->zones = $item['zones'] ?? [$this->getDefaultZone()];
137 $form->lang = $item['lang'] ?? $this->getDefaultLang();
138
139 $forms[] = $form;
140 }
141
142 $forms = $this->findFormByZone($forms);
143 if (count($forms) === 0)
144 {
145 return;
146 }
147
148 $forms = $this->findByLang($forms);
149
150 $this->currentForm = array_shift($forms);
151 }
152
157 private function findFormByZone(array $forms): array
158 {
159 $zone = $this->getZone() ?? $this->getDefaultZone();
160 $found = array_filter($forms, static function ($form) use ($zone)
161 {
162 return in_array($zone, $form->zones, true);
163 });
164
165 if (count($found) === 0)
166 {
167 $zoneDefault = $this->getDefaultZone();
168 $found = array_filter($forms, static function ($form) use ($zoneDefault)
169 {
170 return in_array($zoneDefault, $form->zones, true);
171 });
172 }
173
174 return $found;
175 }
176
181 private function findByLang(array $forms): array
182 {
183 $lang = $this->getLang();
184 $found = array_filter($forms, static function ($form) use ($lang)
185 {
186 return $lang === $form->lang;
187 });
188
189 if (count($found) === 0)
190 {
191 $langDefault = $this->getDefaultLang();
192 $found = array_filter($forms, static function ($form) use ($langDefault)
193 {
194 return $langDefault === $form->lang;
195 });
196 }
197
198 return count($found) > 0 ? $found : $forms;
199 }
200
206 public function setFormParamsDirectly(array $formParams): void
207 {
208 if (!isset($formParams['id'], $formParams['sec']))
209 {
210 return;
211 }
212
213 $form = new FeedbackFormParams();
214 $form->id = (int)$formParams['id'];
215 $form->sec = (string)$formParams['sec'];
216 $form->zones = $formParams['zones'] ?? [$this->getDefaultZone()];
217 $form->lang = $formParams['lang'] ?? $this->getDefaultLang();
218
219 $this->currentForm = $form;
220 }
221
222 protected function getZone(): ?string
223 {
224 return Application::getInstance()->getLicense()->getRegion();
225 }
226
227 private function getDefaultZone(): string
228 {
229 return $this->isCis() ? 'ru' : 'en';
230 }
231
232 protected function getLang(): string
233 {
234 return LANGUAGE_ID;
235 }
236
237 private function getDefaultLang(): string
238 {
239 return $this->isCis() ? 'ru' : 'en';
240 }
241
242 private function isCis(): bool
243 {
244 $zone = $this->getZone() ?? '';
245
246 return in_array($zone, ['ru', 'by', 'kz', 'uz']);
247 }
248
249 public static function getCisZones(): array
250 {
251 return ['ru'];
252 }
253
254 public static function getWestZones(): array
255 {
256 return ['en'];
257 }
258}
static getInstance()
Определения urlmanager.php:28
static getWestZones()
Определения feedbackform.php:254
setPresets(array $presets=[])
Определения feedbackform.php:44
array $presets
Определения feedbackform.php:18
setPortalUri(string $portalUri)
Определения feedbackform.php:101
setFormParams(array $params)
Определения feedbackform.php:122
string $title
Определения feedbackform.php:19
setTitle(string $title)
Определения feedbackform.php:91
FeedbackFormParams $currentForm
Определения feedbackform.php:17
string $portalUri
Определения feedbackform.php:20
static getCisZones()
Определения feedbackform.php:249
setFormParamsDirectly(array $formParams)
Определения feedbackform.php:206
__construct(string $id)
Определения feedbackform.php:22
</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
if(!defined('SITE_ID')) $lang
Определения include.php:91
$name
Определения menu_edit.php:35
$email
Определения payment.php:49
<? endif;?> window document title
Определения prolog_main_admin.php:76
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799