Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
fieldcollection.php
1
<?php
2
3
namespace
Bitrix\Location\Entity\Generic
;
4
5
use
Bitrix\Main\SystemException
;
6
12
abstract
class
FieldCollection
extends
Collection
13
{
15
protected
$items
= [];
16
21
public
function
isItemExist
(
int
$type): bool
22
{
23
foreach
($this->items as $item)
24
{
25
if
($item->getType() === $type)
26
{
27
return
true
;
28
}
29
}
30
31
return
false
;
32
}
33
38
public
function
getItemByType
(
int
$type): ?
IField
39
{
40
foreach
($this->items as $item)
41
{
42
if
($item->getType() === $type)
43
{
44
return
$item;
45
}
46
}
47
48
return
null
;
49
}
50
54
public
function
getSortedItems
(): array
55
{
56
$result =
$this->items
;
57
58
uasort(
59
$result,
60
function
($a, $b)
61
{
62
if
($a->getType() == $b->getType())
63
{
64
return 0;
65
}
66
return ($a->getType() < $b->getType()) ? -1 : 1;
67
}
68
);
69
70
return
$result;
71
}
72
78
public
function
addItem
($item): int
79
{
80
if
($this->
isItemExist
($item->getType()))
81
{
82
throw
new
SystemException
(
'Item with type "'
.$item->getType().
'" already exist in this collection'
);
83
}
84
85
return
parent::addItem($item);
86
}
87
}
Bitrix\Location\Entity\Generic\Collection
Definition
collection.php:12
Bitrix\Location\Entity\Generic\FieldCollection
Definition
fieldcollection.php:13
Bitrix\Location\Entity\Generic\FieldCollection\getSortedItems
getSortedItems()
Definition
fieldcollection.php:54
Bitrix\Location\Entity\Generic\FieldCollection\isItemExist
isItemExist(int $type)
Definition
fieldcollection.php:21
Bitrix\Location\Entity\Generic\FieldCollection\getItemByType
getItemByType(int $type)
Definition
fieldcollection.php:38
Bitrix\Location\Entity\Generic\FieldCollection\$items
$items
Definition
fieldcollection.php:15
Bitrix\Location\Entity\Generic\FieldCollection\addItem
addItem($item)
Definition
fieldcollection.php:78
Bitrix\Main\SystemException
Definition
exception.php:8
Bitrix\Location\Entity\Generic\IField
Definition
ifield.php:10
Bitrix\Location\Entity\Generic
Definition
collection.php:3
modules
location
lib
entity
generic
fieldcollection.php
Создано системой
1.10.0