Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
CompositionItemCollection.php
1
<?php
2
3
namespace
Bitrix\Socialnetwork\Space\Toolbar\Composition
;
4
5
use ArrayIterator;
6
use
Bitrix\Main\Type\Contract\Arrayable
;
7
use IteratorAggregate;
8
9
class
CompositionItemCollection
implements
IteratorAggregate,
Arrayable
10
{
12
private
array $items = [];
13
14
public
static
function
createFromModuleIds
(array $moduleIds): static
15
{
16
$collection =
new
static
();
17
array_map(
static
function
(
string
$moduleId) use ($collection):
void
{
18
$item = AbstractCompositionItem::createFromModuleId($moduleId);
19
!is_null($item) && $collection->addItem($item);
20
}, $moduleIds);
21
22
return
$collection;
23
}
24
25
public
function
getIterator
(): ArrayIterator
26
{
27
return
new
ArrayIterator($this->items);
28
}
29
30
public
function
addItem
(
AbstractCompositionItem
$item): static
31
{
32
if
(!$this->
has
($item))
33
{
34
$this->items[] = $item;
35
}
36
37
return
$this;
38
}
39
40
public
function
remove
(
string
$moduleId): static
41
{
42
foreach
($this->items as $key => $item)
43
{
44
if
($item->getModuleId() === $moduleId)
45
{
46
unset($this->items[$key]);
47
}
48
}
49
50
return
$this;
51
}
52
53
public
function
has
(
AbstractCompositionItem
$item): bool
54
{
55
return
in_array(
56
$item->
getModuleId
(),
57
array_map(fn (
AbstractCompositionItem
$compositionItem):
string
=> $compositionItem->
getModuleId
(),
58
$this->items),
59
true
60
);
61
}
62
63
public
function
fillBoundItems
(): static
64
{
65
foreach
($this->items as $item)
66
{
67
$item->hasBoundItem() && $this->
addItem
($item->getBoundItem());
68
}
69
70
return
$this;
71
}
72
73
public
function
hideItems
(): static
74
{
75
foreach
($this->items as $item)
76
{
77
$item->isHidden() && $this->
remove
($item->getModuleId());
78
}
79
80
return
$this;
81
}
82
83
public
function
toArray
(): array
84
{
85
$moduleIds = [];
86
foreach
($this->items as $item)
87
{
88
$moduleIds[] = $item->getModuleId();
89
}
90
91
return
$moduleIds;
92
}
93
}
Bitrix\Socialnetwork\Space\Toolbar\Composition\AbstractCompositionItem
Definition
AbstractCompositionItem.php:12
Bitrix\Socialnetwork\Space\Toolbar\Composition\AbstractCompositionItem\getModuleId
getModuleId()
Definition
AbstractCompositionItem.php:27
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection
Definition
CompositionItemCollection.php:10
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\hideItems
hideItems()
Definition
CompositionItemCollection.php:73
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\toArray
toArray()
Definition
CompositionItemCollection.php:83
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\getIterator
getIterator()
Definition
CompositionItemCollection.php:25
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\has
has(AbstractCompositionItem $item)
Definition
CompositionItemCollection.php:53
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\addItem
addItem(AbstractCompositionItem $item)
Definition
CompositionItemCollection.php:30
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\createFromModuleIds
static createFromModuleIds(array $moduleIds)
Definition
CompositionItemCollection.php:14
Bitrix\Socialnetwork\Space\Toolbar\Composition\CompositionItemCollection\fillBoundItems
fillBoundItems()
Definition
CompositionItemCollection.php:63
Bitrix\Main\Type\Contract\Arrayable
Definition
arrayable.php:6
Bitrix\Socialnetwork\Space\Toolbar\Composition
Definition
AbstractCompositionItem.php:3
modules
socialnetwork
lib
Space
Toolbar
Composition
CompositionItemCollection.php
Создано системой
1.10.0