Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
itemcollection.php
1
<?
2
3
namespace
Bitrix\UI\EntitySelector
;
4
5
class
ItemCollection
implements
\IteratorAggregate, \JsonSerializable
6
{
7
private
$items = [];
8
private
$itemsByEntity = [];
9
10
public
function
__construct
()
11
{
12
}
13
14
public
function
add
(
Item
$item): bool
15
{
16
if
($this->
has
($item))
17
{
18
return
false
;
19
}
20
21
if
(!isset($this->itemsByEntity[$item->
getEntityId
()]))
22
{
23
$this->itemsByEntity[$item->
getEntityId
()] = [];
24
}
25
26
$this->itemsByEntity[$item->
getEntityId
()][$item->
getId
()] = $item;
27
$this->items[] = $item;
28
29
return
true
;
30
}
31
32
public
function
get
(
string
$entityId, $itemId): ?
Item
33
{
34
return
$this->itemsByEntity[$entityId][$itemId] ??
null
;
35
}
36
37
public
function
has
(
Item
$item): bool
38
{
39
return
isset($this->itemsByEntity[$item->
getEntityId
()][$item->
getId
()]);
40
}
41
42
public
function
getAll
(): array
43
{
44
return
$this->items;
45
}
46
47
public
function
count
(): int
48
{
49
return
count
($this->items);
50
}
51
52
public
function
getEntityItems
(
string
$entityId): array
53
{
54
return
$this->itemsByEntity[$entityId] ?? [];
55
}
56
57
public
function
toJsObject
(): string
58
{
59
$items = $this->
toArray
();
60
61
return \CUtil::phpToJSObject($items,
false
,
false
,
true
);
62
}
63
64
public
function
toArray
(): array
65
{
66
return
array_map(
function
(
Item
$item) {
67
return
$item->
toArray
();
68
}, $this->
getAll
());
69
}
70
71
public
function
jsonSerialize
()
72
{
73
return
$this->items;
74
}
75
76
public
function
getIterator
(): \ArrayIterator
77
{
78
return
new \ArrayIterator($this->items);
79
}
80
}
Bitrix\UI\EntitySelector\ItemCollection
Definition
itemcollection.php:6
Bitrix\UI\EntitySelector\ItemCollection\__construct
__construct()
Definition
itemcollection.php:10
Bitrix\UI\EntitySelector\ItemCollection\has
has(Item $item)
Definition
itemcollection.php:37
Bitrix\UI\EntitySelector\ItemCollection\toJsObject
toJsObject()
Definition
itemcollection.php:57
Bitrix\UI\EntitySelector\ItemCollection\toArray
toArray()
Definition
itemcollection.php:64
Bitrix\UI\EntitySelector\ItemCollection\getIterator
getIterator()
Definition
itemcollection.php:76
Bitrix\UI\EntitySelector\ItemCollection\add
add(Item $item)
Definition
itemcollection.php:14
Bitrix\UI\EntitySelector\ItemCollection\getEntityItems
getEntityItems(string $entityId)
Definition
itemcollection.php:52
Bitrix\UI\EntitySelector\ItemCollection\getAll
getAll()
Definition
itemcollection.php:42
Bitrix\UI\EntitySelector\ItemCollection\count
count()
Definition
itemcollection.php:47
Bitrix\UI\EntitySelector\ItemCollection\jsonSerialize
jsonSerialize()
Definition
itemcollection.php:71
Bitrix\UI\EntitySelector\Item
Definition
item.php:8
Bitrix\UI\EntitySelector\Item\getEntityId
getEntityId()
Definition
item.php:185
Bitrix\UI\EntitySelector\Item\getId
getId()
Definition
item.php:180
Bitrix\UI\EntitySelector\Item\toArray
toArray()
Definition
item.php:663
Bitrix\UI\EntitySelector
Definition
basefilter.php:2
modules
ui
lib
entityselector
itemcollection.php
Создано системой
1.10.0