diff --git a/application/config/routes.php b/application/config/routes.php index 6a8d2b8fb..a22e94990 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -120,8 +120,8 @@ $route['api/frontend/v1/stv/[sS]tudents/([WS]S[0-9]{4})/prestudent/(:num)'] = 'a $route['api/frontend/v1/stv/[sS]tudents/([WS]S[0-9]{4})/person/(:num)'] = 'api/frontend/v1/stv/Students/getPerson/$1/$2'; -$route['test'] = 'Test'; -$route['test/.*'] = 'Test'; +$route['lvplan/caldav'] = 'LvPlanCalDAV'; +$route['lvplan/caldav/.*'] = 'LvPlanCalDAV'; // load routes from extensions, also look for environment-specific configs $subdirs = ['application/config/extensions', 'application/config/' . ENVIRONMENT . '/extensions']; diff --git a/application/controllers/Test.php b/application/controllers/LvPlanCalDAV.php similarity index 77% rename from application/controllers/Test.php rename to application/controllers/LvPlanCalDAV.php index f3803bdae..e45478f62 100644 --- a/application/controllers/Test.php +++ b/application/controllers/LvPlanCalDAV.php @@ -4,7 +4,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** */ -class Test extends FHC_Controller +class LvPlanCalDAV extends FHC_Controller { /** * Constructor @@ -27,13 +27,18 @@ class Test extends FHC_Controller $tree = array( new \Sabre\CalDAV\Principal\Collection($principalBackend), - new SabreDAVReadOnlyCalendarRoot($principalBackend, $calendarBackend) + new \Sabre\CalDAV\CalendarRoot($principalBackend, $calendarBackend) ); $server = new \Sabre\DAV\Server($tree); - $path = "/ma1433/core/FHC-Core/index.ci.php/test"; - $server->setBaseUri($path); + $baseUri = '/' . implode('/', array_filter([ + trim(BASE_LOCATION, '/'), + trim($this->config->item('index_page'), '/'), + 'lvplan', + 'caldav' + ])); + $server->setBaseUri($baseUri); $authBackend->setRealm('SabreDAV'); $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend); diff --git a/application/controllers/jobs/TempusJob.php b/application/controllers/jobs/TempusJob.php index 92901aa33..350732cc7 100644 --- a/application/controllers/jobs/TempusJob.php +++ b/application/controllers/jobs/TempusJob.php @@ -13,7 +13,7 @@ class TempusJob extends JOB_Controller $this->_ci =& get_instance(); $this->_ci->load->helper('hlp_sancho_helper'); - $this->_ci->load->library('KalenderLib'); + $this->_ci->load->library('KalenderLib', ["uid" => null]); } diff --git a/application/libraries/KalenderLib.php b/application/libraries/KalenderLib.php index 87c6d94e0..18c94b805 100644 --- a/application/libraries/KalenderLib.php +++ b/application/libraries/KalenderLib.php @@ -46,6 +46,8 @@ class KalenderLib tbl_kalender.von, tbl_kalender.bis, tbl_kalender_ort.ort_kurzbz, + tbl_kalender_ort.ort_kurzbz as ko_ort_kurzbz, + tbl_kalender_ort.location as ko_location, tbl_lehreinheit.lehreinheit_id, tbl_lehreinheit.lehrveranstaltung_id, tbl_lehreinheit.lehrfach_id, @@ -173,6 +175,8 @@ class KalenderLib 'tooltip' => 'tip', 'status_kurzbz' => $row->status_kurzbz, 'ort_kurzbz' => isset($row->ort_kurzbz) ? $row->ort_kurzbz : '', + 'ko_ort_kurzbz' => isset($row->ko_ort_kurzbz) ? $row->ko_ort_kurzbz : '', + 'ko_location' => isset($row->ko_location) ? $row->ko_location : '', 'lehrform' => isset($row->lehrform_kurzbz) ? $row->lehrform_kurzbz : '', 'lehrfach' => isset($row->lehrfach_kurzbz) ? $row->lehrfach_kurzbz : '', 'lehrfach_bez' => isset($row->lehrfach_bezeichnung) ? $row->lehrfach_bezeichnung : '', diff --git a/application/libraries/sabredav/SabreDAVCalDAVLib.php b/application/libraries/sabredav/SabreDAVCalDAVLib.php index 0417f7002..7b78344a4 100644 --- a/application/libraries/sabredav/SabreDAVCalDAVLib.php +++ b/application/libraries/sabredav/SabreDAVCalDAVLib.php @@ -2,11 +2,6 @@ require_once __DIR__.'/caldav/SabreDAVACLPrincipalBackend.php'; require_once __DIR__.'/caldav/SabreDAVCalDAVBackend.php'; -require_once __DIR__.'/caldav/SabreDAVReadOnlyACL.php'; -require_once __DIR__.'/caldav/SabreDAVReadOnlyCalendarRoot.php'; -require_once __DIR__.'/caldav/SabreDAVReadOnlyCalendarHome.php'; -require_once __DIR__.'/caldav/SabreDAVReadOnlyCalendar.php'; -require_once __DIR__.'/caldav/SabreDAVReadOnlyCalendarObject.php'; /** * Loads the SabreDAV CalDAV classes for the LVPlan calendar endpoint. diff --git a/application/libraries/sabredav/caldav/SabreDAVCalDAVBackend.php b/application/libraries/sabredav/caldav/SabreDAVCalDAVBackend.php index 2bfa12804..2f2b2b822 100644 --- a/application/libraries/sabredav/caldav/SabreDAVCalDAVBackend.php +++ b/application/libraries/sabredav/caldav/SabreDAVCalDAVBackend.php @@ -9,6 +9,10 @@ class SabreDAVCalDAVBackend extends \Sabre\CalDAV\Backend\AbstractBackend protected $CI; + CONST CALENDAR_NAME = 'LVPlan'; + CONST CAL_CATEGORY_STUNDENPLAN = 'Stundenplan'; + CONST CAL_CATEGORY_STUNDENPLAN_EXAM = 'StundenplanExam'; + CONST CAL_CATEGORY_STUNDENPLAN_ONLINE = 'StundenplanOnline'; /** * Creates the backend * @@ -52,11 +56,11 @@ class SabreDAVCalDAVBackend extends \Sabre\CalDAV\Backend\AbstractBackend $calendars = array(); $calendar = array( 'id' => $user, - 'uri' => 'LVPlan-'.$user, + 'uri' => self::CALENDAR_NAME.'-'.$user, 'principaluri' => 'principals/'.$user, '{' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => $this->buildCalendarCtag($user), '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet(array('VEVENT')), - '{DAV:}displayname' => 'LVPlan', + '{DAV:}displayname' => self::CALENDAR_NAME, '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description comes here', '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'Europe/Vienna', '{http://apple.com/ns/ical/}calendar-order' => '1', @@ -226,10 +230,23 @@ class SabreDAVCalDAVBackend extends \Sabre\CalDAV\Backend\AbstractBackend $description = $item->lehrfach_bez . "\r\n"; if (isset($item->lektor) && is_array($item->lektor) && count($item->lektor) > 0) { - $description .= "Lehrer: " . join(", ", array_map(function($teacher) { return $teacher["kurzbz"]; }, $item->lektor)) . "\r\n"; + $description .= "Lektor*in: " . join(", ", array_map(function($teacher) { return $teacher["kurzbz"]; }, $item->lektor)) . "\r\n"; } } + + $category = self::CAL_CATEGORY_STUNDENPLAN; + if ($item->type === 'lehreinheit') { + if ($item->lehrform === 'EXAM') { + $category = self::CAL_CATEGORY_STUNDENPLAN_EXAM; + } else if (!isset($item->ko_ort_kurzbz) || $item->ko_ort_kurzbz === '') { + $category = self::CAL_CATEGORY_STUNDENPLAN_ONLINE; + } + } else if ($item->type === 'reservierung' && (!isset($item->ko_ort_kurzbz) || $item->ko_ort_kurzbz === '')) { + $category = self::CAL_CATEGORY_STUNDENPLAN_ONLINE; + } + + $parsedStartDate = $this->formatICalLocalDateTime($item->isostart); $parsedEndDate = $this->formatICalLocalDateTime($item->isoend); $lastModified = $this->formatICalUtcDateTime(isset($item->updateamum) ? $item->updateamum : null); @@ -244,7 +261,7 @@ class SabreDAVCalDAVBackend extends \Sabre\CalDAV\Backend\AbstractBackend .$this->buildICalTextLine('SUMMARY', $summary) .$this->buildICalTextLine('DESCRIPTION', $description) .$this->buildICalTextLine('LOCATION', isset($item->ort_kurzbz) ? $item->ort_kurzbz : '') - .$this->buildICalTextLine('CATEGORIES', 'Stundenplans') + .$this->buildICalTextLine('CATEGORIES', $category) .$this->buildICalLine('DTSTART', $parsedStartDate, array('TZID' => 'Europe/Vienna')) .$this->buildICalLine('DTEND', $parsedEndDate, array('TZID' => 'Europe/Vienna')); @@ -271,7 +288,7 @@ class SabreDAVCalDAVBackend extends \Sabre\CalDAV\Backend\AbstractBackend } sort($fragments, SORT_STRING); - return 'LVPlan-'.$userUID.'-'.md5(implode('|', $fragments)); + return self::CALENDAR_NAME.'-'.$userUID.'-'.md5(implode('|', $fragments)); } protected function buildICalTextLine($name, $value, array $parameters = array()) diff --git a/application/libraries/sabredav/caldav/SabreDAVReadOnlyACL.php b/application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyACL.php similarity index 100% rename from application/libraries/sabredav/caldav/SabreDAVReadOnlyACL.php rename to application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyACL.php diff --git a/application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendar.php b/application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendar.php similarity index 100% rename from application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendar.php rename to application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendar.php diff --git a/application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarHome.php b/application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarHome.php similarity index 100% rename from application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarHome.php rename to application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarHome.php diff --git a/application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarObject.php b/application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarObject.php similarity index 100% rename from application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarObject.php rename to application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarObject.php diff --git a/application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarRoot.php b/application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarRoot.php similarity index 100% rename from application/libraries/sabredav/caldav/SabreDAVReadOnlyCalendarRoot.php rename to application/libraries/sabredav/caldav/read_only_calendar/SabreDAVReadOnlyCalendarRoot.php