Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
PopupData.php
1<?php
2
4
6{
10 protected array $popupItems = [];
11 protected array $excludedList = [];
12
17 public function __construct(array $popupDataItems, array $excludedList = [])
18 {
19 foreach ($popupDataItems as $popupDataItem)
20 {
21 $this->add($popupDataItem);
22 }
23 $this->excludedList = $excludedList;
24 $this->filterItems($excludedList);
25 }
26
27 public function merge(self $popupData): self
28 {
29 foreach ($popupData->popupItems as $popupItem)
30 {
31 $this->mergeItem($popupItem);
32 }
33
34 return $this;
35 }
36
37 public function add(PopupDataItem $item): self
38 {
39 $this->mergeItem($item);
40
41 return $this;
42 }
43
44 public function mergeFromEntity(RestConvertible $entity, array $excludedList = []): self
45 {
46 if ($entity instanceof PopupDataAggregatable)
47 {
48 return $this->merge($entity->getPopupData($excludedList));
49 }
50
51 return $this;
52 }
53
54 public function toRestFormat(array $options = []): array
55 {
56 $result = [];
57
58 foreach ($this->popupItems as $item)
59 {
60 if ($item instanceof PopupDataAggregatable)
61 {
62 $this->merge($item->getPopupData($this->excludedList));
63 }
64 }
65
66 foreach ($this->popupItems as $item)
67 {
68 $result[$item::getRestEntityName()] = $item->toRestFormat($options);
69 }
70
71 return $result;
72 }
73
74 private function mergeItem(PopupDataItem $popupItem): void
75 {
76 if (!isset($this->popupItems[$popupItem::getRestEntityName()]))
77 {
78 $this->popupItems[$popupItem::getRestEntityName()] = $popupItem;
79 }
80 else
81 {
82 $this->popupItems[$popupItem::getRestEntityName()]->merge($popupItem);
83 }
84 }
85
90 private function filterItems(array $excludedList): void
91 {
92 foreach ($excludedList as $excludedItem)
93 {
94 unset($this->popupItems[$excludedItem::getRestEntityName()]);
95 }
96 }
97}
__construct(array $popupDataItems, array $excludedList=[])
Definition PopupData.php:17
mergeFromEntity(RestConvertible $entity, array $excludedList=[])
Definition PopupData.php:44
toRestFormat(array $options=[])
Definition PopupData.php:54
add(PopupDataItem $item)
Definition PopupData.php:37
merge(self $popupData)
Definition PopupData.php:27