settingService = $settingService; $this->calendarService = $calendarService; } /** * Displays the calendar export page. * * @param array $params Request parameters */ #[RequiresPermission(CalendarPermissions::VIEW)] public function get(array $params): Response { if (isset($_GET['remove'])) { $this->settingService->deleteSetting('usersettings.'.session('userdata.id').'.icalSecret'); $this->tpl->setNotification('notifications.ical_removed_success', 'success'); } $this->assignUrl(); return $this->tpl->displayPartial('calendar.export'); } /** * Handles iCal URL generation. * * @param array $params Request parameters */ #[RequiresPermission(CalendarPermissions::VIEW)] public function post(array $params): Response { if (isset($_POST['generateUrl'])) { try { $this->calendarService->generateIcalHash(); $this->tpl->setNotification('notifications.ical_success', 'success'); } catch (\Exception $e) { $this->tpl->setNotification('There was a problem generating the ical hash', 'error'); } } $this->assignUrl(); return $this->tpl->displayPartial('calendar.export'); } /** * Assigns the iCal URL to the template. */ private function assignUrl(): void { $icalUrl = ''; try { $icalUrl = $this->calendarService->getICalUrl(); } catch (\Exception $e) { $this->tpl->setNotification('Could not find ical URL', 'error'); } $this->tpl->assign('url', $icalUrl); } }