1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basebuilder.php
См. документацию.
1<?php
3
6
7abstract class BaseBuilder
8{
9 public const TYPE_AUTODETECT = 'AUTO';
10
11 public const TYPE_ID = 'BASE';
12 protected const TYPE_WEIGHT = null;
13 protected const PATH_PREFIX = '';
14
15 public const PAGE_ELEMENT_LIST = 'elementList';
16 public const PAGE_ELEMENT_DETAIL = 'elementDetail';
17 public const PAGE_ELEMENT_COPY = 'elementCopy';
18 public const PAGE_ELEMENT_SAVE = 'elementSave';
19 public const PAGE_ELEMENT_SEARCH = 'elementSearch';
20 public const PAGE_ELEMENT_SEO = 'elementSeo';
21 public const PAGE_SECTION_LIST = 'sectionList';
22 public const PAGE_SECTION_DETAIL = 'sectionDetail';
23 public const PAGE_SECTION_COPY = 'sectionCopy';
24 public const PAGE_SECTION_SAVE = 'sectionSave';
25 public const PAGE_SECTION_SEARCH = 'sectionSearch';
26 public const PAGE_SECTION_SEO = 'sectionSeo';
27 public const PAGE_CATALOG_SEO = 'catalogSeo';
28
29 public const ENTITY_SECTION = 'section';
30 public const ENTITY_ELEMENT = 'element';
31
32 protected const SLIDER_PATH_VARIABLE = 'slider_path';
33
35 protected $request;
37 protected $id;
39 protected $weight;
41 protected $languageId;
42
44 protected $iblockId;
46 protected $iblock;
48 protected $iblockListMode;
51
53 protected $prefix;
54
55 protected $urlParams = [];
56
57 protected $compiledUrlParams = '';
58
59 protected $config = [];
60
61 protected $urlTemplates = [];
62
63 protected $templateVariables = [];
65 protected $sliderMode;
66
67 public function __construct()
68 {
69 $this->request = Main\Context::getCurrent()->getRequest();
70
71 $this->initSettings();
72 $this->initConfig();
73 $this->resetIblock();
74 $this->initIblockListMode();
75 $this->initUrlTemplates();
76 }
77
78 public function __destruct()
79 {
80 $this->request = null;
81 }
82
83 public function getId(): string
84 {
85 return $this->id;
86 }
87
88 public function getWeight(): ?int
89 {
90 return $this->weight;
91 }
92
93 public function setLanguageId(string $languageId): void
94 {
95 $this->languageId = $languageId;
96 $this->setTemplateVariable('#LANGUAGE_ID#', $this->languageId);
97 $this->setTemplateVariable('#LANGUAGE#', $this->getLanguageParam());
98 $this->setTemplateVariable('#BASE_PARAMS#', $this->getBaseParams());
99 }
100
101 public function getLanguageId(): string
102 {
103 return $this->languageId;
104 }
105
106 public function setIblockId(int $iblockId): void
107 {
108 if ($this->iblockId !== $iblockId)
109 {
110 $this->resetIblock();
111 if ($iblockId > 0)
112 {
113 $iblock = \CIBlock::GetArrayByID($iblockId);
114 if (!empty($iblock) && is_array($iblock))
115 {
116 $this->iblockId = $iblockId;
117 $this->iblock = $iblock;
118 }
119 unset($iblock);
120 }
121 $this->initIblockListMode();
122 $this->initUrlTemplates();
123 $this->setTemplateVariable('#IBLOCK_ID#', (string)$this->iblockId);
124 $this->setTemplateVariable('#BASE_PARAMS#', $this->getBaseParams());
125 }
126 }
127
128 public function setPrefix(string $prefix): void
129 {
130 $this->prefix = $prefix;
131 $this->setTemplateVariable('#PATH_PREFIX#', $this->prefix);
132 }
133
134 public function getPrefix(): string
135 {
136 return $this->prefix;
137 }
138
139 public function setUrlParams(array $list): void
140 {
141 if ($this->isSliderMode())
142 {
143 $list += static::getSliderOptions();
144 }
145 $this->urlParams = array_filter($list, [__CLASS__, 'clearNull']);
146 $this->compiledUrlParams = $this->compileUrlParams($this->urlParams);
147 }
148
149 public function getCompiledParams(array $params): string
150 {
151 return $this->compileUrlParams($params);
152 }
153
154 public function isIblockListMixed(): bool
155 {
156 $this->initIblockListMode();
158 }
159
160 public function setMixedIblockList(): void
161 {
163 }
164
165 public function setSeparateIblockList(): void
166 {
168 }
169
170 public function getListMode(): string
171 {
173 }
174
175 public function preloadUrlData(string $entityType, array $entityIds): void
176 {
177 switch ($entityType)
178 {
179 case self::ENTITY_SECTION:
180 $this->preloadSectionUrlData($entityIds);
181 break;
182 case self::ENTITY_ELEMENT:
183 $this->preloadElementUrlData($entityIds);
184 break;
185 }
186 }
187
188 public function clearPreloadedUrlData(): void {}
189
190 abstract public function use(): bool;
191
192 public function getSectionListUrl(?int $parentId, array $options = [], string $additional = ''): string
193 {
194 return $this->fillUrlTemplate(
195 $this->getUrlTemplate(self::PAGE_SECTION_LIST),
196 $this->getListVariables(self::PAGE_SECTION_LIST, $parentId, $options, $additional)
197 );
198 }
199
200 public function getSectionDetailUrl(?int $entityId, array $options = [], string $additional = ''): string
201 {
202 return $this->fillUrlTemplate(
203 $this->getUrlTemplate(self::PAGE_SECTION_DETAIL),
204 $this->getDetailVariables(self::PAGE_SECTION_DETAIL, $entityId, $options, $additional)
205 );
206 }
207
208 public function getSectionSaveUrl(?int $entityId, array $options = [], string $additional = ''): string
209 {
210 return $this->fillUrlTemplate(
211 $this->getUrlTemplate(self::PAGE_SECTION_SAVE),
212 $this->getDetailVariables(self::PAGE_SECTION_SAVE, $entityId, $options, $additional)
213 );
214 }
215
216 public function getSectionSearchUrl(array $options = [], string $additional = ''): string
217 {
218 return $this->fillUrlTemplate(
219 $this->getUrlTemplate(self::PAGE_SECTION_SEARCH),
220 $this->getExtendedVariables($options, $additional)
221 );
222 }
223
224 public function getElementListUrl(?int $parentId, array $options = [], string $additional = ''): string
225 {
226 return $this->fillUrlTemplate(
227 $this->getUrlTemplate(self::PAGE_ELEMENT_LIST),
228 $this->getListVariables(self::PAGE_ELEMENT_LIST, $parentId, $options, $additional)
229 );
230 }
231
232 public function getElementDetailUrl(?int $entityId, array $options = [], string $additional = ''): string
233 {
234 return $this->fillUrlTemplate(
235 $this->getUrlTemplate(self::PAGE_ELEMENT_DETAIL),
236 $this->getDetailVariables(self::PAGE_ELEMENT_DETAIL, $entityId, $options, $additional)
237 );
238 }
239
240 public function getElementCopyUrl(?int $entityId, array $options = [], string $additional = ''): string
241 {
242 return $this->fillUrlTemplate(
243 $this->getUrlTemplate(self::PAGE_ELEMENT_COPY),
244 $this->getDetailVariables(self::PAGE_ELEMENT_COPY, $entityId, $options, $additional)
245 );
246 }
247
248 public function getElementSaveUrl(?int $entityId, array $options = [], string $additional = ''): string
249 {
250 return $this->fillUrlTemplate(
251 $this->getUrlTemplate(self::PAGE_ELEMENT_SAVE),
252 $this->getDetailVariables(self::PAGE_ELEMENT_SAVE, $entityId, $options, $additional)
253 );
254 }
255
256 public function getElementSearchUrl(array $options = [], string $additional = ''): string
257 {
258 return $this->fillUrlTemplate(
259 $this->getUrlTemplate(self::PAGE_ELEMENT_SEARCH),
260 $this->getExtendedVariables($options, $additional)
261 );
262 }
263
264 public function getCatalogSeoUrl(array $options = [], string $additional = ''): string
265 {
266 return $this->fillUrlTemplate(
267 $this->getUrlTemplate(self::PAGE_CATALOG_SEO),
268 $this->getExtendedVariables($options, $additional)
269 );
270 }
271
272 public function getElementSeoUrl(int $productId, array $options = [], string $additional = ''): string
273 {
274 return $this->fillUrlTemplate(
275 $this->getUrlTemplate(self::PAGE_ELEMENT_SEO),
276 $this->getDetailSeoVariables($productId, $options, $additional)
277 );
278 }
279
280 public function getSectionSeoUrl(int $sectionId, array $options = [], string $additional = ''): string
281 {
282 return $this->fillUrlTemplate(
283 $this->getUrlTemplate(self::PAGE_SECTION_SEO),
284 $this->getSectionSeoVariables($sectionId, $options, $additional)
285 );
286 }
287
288 public function getContextMenuItems(string $pageType, array $items = [], array $options = []): ?array
289 {
290 return null;
291 }
292
293 public function getBaseParams(): string
294 {
295 if ($this->iblockId === null)
296 {
297 return '';
298 }
299
300 return 'IBLOCK_ID='.$this->iblockId
301 .'&type='.urlencode($this->iblock['IBLOCK_TYPE_ID'])
302 .'&lang='.urlencode($this->languageId);
303 }
304
305 public function getUrlParams(array $options = [], string $additional = ''): string
306 {
307 return $this->getBaseParams().$this->extendUrl($options, $additional);
308 }
309
310 public function getLanguageParam(): string
311 {
312 return 'lang='.urlencode($this->languageId);
313 }
314
315 public function getUrlBuilderIdParam(): string
316 {
317 return 'urlBuilderId='.urlencode($this->id);
318 }
319
320 public function setSliderMode(bool $mode): void
321 {
322 $this->sliderMode = $mode;
323 }
324
325 public function isSliderMode(): bool
326 {
327 return $this->sliderMode;
328 }
329
330 public function getDetailPageSlider(): string
331 {
332 $path = $this->getSliderPath();
333 if (!$this->checkSliderPath($path))
334 {
335 return '';
336 }
337 $path = \CUtil::JSEscape($path);
338
339 return '<script>'
340 . 'window.history.replaceState({}, \'\', \'' . $path . '\');' . "\n"
341 . 'BX.ready(function () {' . "\n"
342 . ' BX.SidePanel.Instance.open(' . "\n"
343 . ' \'' . $path . '\'' . "\n"
344 . ' );' . "\n"
345 . '});' . "\n"
346 . '</script>'
347 ;
348 }
349
350 public function showDetailPageSlider(): void
351 {
352 echo $this->getDetailPageSlider();
353 }
354
355 protected function checkCurrentPage(array $urlList): bool
356 {
357 $currentPage = $this->request->getRequestedPage();
358 foreach ($urlList as $url)
359 {
360 if (strncmp($currentPage, $url, strlen($url)) === 0)
361 {
362 return true;
363 }
364 }
365
366 return false;
367 }
368
369 protected function initSettings(): void
370 {
371 $this->id = static::TYPE_ID;
372 $this->weight = static::TYPE_WEIGHT;
373 $this->setLanguageId(LANGUAGE_ID);
374 $this->setPrefix(static::PATH_PREFIX);
375 $this->setSliderMode($this->request->get('IFRAME') === 'Y');
376 }
377
378 protected function initConfig(): void
379 {
380
381 }
382
383 protected static function clearNull($value): bool
384 {
385 return $value !== null;
386 }
387
388 protected function resetIblock(): void
389 {
390 $this->iblockId = null;
391 $this->iblock = null;
392 $this->iblockListMode = null;
393 }
394
395 protected function initIblockListMode(): void
396 {
397 if ($this->iblockListMode !== null)
398 {
399 return;
400 }
401 $listMode = '';
402 if ($this->iblockId !== null)
403 {
404 $listMode = (string)$this->iblock['LIST_MODE'];
405 }
406 if (
409 )
410 {
411 $listMode = (Main\Config\Option::get('iblock', 'combined_list_mode') === 'Y'
414 );
415 }
416 $this->iblockListMode = $listMode;
417 $this->iblockListMixed = ($this->iblockListMode === Iblock\IblockTable::LIST_MODE_COMBINED);
418 }
419
420 protected function setIblockListMode(string $listMode): void
421 {
422 if (
425 )
426 {
427 $this->iblockListMode = $listMode;
428 $this->iblockListMixed = ($this->iblockListMode === Iblock\IblockTable::LIST_MODE_COMBINED);
429 $this->initUrlTemplates();
430 }
431 }
432
433 protected function compileUrlParams(array $params): string
434 {
435 $result = '';
437 return $result;
438 }
439
440 protected function compileParamsLevel(string &$result, string $prefix, array $params): void
441 {
442 $params = array_filter($params, [__CLASS__, 'clearNull']);
443 if (empty($params))
444 {
445 return;
446 }
447 foreach ($params as $key => $value)
448 {
449 if ($prefix === '' && is_numeric($key))
450 {
451 continue;
452 }
453 $index = ($prefix !== '' ? $prefix.'['.$key.']' : $key);
454 if (is_array($value))
455 {
456 $this->compileParamsLevel($result, $index, $value);
457 }
458 else
459 {
460 $result .= '&'.urlencode($index).'='.urlencode((string)$value);
461 }
462 }
463 unset($index, $key, $value);
464 }
465
466 protected function getParentFilter(?int $parentId): string
467 {
468 $result = '';
469 if ($parentId !== null)
470 {
471 if ($parentId === -1)
472 {
473 $result = $this->compileUrlParams([
474 'find_section_section' => $parentId
475 ]);
476 }
477 elseif ($parentId >= 0)
478 {
479 $result = $this->compileUrlParams([
480 'find_section_section' => $parentId,
481 'SECTION_ID' => $parentId,
482 'apply_filter' => 'Y'
483 ]);
484 }
485 }
486
487 return $result;
488 }
489
490 protected function getEntityFilter(?int $entityId): string
491 {
492 $result = '';
493 if ($entityId !== null && $entityId >= 0)
494 {
495 $result = $this->compileUrlParams([
496 'ID' => $entityId,
497 ]);
498 }
499
500 return $result;
501 }
502
503 protected function extendUrl(array $options = [], string $additional = ''): string
504 {
506 $compiledOptions = $this->compileUrlParams($options);
507 if ($compiledOptions !== '')
508 {
509 $result .= $compiledOptions;
510 }
511 unset($compiledOptions);
512
513 if ($additional !== '')
514 {
515 $result .= $additional;
516 }
517 return $result;
518 }
519
520 abstract protected function initUrlTemplates(): void;
521
522 protected function getUrlTemplate(string $templateId): ?string
523 {
524 return ($this->urlTemplates[$templateId] ?? null);
525 }
526
527 protected function fillUrlTemplate(?string $template, array $replaces): string
528 {
529 if ($template === null)
530 {
531 return '';
532 }
533 if (empty($replaces))
534 {
535 return $template;
536 }
537 return str_replace(array_keys($replaces), array_values($replaces), $template);
538 }
539
540 protected function setTemplateVariable(string $name, string $value): void
541 {
542 $this->templateVariables[$name] = $value;
543 }
544
545 protected function getTemplateVariables(): array
546 {
548 }
549
550 protected function getExtendedVariables(array $options = [], string $additional = ''): array
551 {
552 $replaces = $this->getTemplateVariables();
553 $replaces['#ADDITIONAL_PARAMETERS#'] = $this->extendUrl($options, $additional);
554 return $replaces;
555 }
556
557 protected function getListVariables(string $page, ?int $parentId, array $options = [], string $additional = ''): array
558 {
559 $replaces = $this->getExtendedVariables($options, $additional);
560 $replaces['#PARENT_ID#'] = (string)$parentId;
561 $replaces['#PARENT_FILTER#'] = $this->getParentFilter($parentId);
562 return $replaces;
563 }
564
565 protected function getDetailVariables(string $page, ?int $entityId, array $options = [], string $additional = ''): array
566 {
567 $replaces = $this->getExtendedVariables($options, $additional);
568 $replaces['#ENTITY_ID#'] = (string)$entityId;
569 $replaces['#ENTITY_FILTER#'] = $this->getEntityFilter($entityId);
570 return $replaces;
571 }
572
573 protected function getDetailSeoVariables(?int $entityId, array $options = [], string $additional = ''): array
574 {
575 $replaces = $this->getExtendedVariables($options, $additional);
576 $replaces['#PRODUCT_ID#'] = (string)$entityId;
577
578 return $replaces;
579 }
580
581 protected function getSectionSeoVariables(?int $sectionId, array $options = [], string $additional = ''): array
582 {
583 $replaces = $this->getExtendedVariables($options, $additional);
584 $replaces['#SECTION_ID#'] = (string)$sectionId;
585
586 return $replaces;
587 }
588
589 protected function getCopyAction(): string
590 {
591 return '&action=copy';
592 }
593
594 protected function preloadSectionUrlData(array $sectionIds): void {}
595
596 protected function preloadElementUrlData(array $elementIds): void {}
597
598 protected static function getSliderOptions(): array
599 {
600 return [
601 'IFRAME' => 'Y',
602 'IFRAME_TYPE' => 'SIDE_SLIDER',
603 ];
604 }
605
606 protected function getSliderPath(): ?string
607 {
608 return $this->request->get(self::SLIDER_PATH_VARIABLE);
609 }
610
611 public function getSliderPathOption(string $path): ?array
612 {
613 if ($path === '')
614 {
615 return null;
616 }
617
618 return [
619 self::SLIDER_PATH_VARIABLE => $path,
620 ];
621 }
622
623 public function getSliderPathString(string $path): string
624 {
625 if ($path === '')
626 {
627 return '';
628 }
629
630 return self::SLIDER_PATH_VARIABLE . '=' . $path;
631 }
632
633 protected function checkSliderPath(?string $path): bool
634 {
635 if ($path === null)
636 {
637 $path = $this->getSliderPath();
638 }
639 if ($path === null || $path === '')
640 {
641 return false;
642 }
643
644 $prepared = [];
645 foreach ($this->getSliderPathTemplates() as $mask)
646 {
647 if (preg_match($mask, $path, $prepared))
648 {
649 return true;
650 }
651 }
652
653 return false;
654 }
655
656 protected function getSliderPathTemplates(): array
657 {
658 return [];
659 }
660
667 public function openSettingsPage(): void
668 {
669 }
670
676 public function subscribeOnAfterSettingsSave(): void
677 {
678 }
679}
$path
Определения access_edit.php:21
const LIST_MODE_COMBINED
Определения iblocktable.php:95
const LIST_MODE_SEPARATE
Определения iblocktable.php:94
setIblockId(int $iblockId)
Определения basebuilder.php:106
getUrlParams(array $options=[], string $additional='')
Определения basebuilder.php:305
getSectionListUrl(?int $parentId, array $options=[], string $additional='')
Определения basebuilder.php:192
fillUrlTemplate(?string $template, array $replaces)
Определения basebuilder.php:527
preloadElementUrlData(array $elementIds)
Определения basebuilder.php:596
checkCurrentPage(array $urlList)
Определения basebuilder.php:355
setUrlParams(array $list)
Определения basebuilder.php:139
setSliderMode(bool $mode)
Определения basebuilder.php:320
getSectionSeoVariables(?int $sectionId, array $options=[], string $additional='')
Определения basebuilder.php:581
getSectionSeoUrl(int $sectionId, array $options=[], string $additional='')
Определения basebuilder.php:280
compileParamsLevel(string &$result, string $prefix, array $params)
Определения basebuilder.php:440
static clearNull($value)
Определения basebuilder.php:383
getContextMenuItems(string $pageType, array $items=[], array $options=[])
Определения basebuilder.php:288
getElementSearchUrl(array $options=[], string $additional='')
Определения basebuilder.php:256
getDetailVariables(string $page, ?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:565
getCatalogSeoUrl(array $options=[], string $additional='')
Определения basebuilder.php:264
preloadSectionUrlData(array $sectionIds)
Определения basebuilder.php:594
setIblockListMode(string $listMode)
Определения basebuilder.php:420
getElementListUrl(?int $parentId, array $options=[], string $additional='')
Определения basebuilder.php:224
setLanguageId(string $languageId)
Определения basebuilder.php:93
getDetailSeoVariables(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:573
getSliderPathOption(string $path)
Определения basebuilder.php:611
getElementDetailUrl(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:232
getSectionDetailUrl(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:200
checkSliderPath(?string $path)
Определения basebuilder.php:633
getSliderPathString(string $path)
Определения basebuilder.php:623
setPrefix(string $prefix)
Определения basebuilder.php:128
getElementSaveUrl(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:248
getElementCopyUrl(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:240
preloadUrlData(string $entityType, array $entityIds)
Определения basebuilder.php:175
getSectionSearchUrl(array $options=[], string $additional='')
Определения basebuilder.php:216
getCompiledParams(array $params)
Определения basebuilder.php:149
getEntityFilter(?int $entityId)
Определения basebuilder.php:490
getListVariables(string $page, ?int $parentId, array $options=[], string $additional='')
Определения basebuilder.php:557
getParentFilter(?int $parentId)
Определения basebuilder.php:466
compileUrlParams(array $params)
Определения basebuilder.php:433
getUrlTemplate(string $templateId)
Определения basebuilder.php:522
getElementSeoUrl(int $productId, array $options=[], string $additional='')
Определения basebuilder.php:272
getExtendedVariables(array $options=[], string $additional='')
Определения basebuilder.php:550
setTemplateVariable(string $name, string $value)
Определения basebuilder.php:540
getSectionSaveUrl(?int $entityId, array $options=[], string $additional='')
Определения basebuilder.php:208
extendUrl(array $options=[], string $additional='')
Определения basebuilder.php:503
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
$options
Определения commerceml2.php:49
$templateId
Определения component_props2.php:51
$template
Определения file_edit.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$name
Определения menu_edit.php:35
$entityId
Определения payment.php:4
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$page
Определения order_form.php:33
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224
$currentPage
Определения options_user_settings.php:37
$url
Определения iframe.php:7