id); $calendar_settings = $user_config->CALENDAR_SETTINGS; if ( $calendar_type === 'week' && !empty($calendar_settings['step_week']) ) { $step_week = (int) $calendar_settings['step_week']; $hours = floor($step_week / 3600); $minutes = round(($step_week - $hours * 3600) / 60); return sprintf('%1$02u:%2$02u:00', $hours, $minutes); } elseif ( $calendar_type === 'day' && !empty($calendar_settings['step_day']) ) { $step_day = (int) $calendar_settings['step_day']; $hours = floor($step_day / 3600); $minutes = round(($step_day - $hours * 3600) / 60); return sprintf('%1$02u:%2$02u:00', $hours, $minutes); } elseif ( $calendar_type === 'week_group' && !empty($calendar_settings['step_week_group']) ) { $step_week = (int) $calendar_settings['step_week_group']; $hours = floor($step_week / 3600); $minutes = round(($step_week - $hours * 3600) / 60); return sprintf('%1$02u:%2$02u:00', $hours, $minutes); } elseif ( $calendar_type === 'day_group' && !empty($calendar_settings['step_day_group']) ) { $step_day = (int) $calendar_settings['step_day_group']; $hours = floor($step_day / 3600); $minutes = round(($step_day - $hours * 3600) / 60); return sprintf('%1$02u:%2$02u:00', $hours, $minutes); } // An unknown slot type or no appropriate match before: // Return the default duration. return $default_slot_duration; } /** * Retrieves the default calendar date by various methods. * * @return \DateTime The default date for the calendar. * This defaults to the current date if no other date * can be retrieved. */ public static function getDefaultCalendarDate() : \DateTime { $default_date = new \DateTime(); if (\Request::submitted('date') || \Request::submitted('defaultDate')) { $parameter_name = 'date'; if (\Request::submitted('defaultDate')) { $parameter_name = 'defaultDate'; } $date = \Request::getDateTime($parameter_name, 'Y-m-d'); if ($date instanceof \DateTime) { $default_date = $date; //Update the session value: $_SESSION['calendar_date'] = $default_date->format('Y-m-d'); } } elseif (\Request::submitted('semester_id')) { //A semester-ID is set, but no specific date that would override it. //Use the first lecture week of the semester as default date. $semester_id = \Request::option('semester_id'); $semester = \Semester::find($semester_id); if ($semester) { $default_date->setTimestamp($semester->vorles_beginn); //Update the session value: $_SESSION['calendar_date'] = $default_date->format('Y-m-d'); } } elseif (!empty($_SESSION['calendar_date'])) { $date = \DateTime::createFromFormat( 'Y-m-d', $_SESSION['calendar_date'], $default_date->getTimezone() ); if ($date instanceof \DateTime) { $default_date = $date; } } $default_date->setTime(0,0,0); return $default_date; } /** * Constructs a Fullcalendar instance of the schedule for the current user. * * @param string $semester_id The ID of the semester to be used. Defaults to an empty string * which in turn means that the current semester shall be used. * * @param bool $show_hidden_courses Whether to include hidden courses in the schedule (true) * or not (false). Defaults to false. * * @return \Studip\Fullcalendar A fullcalendar instance for the schedule of the current user. */ public static function getScheduleFullcalendar( string $semester_id = '', bool $show_hidden_courses = false ) : \Studip\Fullcalendar { if (!$semester_id) { $semester_id = \Semester::findCurrent()?->id ?? ''; } $schedule_settings = \UserConfig::get(\User::findCurrent()->id)->getValue('SCHEDULE_SETTINGS') ?? []; $slot_duration = '00:30:00'; if (!empty($schedule_settings['size']) && in_array($schedule_settings['size'], ['small', 'large'])) { if ($schedule_settings['size'] === 'small') { $slot_duration = '01:00:00'; } elseif ($schedule_settings['size'] === 'large') { $slot_duration = '00:15:00'; } } //Determine the value of the hiddenDays config. //In case no visible days are set, default to hide Saturday and Sunday. $hidden_days = [6, 7]; if (!empty($schedule_settings['visible_days'])) { $hidden_days = [1, 2, 3, 4, 5, 6, 7]; $hidden_days = array_diff( $hidden_days, $schedule_settings['visible_days'] ); } $fullcalendar_hidden_days = []; foreach ($hidden_days as $day) { if ($day === 7) { $fullcalendar_hidden_days[] = 0; } else { $fullcalendar_hidden_days[] = $day; } } $available_views = [ 'timeGridWeek' => [ 'columnHeaderFormat' => ['weekday' => 'short'], 'slotDuration' => $slot_duration ] ]; if (!in_array(date('N'), $hidden_days)) { //The current day is visible: Allow a day view: $available_views['timeGridDay'] = [ 'columnHeaderFormat' => ['weekday' => 'short'], 'slotDuration' => $slot_duration ]; } return new \Studip\Fullcalendar( _('Stundenplan'), [ 'editable' => true, 'selectable' => true, 'dialog_size' => 'auto', 'minTime' => $schedule_settings['start_time'] ?? '08:00', 'maxTime' => $schedule_settings['end_time'] ?? '20:00', 'allDaySlot' => false, 'header' => [ 'left' => count($available_views) > 1 ? implode(',', array_keys($available_views)) : '', 'right' => '' ], 'views' => $available_views, 'columnHeaderFormat' => ['weekday' => 'short'], 'defaultView' => 'timeGridWeek', 'defaultDate' => date('Y-m-d'), 'slotLabelFormat' => [ 'hour' => 'numeric', 'minute' => '2-digit', 'omitZeroMinute' => false ], 'weekends' => true, 'hiddenDays' => $fullcalendar_hidden_days, 'timeGridEventMinHeight' => 20, 'eventSources' => [ [ 'url' => \URLHelper::getURL( 'dispatch.php/calendar/schedule/data', ['show_hidden' => $show_hidden_courses] ), 'method' => 'GET', 'extraParams' => [ 'semester_id' => $semester_id, 'full_semester_time_range' => false ] ] ], 'studip_urls' => [ 'add' => \URLHelper::getURL('dispatch.php/calendar/schedule/entry/add') ] ], [ 'class' => 'schedule' ] ); } public static function getPersonalFullcalendar(): \Studip\Fullcalendar { $calendar_owner = \User::findCurrent(); $fullcalendar_studip_urls = []; $fullcalendar_studip_urls['add'] = \URLHelper::getURL('dispatch.php/calendar/date/add', ['user_id' => $calendar_owner->id]); $calendar_settings = $calendar_owner->getConfiguration()->CALENDAR_SETTINGS ?? []; //Map calendar settings to fullcalendar settings: $default_view = 'timeGridWeek'; if (!empty($calendar_settings['view'])) { if ($calendar_settings['view'] === 'day') { $default_view = 'timeGridDay'; } elseif ($calendar_settings['view'] === 'month') { $default_view = 'dayGridMonth'; } } $slot_durations = [ 'day' => self::getCalendarSlotDuration('day'), 'week' => self::getCalendarSlotDuration('week'), 'day_group' => self::getCalendarSlotDuration('day_group'), 'week_group' => self::getCalendarSlotDuration('week_group') ]; return new \Studip\Fullcalendar( _('Kalender'), [ 'editable' => true, 'selectable' => true, 'studip_urls' => $fullcalendar_studip_urls, 'dialog_size' => 'auto', 'minTime' => sprintf('%02u:00', $calendar_settings['start'] ?? 8), 'maxTime' => sprintf('%02u:00', $calendar_settings['end'] ?? 20), 'defaultDate' => self::getDefaultCalendarDate()->format('Y-m-d'), 'allDaySlot' => true, 'allDayText' => '', 'header' => [ 'left' => 'dayGridYear,dayGridMonth,timeGridWeek,timeGridDay', 'right' => 'prev,today,next' ], 'weekNumbers' => true, 'views' => [ 'dayGridMonth' => [ 'eventTimeFormat' => ['hour' => 'numeric', 'minute' => '2-digit'], 'titleFormat' => ['year' => 'numeric', 'month' => 'long'], 'displayEventEnd' => true ], 'timeGridWeek' => [ 'columnHeaderFormat' => ['weekday' => 'short', 'year' => 'numeric', 'month' => '2-digit', 'day' => '2-digit', 'omitCommas' => true], 'weekends' => $calendar_settings['type_week'] === 'LONG', 'titleFormat' => ['year' => 'numeric', 'month' => '2-digit', 'day' => '2-digit'], 'slotDuration' => $slot_durations['week'] ], 'timeGridDay' => [ 'columnHeaderFormat' => ['weekday' => 'long', 'year' => 'numeric', 'month' => '2-digit', 'day' => '2-digit', 'omitCommas' => true], 'titleFormat' => ['year' => 'numeric', 'month' => '2-digit', 'day' => '2-digit'], 'slotDuration' => $slot_durations['day'] ] ], 'defaultView' => $default_view, 'eventSources' => [ [ 'url' => \URLHelper::getURL( 'dispatch.php/calendar/calendar/calendar_data/user_' . $calendar_owner->id ), 'method' => 'GET', 'extraParams' => [] ] ] ] ); } }