Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EntityCollection.php
1<?php
2
3namespace Bitrix\Im\V2\Entity;
4
5use Bitrix\Im\V2\Common\ContextCustomer;
11
13{
14 use ContextCustomer;
15
16 protected array $entitiesWithId = [];
17
18 public function getPopupData(array $excludedList = []): PopupData
19 {
20 $data = new PopupData([], $excludedList);
21
22 foreach ($this as $entity)
23 {
24 $data->mergeFromEntity($entity, $excludedList);
25 }
26
27 return $data;
28 }
29
33 public function getUnique(): self
34 {
35 return static::initByArray($this->entitiesWithId);
36 }
37
38 public function getIds(): array
39 {
40 $ids = [];
41
42 foreach ($this as $entity)
43 {
44 $ids[$entity->getId()] = $entity->getId();
45 }
46
47 return $ids;
48 }
49
50 public function getById(int $id): ?RestEntity
51 {
52 return $this->entitiesWithId[$id] ?? null;
53 }
54
55 public function toRestFormat(array $option = []): array
56 {
57 $collection = [];
58
59 foreach ($this as $entity)
60 {
61 $collection[] = $entity->toRestFormat($option);
62 }
63
64 return $collection;
65 }
66
71 public static function initByArray(array $entities): self
72 {
73 $collection = new static();
74
75 foreach ($entities as $entity)
76 {
77 $collection[] = $entity;
78 }
79
80 return $collection;
81 }
82
83 //region Collection interface
84
85 public function offsetSet($offset, $value): void
86 {
87 if ($offset === null)
88 {
89 if ($value->getId() !== null)
90 {
91 $this->entitiesWithId[$value->getId()] = $value;
92 }
93 }
94
95 parent::offsetSet($offset, $value);
96 }
97
98 //endregion
99}