Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fieldcollection.php
1<?php
2
4
6
12abstract 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}