Kalender auf Smartphones: 2 Monate zurück/voraus rendern, Start bei aktueller Woche
This commit is contained in:
parent
b6136563a7
commit
2ca19dd2fb
5 changed files with 46 additions and 7 deletions
|
|
@ -418,6 +418,10 @@ function page_calendar(array $user): void
|
|||
$employeeId = query_int('employee');
|
||||
$showCancelled = query_string('cancelled') === '1';
|
||||
|
||||
// Startwoche: Montag der Woche, in der $date liegt.
|
||||
$focusFrom = week_start($date);
|
||||
$focusTo = add_days($focusFrom, CALENDAR_WEEKS * 7 - 1);
|
||||
|
||||
if ($view === 'day') {
|
||||
$from = $to = $date;
|
||||
} elseif ($view === 'month') {
|
||||
|
|
@ -425,8 +429,15 @@ function page_calendar(array $user): void
|
|||
$to = month_end($date);
|
||||
} else {
|
||||
// Vier Kalenderwochen ab dem Montag der Woche, in der $date liegt.
|
||||
$from = week_start($date);
|
||||
$to = add_days($from, CALENDAR_WEEKS * 7 - 1);
|
||||
$from = $focusFrom;
|
||||
$to = $focusTo;
|
||||
if (client_is_mobile()) {
|
||||
// Smartphone: mehr Wochen rendern, damit sich der Kalender nach
|
||||
// links und rechts wischen lässt (± 2 Monate um die Startwoche).
|
||||
$from = week_start(date_obj($date)->modify('-' . CALENDAR_MOBILE_MONTHS . ' months')->format('Y-m-d'));
|
||||
$later = date_obj($date)->modify('+' . CALENDAR_MOBILE_MONTHS . ' months')->format('Y-m-d');
|
||||
$to = add_days(week_start($later), 6);
|
||||
}
|
||||
}
|
||||
|
||||
$bookings = booking_list($from, $to, $showCancelled, $employeeId);
|
||||
|
|
@ -494,8 +505,8 @@ function page_calendar(array $user): void
|
|||
if ($view === 'day') {
|
||||
$title = fmt_date_long($date);
|
||||
} elseif ($view === 'weeks') {
|
||||
$title = 'KW ' . date_obj($from)->format('W') . '–' . date_obj($to)->format('W')
|
||||
. ' · ' . fmt_date_range($from, $to);
|
||||
$title = 'KW ' . date_obj($focusFrom)->format('W') . '–' . date_obj($focusTo)->format('W')
|
||||
. ' · ' . fmt_date_range($focusFrom, $focusTo);
|
||||
} else {
|
||||
$title = fmt_month($date);
|
||||
}
|
||||
|
|
@ -509,6 +520,7 @@ function page_calendar(array $user): void
|
|||
'days' => $days,
|
||||
'rows' => $rows,
|
||||
'calTitle' => $title,
|
||||
'focusFrom' => $focusFrom,
|
||||
'prevDate' => $prevDate,
|
||||
'nextDate' => $nextDate,
|
||||
'today' => today_iso(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue