Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EntityCollection.php
1
<?php
2
3
namespace
Bitrix\Im\V2\Entity
;
4
5
use Bitrix\Im\V2\Common\ContextCustomer;
6
use
Bitrix\Im\V2\Registry
;
7
use
Bitrix\Im\V2\Rest\PopupData
;
8
use
Bitrix\Im\V2\Rest\PopupDataAggregatable
;
9
use
Bitrix\Im\V2\Rest\RestConvertible
;
10
use
Bitrix\Im\V2\Rest\RestEntity
;
11
12
abstract
class
EntityCollection
extends
Registry
implements
RestConvertible
,
PopupDataAggregatable
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
}
Bitrix\Im\V2\Entity\EntityCollection
Definition
EntityCollection.php:13
Bitrix\Im\V2\Entity\EntityCollection\initByArray
static initByArray(array $entities)
Definition
EntityCollection.php:71
Bitrix\Im\V2\Entity\EntityCollection\$entitiesWithId
array $entitiesWithId
Definition
EntityCollection.php:16
Bitrix\Im\V2\Entity\EntityCollection\toRestFormat
toRestFormat(array $option=[])
Definition
EntityCollection.php:55
Bitrix\Im\V2\Entity\EntityCollection\getPopupData
getPopupData(array $excludedList=[])
Definition
EntityCollection.php:18
Bitrix\Im\V2\Entity\EntityCollection\getUnique
getUnique()
Definition
EntityCollection.php:33
Bitrix\Im\V2\Entity\EntityCollection\getById
getById(int $id)
Definition
EntityCollection.php:50
Bitrix\Im\V2\Entity\EntityCollection\offsetSet
offsetSet($offset, $value)
Definition
EntityCollection.php:85
Bitrix\Im\V2\Entity\EntityCollection\getIds
getIds()
Definition
EntityCollection.php:38
Bitrix\Im\V2\Registry
Definition
Registry.php:9
Bitrix\Im\V2\Rest\PopupData
Definition
PopupData.php:6
Bitrix\Im\V2\Rest\PopupDataAggregatable
Definition
PopupDataAggregatable.php:10
Bitrix\Im\V2\Rest\RestConvertible
Definition
RestConvertible.php:6
Bitrix\Im\V2\Rest\RestEntity
Definition
RestEntity.php:8
Bitrix\Im\V2\Entity
modules
im
lib
V2
Entity
EntityCollection.php
Создано системой
1.10.0