Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
feedbackform.php
1<?php
2namespace Bitrix\UI\Form;
3
9
11{
12 protected $id;
13 protected $isCloud;
14 protected $formParams = [];
15 protected $presets = [];
16 protected $title;
17 protected $portalUri;
18
19 public function __construct(string $id)
20 {
21 if ($id == '')
22 {
23 throw new ArgumentException(' Feedback form id can not be empty');
24 }
25 $this->id = $id;
26 $this->isCloud = Loader::includeModule('bitrix24');
27 $this->title = Loc::getMessage('UI_FEEDBACK_FORM_BUTTON');
28 $this->portalUri = 'https://product-feedback.bitrix24.com';
29 }
30
31 public function getId()
32 {
33 return $this->id;
34 }
35
36 public function getFormParams()
37 {
38 return $this->formParams;
39 }
40
41 public function setFormParamsDirectly($form)
42 {
43 $form['lang'] = $form['lang']??LANGUAGE_ID;
44 $this->formParams = $form;
45 }
46
47 public function getPresets()
48 {
50 $presets['b24_plan'] = $this->isCloud ? \CBitrix24::getLicenseType() : '';
51 $presets['b24_plan_date_to'] = (
52 $this->isCloud
53 ? ConvertTimeStamp(Option::get('main', '~controller_group_till', time()))
54 : ''
55 );
56 $presets['b24_partner_id'] = (
57 ($this->isCloud && method_exists('CBitrix24', 'getPartnerId'))
58 ? \CBitrix24::getPartnerId()
59 : ''
60 );
61
62 $presets['hosturl'] = Main\Engine\UrlManager::getInstance()->getHostUrl();
63 $presets['hostname'] = parse_url($presets['hosturl'], PHP_URL_HOST);
64
65 global $USER;
66 $name = '';
67 $email = '';
68 if(is_object($USER))
69 {
70 $name = $USER->GetFirstName();
71 if(!$name)
72 {
73 $name = $USER->GetLogin();
74 }
75 $email = $USER->GetEmail();
76 }
77 $presets['c_name'] = $name;
78 $presets['c_email'] = $email;
79
80 return $presets;
81 }
82
83 public function getTitle()
84 {
85 return $this->title;
86 }
87
88 public function getPortalUri()
89 {
90 return $this->portalUri;
91 }
92
93 public function getJsObjectParams()
94 {
95 return [
96 'id' => $this->getId(),
97 'form' => $this->getFormParams(),
98 'presets' => $this->getPresets(),
99 'title' => $this->getTitle(),
100 'portal' => $this->getPortalUri()
101 ];
102 }
103
104 public function setFormParams(array $forms)
105 {
106 if ($this->isCloud && isset($forms['prefixes']))
107 {
108 $zone = \CBitrix24::getLicensePrefix();
109 $defaultForm = null;
110 foreach ($forms as $form)
111 {
112 if (!isset($form['licenseZones']) || !isset($form['zones']) || !is_array($forms['licenseZones']))
113 {
114 continue;
115 }
116
117 if (in_array($zone, $forms['licenseZones']))
118 {
119 $form['lang'] = $form['lang']??LANGUAGE_ID;
120 $this->formParams = $form;
121 return;
122 }
123
124 if (in_array('en', $forms['licenseZones']))
125 {
126 $form['lang'] = $form['lang']??LANGUAGE_ID;
127 $defaultForm = $form;
128 }
129 }
130
131 $this->formParams = $defaultForm;
132 }
133 else if ($this->isCloud)
134 {
135 $zone = \CBitrix24::getPortalZone();
136 $defaultForm = null;
137 foreach ($forms as $form)
138 {
139 if (!isset($form['zones']) || !is_array($form['zones']))
140 {
141 continue;
142 }
143
144 if (in_array($zone, $form['zones']))
145 {
146 $form['lang'] = $form['lang']??LANGUAGE_ID;
147 $this->formParams = $form;
148 return;
149 }
150
151 if (in_array('en', $form['zones']))
152 {
153 $form['lang'] = $form['lang']??LANGUAGE_ID;
154 $defaultForm = $form;
155 }
156 }
157
158 $this->formParams = $defaultForm;
159 }
160 else
161 {
162 $lang = LANGUAGE_ID;
163 $defaultForm = null;
164 foreach ($forms as $form)
165 {
166 if (!isset($form['lang']))
167 {
168 continue;
169 }
170
171 if ($lang === $form['lang'])
172 {
173 $this->formParams = $form;
174 return;
175 }
176
177 if ($form['lang'] === 'en')
178 {
179 $defaultForm = $form;
180 }
181 }
182
183 $this->formParams = $defaultForm;
184 }
185 }
186
187 public function setPresets(array $presets = [])
188 {
189 $this->presets = $presets;
190 }
191
192 public function setTitle(string $title)
193 {
194 $this->title = $title;
195 }
196
197 public function setPortalUri(string $portalUri)
198 {
199 $this->portalUri = $portalUri;
200 }
201}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
setPresets(array $presets=[])
setPortalUri(string $portalUri)