1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
RestAdapter.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Rest;
4
5use Bitrix\Im\V2\TariffLimit\DateFilterable;
6use Bitrix\Im\V2\TariffLimit\Limit;
7use Bitrix\Im\V2\TariffLimit\TariffLimitPopupItem;
8
10{
14 protected array $entities = [];
16
18 {
19 $this->entities = $entities ?? [];
20 }
21
22 public function toRestFormat(array $option = []): array
23 {
24 $this->processTariffLimit();
25 $excludedList = $option['POPUP_DATA_EXCLUDE'] ?? [];
26 $popupData = new PopupData([], $excludedList);
27
28 foreach ($this->entities as $entity)
29 {
30 if ($entity instanceof PopupDataAggregatable)
31 {
32 $popupData->merge($entity->getPopupData($excludedList));
33 }
34 }
35
36 if (isset($this->additionalPopupData))
37 {
38 $popupData->merge($this->additionalPopupData);
39 }
40
41 $rest = $popupData->toRestFormat($option);
42
43 if (empty($rest))
44 {
45 if (count($this->entities) === 1)
46 {
47 return $this->entities[0]->toRestFormat($option);
48 }
49 }
50
51 foreach ($this->entities as $entity)
52 {
53 $rest[$entity::getRestEntityName()] = $entity->toRestFormat($option);
54 }
55
56 return $rest;
57 }
58
59 public function setAdditionalPopupData(PopupData $popupData): self
60 {
61 $this->additionalPopupData = $popupData;
62
63 return $this;
64 }
65
66 public function addAdditionalPopupData(PopupData $popupData): self
67 {
68 if (!isset($this->additionalPopupData))
69 {
70 $this->additionalPopupData = $popupData;
71 }
72 else
73 {
74 $this->additionalPopupData->merge($popupData);
75 }
76
77 return $this;
78 }
79
80 public function addEntities(RestConvertible ...$entities): self
81 {
82 foreach ($entities as $entity)
83 {
84 $this->entities[] = $entity;
85 }
86
87 return $this;
88 }
89
90 protected function processTariffLimit(): void
91 {
92 $limit = Limit::getInstance();
93 $hasTariffLimit = false;
94 $isLimitExceeded = false;
95
96 foreach ($this->entities as $key => $entity)
97 {
98 if (!$entity instanceof DateFilterable)
99 {
100 continue;
101 }
102
103 $hasTariffLimit = true;
104
105 if (!$limit->hasRestrictions())
106 {
107 break;
108 }
109
110 if (!$limit->shouldFilterByDate($entity))
111 {
112 continue;
113 }
114
115 $result = $entity->filterByDate($limit->getLimitDate());
116
117 if ($result->wasFiltered())
118 {
119 $isLimitExceeded = true;
120 $this->entities[$key] = $result->getResult();
121 }
122 }
123
124 if ($hasTariffLimit)
125 {
126 $popupData = new PopupData([new TariffLimitPopupItem($isLimitExceeded)]);
127 $this->addAdditionalPopupData($popupData);
128 }
129 }
130
131 public static function getRestEntityName(): string
132 {
133 return 'result';
134 }
135}
static getRestEntityName()
Определения RestAdapter.php:131
array $entities
Определения RestAdapter.php:14
toRestFormat(array $option=[])
Определения RestAdapter.php:22
PopupData $additionalPopupData
Определения RestAdapter.php:15
addEntities(RestConvertible ... $entities)
Определения RestAdapter.php:80
__construct(RestConvertible ... $entities)
Определения RestAdapter.php:17
setAdditionalPopupData(PopupData $popupData)
Определения RestAdapter.php:59
addAdditionalPopupData(PopupData $popupData)
Определения RestAdapter.php:66
</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
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$option
Определения options.php:1711