Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
analyticboard.php
1<?php
3
8
14{
15 private $title;
16 private $boardKey;
17 private $machineKey;
18 private $filter;
19 private $batchKey = null;
20 private $group = null;
21 private $buttons = [];
22 private $disabled = false;
23 private $stepperEnabled = false;
24 private $stepperIds = [];
25 private $limited = false;
26 private $limitComponentParams = [];
27 private $isExternal = false;
28 private $externalUrl = "";
29 private $isSliderSupport = true;
30 private $options;
31 private $setOptionsCallback;
32 private ?string $sliderLoader = null;
33
34 public function __construct(string $boardId = '', array $options = [])
35 {
36 $this->options = $options;
37
38 if ($boardId)
39 {
40 $this->setBoardKey($boardId);
41
42 $configurationButton = new BoardComponentButton(
43 'bitrix:report.analytics.config.control',
44 '',
45 [
46 'BOARD_ID' => $this->getBoardKey(),
47 'BOARD_OPTIONS' => $this->getOptions(),
48 ]
49 );
50 $this->addButton($configurationButton);
51 //$this->addButton(new BoardButton(' '));
52 }
53 }
54
58 public function getTitle()
59 {
60 return $this->title;
61 }
62
66 public function setTitle($title)
67 {
68 $this->title = $title;
69 }
70
74 public function getBoardKey()
75 {
76 return $this->boardKey;
77 }
78
82 public function setBoardKey($boardKey)
83 {
84 $this->boardKey = $boardKey;
85 }
86
90 public function getMachineKey()
91 {
92 return $this->machineKey ?: $this->boardKey;
93 }
94
98 public function setMachineKey($machineKey)
99 {
100 $this->machineKey = $machineKey;
101 }
102
106 public function getFilter()
107 {
108 return $this->filter;
109 }
110
114 public function setFilter(Filter $filter)
115 {
116 $this->filter = $filter;
117 }
118
122 public function getBatchKey()
123 {
124 return $this->batchKey;
125 }
126
130 public function setBatchKey($batchKey)
131 {
132 $this->batchKey = $batchKey;
133 }
134
138 public function isNestedInBatch()
139 {
140 return $this->batchKey !== null;
141 }
142
146 public function addButton(BoardButton $button)
147 {
148 $this->buttons[] = $button;
149 }
150
151 public function getButtonsContent()
152 {
153 $result = [
154 'html' => '',
155 'assets' => [
156 'js' => [],
157 'css' => [],
158 'string' => [],
159 ]
160 ];
161 if ($this->isDisabled())
162 {
163 return $result;
164 }
165 $buttons = $this->getButtons();
166 foreach ($buttons as $button)
167 {
168 $result['html'] .= $button->process()->getHtml();
169 foreach ($button->getJsList() as $jsPath)
170 {
171 $result['assets']['js'][] = $jsPath;
172 }
173
174 foreach ($button->getCssList() as $cssPath)
175 {
176 $result['assets']['css'][] = $cssPath;
177 }
178
179 foreach ($button->getStringList() as $string)
180 {
181 $result['assets']['string'][] = $string;
182 }
183 }
184
185 return $result;
186 }
187
191 public function getButtons()
192 {
193 return $this->buttons;
194 }
195
199 public function isDisabled()
200 {
201 return $this->disabled;
202 }
203
207 public function setDisabled($disabled)
208 {
209 $this->disabled = $disabled;
210 }
211
212 public function addFeedbackButton()
213 {
214 $feedbackButton = new BoardComponentButton('bitrix:ui.feedback.form', '', [
215 'ID' => 'crm-analytics',
216 'VIEW_TARGET' => null,
217 'FORMS' => [
218 ['zones' => ['com.br'], 'id' => '58','lang' => 'br', 'sec' => 'k6be5r'],
219 ['zones' => ['es'], 'id' => '60','lang' => 'la', 'sec' => '1shpig'],
220 ['zones' => ['de'], 'id' => '62','lang' => 'de', 'sec' => 'dj2q8l'],
221 ['zones' => ['ua'], 'id' => '66','lang' => 'ua', 'sec' => 't5y7px'],
222 ['zones' => ['ru', 'kz', 'by'], 'id' => '68','lang' => 'ru', 'sec' => 'h6thh2'],
223 ['zones' => ['en'], 'id' => '64','lang' => 'en', 'sec' => '776ire'],
224 ],
225 'PRESETS' => [
226 'BOARD_KEY' => $this->getBoardKey(),
227 'sender_page' => $this->getTitle()
228 ]
229
230 ]);
231 $this->addButton($feedbackButton);
232 }
233
237 public function isStepperEnabled()
238 {
239 return $this->stepperEnabled;
240 }
241
242 public function getStepperIds()
243 {
244 return $this->stepperIds;
245 }
246
247 public function setStepperIds($stepperIds = [])
248 {
249 $this->stepperIds =$stepperIds;
250 }
254 public function setStepperEnabled($stepperEnabled)
255 {
256 $this->stepperEnabled = $stepperEnabled;
257 }
258
259 public function isLimited()
260 {
261 return $this->limited;
262 }
263
264 private function getLimitComponentOptions()
265 {
266 return $this->limitComponentParams;
267 }
268
269 public function getLimitComponentName()
270 {
271 $componentParams = $this->getLimitComponentOptions();
272 if (!isset($componentParams['NAME']))
273 {
274 throw new ArgumentException("Component name do not isset");
275 }
276 return $componentParams['NAME'];
277 }
278
280 {
281 $componentOptions = $this->getLimitComponentOptions();
282 if (!isset($componentOptions['TEMPLATE_NAME']))
283 {
284 return '';
285 }
286 return $componentOptions['TEMPLATE_NAME'];
287 }
288
289 public function getLimitComponentParams()
290 {
291 $componentOptions = $this->getLimitComponentOptions();
292 if (!isset($componentOptions['PARAMS']))
293 {
294 return [];
295 }
296 return $componentOptions['PARAMS'];
297 }
298
299 public function setLimit($limitComponentParams, $limit = false)
300 {
301 $this->limitComponentParams = $limitComponentParams;
302 $this->limited = $limit;
303 }
304
308 public function isExternal(): bool
309 {
310 return $this->isExternal;
311 }
312
316 public function setExternal(bool $isExternal): void
317 {
318 $this->isExternal = $isExternal;
319 }
320
324 public function getExternalUrl(): string
325 {
326 return $this->externalUrl;
327 }
328
332 public function setExternalUrl(string $externalUrl): void
333 {
334 $this->externalUrl = $externalUrl;
335 }
336
340 public function isSliderSupport(): bool
341 {
342 return $this->isSliderSupport;
343 }
344
348 public function setSliderSupport(bool $isSliderSupport): void
349 {
350 $this->isSliderSupport = $isSliderSupport;
351 }
352
353 public function getSliderLoader(): ?string
354 {
355 return $this->sliderLoader;
356 }
357
358 public function setSliderLoader(string $sliderLoader): void
359 {
360 $this->sliderLoader = $sliderLoader;
361 }
362
363 public function getDisplayComponentName()
364 {
365 if ($this->isDisabled())
366 {
367 return 'bitrix:report.analytics.empty';
368 }
369 elseif ($this->isLimited())
370 {
371 return $this->getLimitComponentName();
372 }
373 else
374 {
375 return 'bitrix:report.visualconstructor.board.base';
376 }
377 }
378
380 {
381 return ($this->isLimited() ? $this->getLimitComponentTemplateName() : "");
382 }
383
385 {
386 if ($this->isDisabled())
387 {
388 return [];
389 }
390 elseif ($this->isLimited())
391 {
392 return $this->getLimitComponentParams();
393 }
394 else
395 {
396 return [
397 'BOARD_ID' => $this->getBoardKey(),
398 'IS_DEFAULT_MODE_DEMO' => false,
399 'IS_BOARD_DEFAULT' => true,
400 'FILTER' => $this->getFilter(),
401 'BOARD_BUTTONS' => $this->getButtons(),
402 'IS_ENABLED_STEPPER' => $this->isStepperEnabled(),
403 'STEPPER_IDS' => $this->getStepperIds()
404 ];
405 }
406 }
407
411 public function resetToDefault()
412 {
413 // nothing here
414 }
415
419 public function getGroup()
420 {
421 return $this->group;
422 }
423
427 public function setGroup($group): void
428 {
429 $this->group = $group;
430 }
431
432 public function toggleOption(string $optionName)
433 {
434 $found = false;
435 foreach ($this->options as $optionFields)
436 {
437 if ($optionFields['NAME'] === $optionName)
438 {
439 $found = true;
440 break;
441 }
442 }
443
444 if (!$found)
445 {
446 throw new SystemException("Unknown option {$optionName} for the board {$this->boardKey}");
447 }
448
449 if (!is_callable($this->setOptionsCallback))
450 {
451 throw new SystemException("setOptionsCallback is not callable for the board {$this->boardKey}");
452 }
453
454 call_user_func($this->setOptionsCallback, $optionName, !$optionFields['VALUE']);
455 }
456
457 public function registerSetOptionsCallback(callable $cb)
458 {
459 $this->setOptionsCallback = $cb;
460 }
461
462 public function getOptions() : array
463 {
464 return $this->options;
465 }
466}
setLimit($limitComponentParams, $limit=false)
__construct(string $boardId='', array $options=[])