1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
PopupData.php
См. документацию.
1<?php
2
4
6{
7 protected const DEFAULT_MAX_LEVEL = 1;
8
12 protected array $popupItems = [];
13 protected array $excludedList = [];
14 protected int $maxLevel = self::DEFAULT_MAX_LEVEL;
15
20 public function __construct(array $popupDataItems, array $excludedList = [])
21 {
22 foreach ($popupDataItems as $popupDataItem)
23 {
24 $this->add($popupDataItem);
25 }
26 $this->excludedList = $excludedList;
27 $this->filterItems($excludedList);
28 }
29
30 public function merge(self $popupData): self
31 {
32 foreach ($popupData->popupItems as $popupItem)
33 {
34 $this->mergeItem($popupItem);
35 }
36
37 return $this;
38 }
39
40 public function add(PopupDataItem $item): self
41 {
42 $this->mergeItem($item);
43
44 return $this;
45 }
46
48 {
49 if ($entity instanceof PopupDataAggregatable)
50 {
51 return $this->merge($entity->getPopupData($excludedList));
52 }
53
54 return $this;
55 }
56
57 public function toRestFormat(array $options = []): array
58 {
59 $result = [];
60 $this->maxLevel = $options['POPUP_MAX_LEVEL'] ?? static::DEFAULT_MAX_LEVEL;
61 $this->fillNextLevel();
62
63 foreach ($this->popupItems as $item)
64 {
65 $result[$item::getRestEntityName()] = $item->toRestFormat($options);
66 }
67
68 return $result;
69 }
70
71 protected function fillNextLevel(int $level = 1): void
72 {
73 if ($level > $this->maxLevel)
74 {
75 return;
76 }
77
78 $innerPopupData = new static([], $this->excludedList);
79 $innerPopupData->maxLevel = $this->maxLevel;
80
81 foreach ($this->popupItems as $item)
82 {
83 if ($item instanceof PopupDataAggregatable)
84 {
85 $innerPopupData->merge($item->getPopupData($this->excludedList));
86 }
87 }
88
89 $innerPopupData->fillNextLevel($level + 1);
90 $this->merge($innerPopupData);
91 }
92
93 private function mergeItem(PopupDataItem $popupItem): void
94 {
95 if (!isset($this->popupItems[$popupItem::getRestEntityName()]))
96 {
97 $this->popupItems[$popupItem::getRestEntityName()] = $popupItem;
98 $this->filterItems($this->excludedList);
99 }
100 else
101 {
102 $this->popupItems[$popupItem::getRestEntityName()]->merge($popupItem);
103 }
104 }
105
110 private function filterItems(array $excludedList): void
111 {
112 foreach ($excludedList as $excludedItem)
113 {
114 unset($this->popupItems[$excludedItem::getRestEntityName()]);
115 }
116 }
117}
array $popupItems
Определения PopupData.php:12
const DEFAULT_MAX_LEVEL
Определения PopupData.php:7
__construct(array $popupDataItems, array $excludedList=[])
Определения PopupData.php:20
mergeFromEntity(RestConvertible $entity, array $excludedList=[])
Определения PopupData.php:47
int $maxLevel
Определения PopupData.php:14
fillNextLevel(int $level=1)
Определения PopupData.php:71
toRestFormat(array $options=[])
Определения PopupData.php:57
array $excludedList
Определения PopupData.php:13
add(PopupDataItem $item)
Определения PopupData.php:40
merge(self $popupData)
Определения PopupData.php:30
$options
Определения commerceml2.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
$entity
Определения PopupData.php:3