Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
attendeecollection.php
1<?php
2
4
5use ArrayIterator;
8
9
11{
13 private array $attendeesIdCollection = [];
15 private array $attendeesCodesCollection = [];
16
20 public function getFields(): array
21 {
22 return array_merge(parent::getFields(), [
23 'attendeesIdCollection' => $this->attendeesIdCollection,
24 'attendeesCodesCollection' => $this->attendeesCodesCollection
25 ]);
26 }
27
34 public function getIterator(): ArrayIterator
35 {
36 if (!$this->collection && $this->attendeesIdCollection)
37 {
38 $this->loadAttendees();
39 }
40
41 return parent::getIterator();
42 }
43
47 public function count(): int
48 {
49 if (!$this->collection && $this->attendeesIdCollection)
50 {
51 return count($this->attendeesIdCollection);
52 }
53
54 if (!$this->collection && $this->attendeesCodesCollection)
55 {
56 return count($this->attendeesCodesCollection);
57 }
58
59 return parent::count();
60 }
61
66 public function setAttendeesId(array $attendeesId): AttendeeCollection
67 {
68 $this->attendeesIdCollection = $attendeesId;
69
70 return $this;
71 }
72
73 public function setAttendeesCodes(array $attendeesCodes): AttendeeCollection
74 {
75 $this->attendeesCodesCollection = $attendeesCodes;
76
77 return $this;
78 }
79
80 public function getAttendeesCodes(): array
81 {
82 return $this->attendeesCodesCollection;
83 }
84
91 private function loadAttendees(): void
92 {
93 foreach ($this->attendeesIdCollection as $attendee)
94 {
95 if (!$attendee)
96 {
97 continue;
98 }
99
100 // if (mb_strpos($attendee, 'U') === 0)
101 // {
102 // $attendee = mb_substr($attendee, 1);
103 // }
104 if ((int)$attendee)
105 {
106 $this->add(
107 Helper::getUserRole((int)$attendee)
108 );
109 }
110 }
111 }
112
120 public function toString($separator = ', '): string
121 {
122 if (!$this->collection)
123 {
124 $this->loadAttendees();
125 }
126
127 return parent::toString($separator);
128 }
129
133 public function getAttendeesIdCollection(): array
134 {
135 return $this->attendeesIdCollection;
136 }
137}