Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
factorycomponents.php
1<?php
2
3
5
6
8{
12 private $componentName;
16 private $component;
17
22 public static function createInstance(string $componentName): FactoryComponents
23 {
24 return new self($componentName);
25 }
26
31 public function __construct(string $componentName)
32 {
33 $this->componentName = $componentName;
34 }
35
43 public function createComponent($properties, $subComponents): FactoryComponents
44 {
45 switch ($this->componentName)
46 {
47 case 'standard':
48 $this->component = $this->getStandardComponent($properties);
49 break;
50 case 'daylight':
51 $this->component = $this->getDaylightComponent($properties);
52 break;
53 case 'vcalendar':
54 $this->component = $this->getCalendarComponent($properties, $subComponents);
55 break;
56 case 'vevent':
57 $this->component = $this->getEventComponent($properties, $subComponents);
58 break;
59 case 'vtimezone':
60 $this->component = $this->getTimezoneComponent($properties, $subComponents);
61 break;
62 case 'valarm':
63 break; //TODO: Add VALARM component support
64 default:
65 $this->addMessageLog();
66 }
67
68 return $this;
69 }
70
74 public function getComponent(): ?ParserComponent
75 {
76 return $this->component;
77 }
78
83 private function getStandardComponent(?array $properties): StandardObservance
84 {
86 ->setTzOffsetTo($properties['tzoffsetto'] ?? null)
87 ->setTzOffsetFrom($properties['tzoffsetfrom'] ?? null)
88 ->setDtStart($properties['dtstart'] ?? null);
89 }
90
95 private function getDaylightComponent(?array $properties): DaylightObservance
96 {
98 ->setTzOffsetTo($properties['tzoffsetto'] ?? null)
99 ->setTzOffsetFrom($properties['tzoffsetfrom'] ?? null)
100 ->setDtStart($properties['dtstart'] ?? null);
101 }
102
108 private function getCalendarComponent($properties, $subComponents): Calendar
109 {
111 $name = isset($properties['name']) ? $properties['name']->getValue() : 'Outer Calendar';
112 return (Calendar::createInstance($name))
113 ->setMethod($properties['method'] ?? null)
114 ->setProdId($properties['prodid'] ?? null)
115 ->setCalScale($properties['calscale'] ?? null)
116 ->setVersion($properties['version'] ?? null)
117 ->setSubComponents($subComponents);
118 }
119
127 private function getEventComponent($properties, $subComponents): Event
128 {
129 if (empty($properties['uid']))
130 {
131 throw new IcalParserException("event identifier is not passed");
132 }
133 return (Event::createInstance($properties['uid']->getValue()))
134 ->setStart($properties['dtstart'] ?? null)
135 ->setEnd($properties['dtend'] ?? null)
136 ->setDescription($properties['description'] ?? null)
137 ->setSummary($properties['summary'] ?? null)
138 ->setSequence($properties['sequence'] ?? null)
139 ->setCreated($properties['created'] ?? null)
140 ->setDTStamp($properties['dtstamp'] ?? null)
141 ->setLocation($properties['location'] ?? null)
142 ->setUrl($properties['url'] ?? null)
143 ->setRRule($properties['rrule'] ?? null)
144 ->setTransparent($properties['transp'] ?? null)
145 ->setCategories($properties['categories'] ?? null)
146 ->setOrganizer($properties['organizer'] ?? null)
147 ->setAttendees($properties['attendee'] ?? null)
148 ->setModified($properties['last-modified'] ?? null)
149 ->setStatus($properties['status'] ?? null)
150 ->setRecurrenceId($properties['recurrence-id'] ?? null)
151 ->setAttachment($properties['attach'] ?? null);
152 }
153
159 private function getTimezoneComponent($properties, $subComponents): Timezone
160 {
162 ->setTimezoneId($properties['tzid'] ?? null)
163 ->setTimezoneUrl($properties['tzurl'] ?? null)
164 ->setSubComponents($subComponents);
165 }
166
170 private function addMessageLog(): void
171 {
172 AddMessage2Log("Component not found: {$this->componentName}", "calendar", 2);
173 }
174}
static createInstance(string $name='')
Definition calendar.php:43
static createInstance(string $uid)
Definition event.php:36
setTzOffsetTo(?ParserPropertyType $tzOffsetTo)