diff --git a/components/Download.php b/components/Download.php new file mode 100644 index 0000000..a7e2819 --- /dev/null +++ b/components/Download.php @@ -0,0 +1,95 @@ + 'nicost.gcalendar::lang.component.download.name', + 'description' => 'nicost.gcalendar::lang.component.download.description' + ]; + } + + public function defineProperties() { + + $calendars = $this->calendarProperties(); + $customProperties = []; + + $result = array_merge($customProperties, $calendars); + + return $result; + } + + public function getCalendarDownloads() { + + // Calenders from config + $calendarList = $this->getCalendarsFromProperties(); + + $data = []; + foreach($calendarList as $calendarData) { + $calendar = []; + $calendar['link'] = sprintf($this->googleIcalUrl, $calendarData['id']); + $calendar['title'] = $calendarData['title']; + + array_push($data, $calendar); + } + + return $data; + } + + private function getCalendarsFromProperties() { + $calendars = []; + foreach($this->properties as $key => $value){ + $exp_key = explode($this->calPropSeparator, $key); + if($exp_key[0] == 'cal' && $this->property($key) == true){ + $calendar = []; + $calendar['id'] = $exp_key[1]; + $calendar['title'] = $exp_key[2]; + array_push($calendars, $calendar); + } + } + + return $calendars; + } + + private function calendarProperties() { + $service = new GoogleCalendarService(); + $calendars = $service->calendarList(); + + if (isset($calendars['error'])) { + $calendars = ''; + } + + $calendarProperties = []; + if (!empty($calendars)) { + foreach ($calendars as &$calendar) { + $calendarData = []; + $calendarData['id'] = $calendar->id; + $calendarData['title'] = $calendar->summary; + + $property = $this->createProperty($calendarData); + $calendarProperties = array_merge($calendarProperties, $property); + } + } + return $calendarProperties; + } + + private function createProperty(array $calendarData) { + return [ + 'cal'.$this->calPropSeparator.$calendarData['id'].$this->calPropSeparator.$calendarData['title'] => [ + 'title' => $calendarData['title'], + 'type' => 'checkbox', + 'group' => 'nicost.gcalendar::lang.component.download.groups.calendars', + // Default to setting from config + 'default' => 0, + ] + ]; + } +} \ No newline at end of file diff --git a/components/download/default.htm b/components/download/default.htm new file mode 100644 index 0000000..2fedc5f --- /dev/null +++ b/components/download/default.htm @@ -0,0 +1,5 @@ +