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(),
|
||||
|
|
|
|||
15
app/util.php
15
app/util.php
|
|
@ -92,7 +92,7 @@ function url(string $path = '/'): string
|
|||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '21';
|
||||
const DIC_ASSET_VERSION = '22';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
|
|
@ -332,6 +332,19 @@ function week_start(string $iso): string
|
|||
/** Anzahl der Kalenderwochen, die die Kalenderansicht standardmäßig zeigt. */
|
||||
const CALENDAR_WEEKS = 4;
|
||||
|
||||
/**
|
||||
* Auf Smartphones wird zusätzlich Zeitraum vor/nach der Startwoche gerendert,
|
||||
* damit sich der Kalender seitlich durchwischen lässt (in Monaten).
|
||||
*/
|
||||
const CALENDAR_MOBILE_MONTHS = 2;
|
||||
|
||||
/** Grobe Geräteerkennung: schmale Touch-Geräte bekommen den erweiterten Kalender. */
|
||||
function client_is_mobile(): bool
|
||||
{
|
||||
$agent = (string) ($_SERVER['HTTP_USER_AGENT'] ?? '');
|
||||
return $agent !== '' && preg_match('/Android|iPhone|iPod|Windows Phone|IEMobile|Opera Mini|Mobile Safari|Mobile\//i', $agent) === 1;
|
||||
}
|
||||
|
||||
function month_start(string $iso): string
|
||||
{
|
||||
return date_obj($iso)->modify('first day of this month')->format('Y-m-d');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue