1 | <?php |
||
20 | class ImportCommandController extends AbstractCommandController |
||
21 | { |
||
22 | /** |
||
23 | * Import command. |
||
24 | * |
||
25 | * @param string $icsCalendarUri |
||
26 | * @param int $pid |
||
27 | */ |
||
28 | public function importCommand($icsCalendarUri = null, $pid = null) |
||
72 | |||
73 | /** |
||
74 | * Prepare the events. |
||
75 | * |
||
76 | * @param array $icalEvents |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | protected function prepareEvents(array $icalEvents) |
||
81 | { |
||
82 | $events = []; |
||
83 | foreach ($icalEvents as $icalEvent) { |
||
84 | $startDateTime = null; |
||
85 | $endDateTime = null; |
||
86 | try { |
||
87 | $startDateTime = new \DateTime($icalEvent['DTSTART']); |
||
88 | if ($icalEvent['DTEND']) { |
||
89 | $endDateTime = new \DateTime($icalEvent['DTEND']); |
||
90 | } else { |
||
91 | $endDateTime = clone $startDateTime; |
||
92 | $endDateTime->add(new \DateInterval($icalEvent['DURATION'])); |
||
93 | } |
||
94 | } catch (\Exception $ex) { |
||
95 | $this->enqueueMessage( |
||
96 | 'Could not convert the date in the right format of "' . $icalEvent['SUMMARY'] . '"', |
||
97 | 'Warning', |
||
98 | FlashMessage::WARNING |
||
99 | ); |
||
100 | continue; |
||
101 | } |
||
102 | |||
103 | $events[] = [ |
||
104 | 'uid' => $icalEvent['UID'], |
||
105 | 'start' => $startDateTime, |
||
106 | 'end' => $endDateTime, |
||
107 | 'title' => $icalEvent['SUMMARY'] ? $icalEvent['SUMMARY'] : '', |
||
108 | 'description' => $icalEvent['DESCRIPTION'] ? $icalEvent['DESCRIPTION'] : '', |
||
109 | 'location' => $icalEvent['LOCATION'] ? $icalEvent['LOCATION'] : '', |
||
110 | ]; |
||
111 | } |
||
112 | |||
113 | return $events; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Get the events from the given ical file. |
||
118 | * |
||
119 | * @param string $absoluteIcalFile |
||
120 | * |
||
121 | * @return array |
||
122 | */ |
||
123 | protected function getIcalEvents($absoluteIcalFile) |
||
134 | } |
||
135 |