Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
templatecollection.php
1
<?php
2
3
namespace
Bitrix\Location\Entity\Format
;
4
5
use
Bitrix\Location\Entity\Generic\Collection
;
6
use
Bitrix\Main\ArgumentTypeException
;
7
8
final
class
TemplateCollection
extends
Collection
9
{
11
protected
$items
= [];
12
19
public
function
addItem
($template): int
20
{
21
if
(!($template instanceof
Template
))
22
{
23
throw
new
ArgumentTypeException
(
'field must be the instance of Template'
);
24
}
25
26
$this->removeTemplateByType($template->getType());
27
return
parent::addItem($template);
28
}
29
33
private
function
removeTemplateByType(
string
$type): void
34
{
35
foreach
($this->items as $idx => $template)
36
{
37
if
($template->getType() === $type)
38
{
39
unset($this->items[$idx]);
40
break
;
41
}
42
}
43
}
44
49
public
function
getTemplate
(
string
$type): ?
Template
50
{
51
foreach
($this->items as $template)
52
{
53
if
($template->getType() === $type)
54
{
55
return
$template;
56
}
57
}
58
59
return
null
;
60
}
61
}
Bitrix\Location\Entity\Format\TemplateCollection
Definition
templatecollection.php:9
Bitrix\Location\Entity\Format\TemplateCollection\addItem
addItem($template)
Definition
templatecollection.php:19
Bitrix\Location\Entity\Format\TemplateCollection\$items
$items
Definition
templatecollection.php:11
Bitrix\Location\Entity\Format\TemplateCollection\getTemplate
getTemplate(string $type)
Definition
templatecollection.php:49
Bitrix\Location\Entity\Format\Template
Definition
template.php:12
Bitrix\Location\Entity\Generic\Collection
Definition
collection.php:12
Bitrix\Main\ArgumentTypeException
Definition
exception.php:114
Bitrix\Location\Entity\Format
modules
location
lib
entity
format
templatecollection.php
Создано системой
1.10.0