diff options
Diffstat (limited to 'app/controllers/calendar')
| -rw-r--r-- | app/controllers/calendar/calendar.php | 101 | ||||
| -rw-r--r-- | app/controllers/calendar/contentbox.php | 49 | ||||
| -rw-r--r-- | app/controllers/calendar/date.php | 26 | ||||
| -rw-r--r-- | app/controllers/calendar/schedule.php | 2 |
4 files changed, 119 insertions, 59 deletions
diff --git a/app/controllers/calendar/calendar.php b/app/controllers/calendar/calendar.php index c605c01..0cb96ad 100644 --- a/app/controllers/calendar/calendar.php +++ b/app/controllers/calendar/calendar.php @@ -12,8 +12,12 @@ class Calendar_CalendarController extends AuthenticatedController } - protected function buildSidebar($schedule = false) - { + protected function buildSidebar( + bool $schedule = false, + string $user_id = '', + string $group_id = '' + ) { + $sidebar = Sidebar::get(); $actions = new ActionsWidget(); @@ -25,11 +29,17 @@ class Calendar_CalendarController extends AuthenticatedController ['data-dialog' => 'size=default'] ); } else { + $params = []; + if ($user_id) { + $params['user_id'] = $user_id; + } elseif ($group_id) { + $params['group_id'] = $group_id; + } $actions->addLink( _('Termin anlegen'), - $this->url_for('calendar/date/add'), + $this->url_for('calendar/date/add', $params), Icon::create('add'), - ['data-dialog' => 'size=auto'] + ['data-dialog' => 'size=auto', 'class' => 'calendar-action'] ); } @@ -101,6 +111,8 @@ class Calendar_CalendarController extends AuthenticatedController { PageLayout::setTitle(_('Kalender')); + $default_date = \Studip\Calendar\Helper::getDefaultCalendarDate(); + if (Request::isPost()) { //In case the checkbox of the options widget is clicked, the resulting //POST request must be catched here and result in a redirect. @@ -181,7 +193,11 @@ class Calendar_CalendarController extends AuthenticatedController throw new AccessDeniedException(_('Sie dürfen diesen Kalender nicht sehen!')); } - $this->buildSidebar(false); + $this->buildSidebar( + false, + $calendar_owner ? $calendar_owner->id : '', + $selected_group ? $selected_group->id : '' + ); $sidebar = Sidebar::get(); @@ -189,6 +205,7 @@ class Calendar_CalendarController extends AuthenticatedController if ($calendar_owner && $calendar_owner->id === User::findCurrent()->id) { //The user is viewing their own calendar. $options = new OptionsWidget(); + $options->addLayoutCSSClass('calendar-action'); $options->addCheckbox( _('Abgelehnte Termine anzeigen'), Request::bool('show_declined'), @@ -223,6 +240,7 @@ class Calendar_CalendarController extends AuthenticatedController $this->url_for('calendar/calendar/index', ['view' => 'group']), 'group_id' ); + $group_select->addLayoutCSSClass('calendar-action'); $options = [ '' => _('(bitte wählen)') ]; @@ -249,6 +267,7 @@ class Calendar_CalendarController extends AuthenticatedController $this->url_for('calendar/calendar'), 'user_id' ); + $calendar_select->addLayoutCSSClass('calendar-action'); $select_options = [ '' => _('(bitte wählen)'), User::findCurrent()->id => _('Eigener Kalender') @@ -321,7 +340,6 @@ class Calendar_CalendarController extends AuthenticatedController $slot_durations = $this->getUserCalendarSlotSettings(); //Create the fullcalendar object: - $default_date = \Studip\Calendar\Helper::getDefaultCalendarDate(); $data_url_params = []; if (Request::bool('show_declined')) { @@ -432,7 +450,7 @@ class Calendar_CalendarController extends AuthenticatedController _('Termin anlegen'), $this->url_for('calendar/date/add/course_' . $course->id), Icon::create('add'), - ['data-dialog' => 'size=default'] + ['data-dialog' => 'size=default', 'class' => 'calendar-action'] ); $actions->addLink( _('Drucken'), @@ -564,20 +582,18 @@ class Calendar_CalendarController extends AuthenticatedController $course_dates = CalendarCourseDate::getEvents($begin, $end, $owner->id); foreach ($course_dates as $course_date) { $event = $course_date->toEventData(User::findCurrent()->id); - $event->background_colour = '#ffffff'; + $event->background_colour = ''; $event->text_colour = '#000000'; - $event->border_colour = '#000000'; - $event->event_classes = []; + $event->border_colour = ''; $result[] = $event->toFullcalendarEvent(); } //Include relevant cancelled course dates: $cancelled_course_dates = CalendarCourseExDate::getEvents($begin, $end, $owner->id); foreach ($cancelled_course_dates as $cancelled_course_date) { $event = $cancelled_course_date->toEventData(User::findCurrent()->id); - $event->background_colour = '#ffffff'; + $event->background_colour = ''; $event->text_colour = '#000000'; - $event->border_colour = '#000000'; - $event->event_classes = []; + $event->border_colour = ''; $result[] = $event->toFullcalendarEvent(); } } @@ -660,7 +676,7 @@ class Calendar_CalendarController extends AuthenticatedController public function add_courses_action() { $selected_semester_pseudo_id = Request::option('semester_id'); - $this->selected_semesters_id = ''; + $this->selected_semester_id = ''; $this->available_semester_data = []; $semesters = Semester::getAll(); foreach ($semesters as $semester) { @@ -691,8 +707,9 @@ class Calendar_CalendarController extends AuthenticatedController $this->selected_semester_id = $semester->id; } else { $this->selected_semester_id = $selected_semester_pseudo_id ?? ''; - if (!Semester::exists($this->selected_semesters_id)) { - $this->selected_semester_id = ''; + if (!Semester::exists($this->selected_semester_id)) { + $semester = Semester::findCurrent(); + $this->selected_semester_id = $semester->id; } } @@ -755,29 +772,41 @@ class Calendar_CalendarController extends AuthenticatedController PageLayout::postError(_('Bitte wählen Sie aus, welche Termine exportiert werden sollen!')); return; } - $ical = ''; - $calendar_export = new ICalendarExport(); - if ($this->dates_to_export === 'user') { - $ical = $calendar_export->exportCalendarDates(User::findCurrent()->id, $this->begin, $this->end); - } elseif ($this->dates_to_export === 'course') { - $ical = $calendar_export->exportCourseDates(User::findCurrent()->id, $this->begin, $this->end); - $ical .= $calendar_export->exportCourseExDates(User::findCurrent()->id, $this->begin, $this->end); - } elseif ($this->dates_to_export === 'all') { - $ical = $calendar_export->exportCalendarDates(User::findCurrent()->id, $this->begin, $this->end); - $ical .= $calendar_export->exportCourseDates(User::findCurrent()->id, $this->begin, $this->end); - $ical .= $calendar_export->exportCourseExDates(User::findCurrent()->id, $this->begin, $this->end); - } - $ical = $calendar_export->writeHeader() . $ical . $calendar_export->writeFooter(); - $this->response->add_header('Content-Type', 'text/calendar;charset=utf-8'); - $this->response->add_header('Content-Disposition', 'attachment; filename="studip.ics"'); - $this->response->add_header('Content-Transfer-Encoding', 'binary'); - $this->response->add_header('Pragma', 'public'); - $this->response->add_header('Cache-Control', 'private'); - $this->response->add_header('Content-Length', strlen($ical)); - $this->render_text($ical); + $this->relocate($this->url_for('calendar/calendar/export_file', [ + 'begin' => $this->begin->format('d.m.Y'), + 'end' => $this->end->format('d.m.Y'), + 'dates_to_export' => $this->dates_to_export + ])); } } + public function export_file_action() + { + $begin = Request::getDateTime('begin', 'd.m.Y'); + $end = Request::getDateTime('end', 'd.m.Y'); + $dates_to_export = Request::option('dates_to_export', 'user'); + $ical = ''; + $calendar_export = new ICalendarExport(); + if ($dates_to_export === 'user') { + $ical = $calendar_export->exportCalendarDates(User::findCurrent()->id, $begin, $end); + } elseif ($dates_to_export === 'course') { + $ical = $calendar_export->exportCourseDates(User::findCurrent()->id, $begin, $end); + $ical .= $calendar_export->exportCourseExDates(User::findCurrent()->id, $begin, $end); + } elseif ($dates_to_export === 'all') { + $ical = $calendar_export->exportCalendarDates(User::findCurrent()->id, $begin, $end); + $ical .= $calendar_export->exportCourseDates(User::findCurrent()->id, $begin, $end); + $ical .= $calendar_export->exportCourseExDates(User::findCurrent()->id, $begin, $end); + } + $ical = $calendar_export->writeHeader() . $ical . $calendar_export->writeFooter(); + $this->response->add_header('Content-Type', 'text/calendar;charset=utf-8'); + $this->response->add_header('Content-Disposition', 'attachment; filename="studip.ics"'); + $this->response->add_header('Content-Transfer-Encoding', 'binary'); + $this->response->add_header('Pragma', 'public'); + $this->response->add_header('Cache-Control', 'private'); + $this->response->add_header('Content-Length', strlen($ical)); + $this->render_text($ical); + } + public function import_action() {} public function import_file_action() diff --git a/app/controllers/calendar/contentbox.php b/app/controllers/calendar/contentbox.php index 8ba5215..b684905 100644 --- a/app/controllers/calendar/contentbox.php +++ b/app/controllers/calendar/contentbox.php @@ -78,21 +78,29 @@ class Calendar_ContentboxController extends StudipController if ($this->admin) { $this->isProfile = $this->single && $this->userRange; } + + // Sort dates + usort($this->termine, function ($a, $b) { + [$a_begin, $a_end] = $this->parseBeginAndEndFromDate($a); + [$b_begin, $b_end] = $this->parseBeginAndEndFromDate($b); + + return $a_begin - $b_begin + ?: $a_end - $b_end; + }); } private function parseSeminar($id) { - $course = Course::find($id); - $this->termine = $course->getDatesWithExdates()->findBy('end_time', [$this->start, $this->start + $this->timespan], '><'); - foreach ($this->termine as $course_date) { - if ($this->course_range) { - //Display only date and time: - $this->titles[$course_date->id] = $course_date->getFullName('include-room'); - } else { - //Include the course title: - $this->titles[$course_date->id] = $course_date->getFullName('verbose'); - } - } + // Display only date and time if in course range, include course title + // otherwise + $date_format = $this->course_range ? 'include-room' : 'verbose'; + + $this->termine = Course::find($id)->getDatesWithExdates() + ->findBy('end_time', [$this->start, $this->start + $this->timespan], '><') + ->map(function ($course_date) use ($date_format) { + $this->titles[$course_date->id] = $course_date->getFullName($date_format); + return $course_date; + }); } private function parseUser($id) @@ -170,4 +178,23 @@ class Calendar_ContentboxController extends StudipController $this->termine[] = $assignment; } } + + private function parseBeginAndEndFromDate($date): array + { + if ($date instanceof CalendarDateAssignment) { + return [ + $date->calendar_date->begin, + $date->calendar_date->end, + ]; + } + + if ($date instanceof CourseDate || $date instanceof CourseExDate) { + return [ + $date->date, + $date->end_time, + ]; + } + + throw new Exception('Invalid date type passed: ' . get_class($date)); + } } diff --git a/app/controllers/calendar/date.php b/app/controllers/calendar/date.php index 72f3a40..cb61a7e 100644 --- a/app/controllers/calendar/date.php +++ b/app/controllers/calendar/date.php @@ -27,9 +27,8 @@ class Calendar_DateController extends AuthenticatedController $range_id = $range_and_id[1]; } if (!$range) { - //Show the personal calendar of the current user: + $range_id = Request::option('user_id', $GLOBALS['user']->id); $range = 'user'; - $range_id = $GLOBALS['user']->id; } $owner = null; @@ -233,6 +232,14 @@ class Calendar_DateController extends AuthenticatedController $this->date->repetition_end = $this->date->end; } else { $time = new DateTime(); + if (Request::submitted('timestamp')) { + $time->setTimestamp(Request::int('timestamp')); + } elseif (Request::submitted('defaultDate')) { + $date_parts = explode('-', Request::get('defaultDate')); + if (count($date_parts) === 3) { + $time->setDate($date_parts[0], $date_parts[1], $date_parts[2]); + } + } $time = $time->add(new DateInterval('PT1H')); $time->setTime(intval($time->format('H')), 0, 0); $this->date->begin = $time->getTimestamp(); @@ -325,15 +332,12 @@ class Calendar_DateController extends AuthenticatedController if ($this->date->isNew()) { if (!($owner instanceof Course)) { - //Assign the date to the calendar of the current user by default: - $user = User::findCurrent(); - if ($user) { - $this->calendar_assignment_items[] = [ - 'value' => $user->id, - 'name' => $user->getFullName(), - 'deletable' => true - ]; - } + //Assign the date to the calendar of the owner by default: + $this->calendar_assignment_items[] = [ + 'value' => $owner->id, + 'name' => $owner->getFullName(), + 'deletable' => true + ]; } } else { $exceptions = CalendarDateException::findBySql( diff --git a/app/controllers/calendar/schedule.php b/app/controllers/calendar/schedule.php index 88c4304..5d9a26e 100644 --- a/app/controllers/calendar/schedule.php +++ b/app/controllers/calendar/schedule.php @@ -143,7 +143,7 @@ class Calendar_ScheduleController extends AuthenticatedController 'entry_height' => $this->calendar_view->getHeight() ]; - $factory = new Flexi_TemplateFactory($this->dispatcher->trails_root . '/views'); + $factory = new Flexi\Factory($this->dispatcher->trails_root . '/views'); PageLayout::addStyle($factory->render('calendar/schedule/stylesheet', $style_parameters), 'screen, print'); if (Request::option('printview')) { |
