Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
collection.php
1<?php
3
4use Traversable;
5
7 implements \IteratorAggregate
8{
9 protected $collection = [];
10 static $internalIndex = 0;
11
12 public function addItem(Item $item)
13 {
14 $index = $item->getInternalIndex() == '' ? 'n'.static::$internalIndex++ : $item->getInternalIndex();
15
16 $this->collection[$index] = $item;
17 }
18
19 public function count()
20 {
21 return count($this->collection);
22 }
23
24 public function toArray()
25 {
26 $result = [];
27 if(count($this->collection)>0)
28 {
32 foreach ($this->collection as $index=>$item)
33 {
34 $result[$index] = $item->getEntity()->getFieldsValues();
35 }
36 }
37 return $result;
38 }
39
40 public function getIndexes()
41 {
42 return count($this->collection)>0 ? array_keys($this->collection):[];
43 }
44
49 public function getItemByIndex($index)
50 {
51 $result = null;
52 if(count($this->collection)>0)
53 {
54 foreach ($this->collection as $k=>$item)
55 {
56 if($index == $k)
57 {
58 $result = $item;
59 break;
60 }
61 }
62 }
63 return $result;
64 }
65
73 public function getIterator()
74 {
75 return new \ArrayIterator($this->collection);
76 }
77}