Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attendeescollection.php
1<?php
2
3
5
6
7use Bitrix\Calendar\SerializeObject;
8use ArrayIterator;
9use IteratorAggregate;
10use Serializable;
11
16class AttendeesCollection implements IteratorAggregate, Serializable
17{
18 use SerializeObject;
22 private array $collection;
23
28 public static function createInstance(array $collection = []): AttendeesCollection
29 {
30 return new self($collection);
31 }
32
33
38 public function __construct(array $collection = [])
39 {
40 if (!$this->checkCollection($collection))
41 {
42 throw new \InvalidArgumentException('The collection contains elements of the wrong class. You need to pass a collection of objects Bitrix\\Calendar\\ICal\\Builder\\Attendee');
43 }
44
45 $this->collection = $collection;
46 }
47
51 public function __toString(): string
52 {
53 if (empty($this->collection))
54 {
55 return '';
56 }
57
58 $result = [];
59 foreach ($this->collection as $attendee)
60 {
61 if (!empty($attendee->getFullName()))
62 {
63 $result[] = $attendee->getFullName();
64 }
65 }
66
67 return implode(', ', $result);
68 }
69
74 public function add(Attendee $attendee): AttendeesCollection
75 {
76 $this->collection[] = $attendee;
77
78 return $this;
79 }
80
84 public function getIterator(): ArrayIterator
85 {
86 return new ArrayIterator($this->collection);
87 }
88
92 public function getCount(): int
93 {
94 return count($this->collection);
95 }
96
101 private function checkCollection(?array $collection): bool
102 {
103 if (is_null($collection))
104 {
105 return true;
106 }
107
108 $attendee = array_filter($collection, static function ($attendee) {
109 return !($attendee instanceof Attendee);
110 });
111
112 return empty($attendee);
113 }
114}