Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BaseLinkCollection.php
1<?php
2
4
10
15abstract class BaseLinkCollection extends Collection implements LinkRestConvertible
16{
20 abstract public static function getCollectionElementClass(): string;
21
22 public function getPopupData(array $excludedList = []): PopupData
23 {
24 $data = new PopupData([new Entity\User\UserPopupItem()], $excludedList);
25
26 foreach ($this as $link)
27 {
28 $data->mergeFromEntity($link, $excludedList);
29 }
30
31 return $data;
32 }
33
34 public static function getRestEntityName(): string
35 {
36 return 'list';
37 }
38
39 public function toRestFormatIdOnly(): array
40 {
41 $ids = [];
42
43 foreach ($this as $item)
44 {
45 $ids[] = $item->toRestFormatIdOnly();
46 }
47
48 return $ids;
49 }
50
51 public function setMessageInfo(Message $message): Link
52 {
53 foreach ($this as $link)
54 {
55 $link->setMessageInfo($message);
56 }
57
58 return $this;
59 }
60
61 public function getEntityIds(): array
62 {
63 $ids = [];
64
65 foreach ($this as $link)
66 {
67 $ids[] = $link->getEntityId();
68 }
69
70 return $ids;
71 }
72
79 public static function linkEntityToMessage(Entity\EntityCollection $entities, Message $message): self
80 {
81 $linkCollection = new static();
82
83 foreach ($entities as $entity)
84 {
85 $linkItemClass = static::getCollectionElementClass();
87 $linkItem = new $linkItemClass;
88 $linkItem->setEntity($entity)->setMessageInfo($message);
89 $linkCollection->add($linkItem);
90 }
91
92 return $linkCollection;
93 }
94
95 public function toRestFormat(array $option = []): array
96 {
97 $linkCollection = [];
98
99 foreach ($this as $link)
100 {
101 $linkCollection[] = $link->toRestFormat($option);
102 }
103
104 return $linkCollection;
105 }
106}