Files
mood-tracking/templates/pages/archive.php
T

299 lines
20 KiB
PHP

<?php
$baseParams = ['view' => $archiveView];
if ($archiveFilterMonth !== '') {
$baseParams['filter_month'] = $archiveFilterMonth;
}
$archiveUrl = static function (array $params = []) use ($baseParams): string {
$query = array_filter(array_merge($baseParams, $params), static fn (mixed $value): bool => $value !== null && $value !== '');
return $query === [] ? '/archive' : '/archive?' . http_build_query($query);
};
$detailType = $selectedEntry !== null
? 'day'
: ($selectedWeek !== null
? 'week'
: ($selectedMonth !== null ? 'month' : null));
$detailOpen = $detailType !== null;
?>
<section class="archive-page">
<article class="glass-panel archive-shell">
<div class="archive-toolbar archive-toolbar--compact">
<nav class="archive-switcher" aria-label="Archivansicht">
<a class="archive-switcher__item <?= $archiveView === 'days' ? 'active' : '' ?>" href="<?= e('/archive?view=days' . ($archiveFilterMonth !== '' ? '&filter_month=' . rawurlencode($archiveFilterMonth) : '')) ?>">Tage</a>
<a class="archive-switcher__item <?= $archiveView === 'weeks' ? 'active' : '' ?>" href="<?= e('/archive?view=weeks' . ($archiveFilterMonth !== '' ? '&filter_month=' . rawurlencode($archiveFilterMonth) : '')) ?>">Wochen</a>
<a class="archive-switcher__item <?= $archiveView === 'months' ? 'active' : '' ?>" href="<?= e('/archive?view=months' . ($archiveFilterMonth !== '' ? '&filter_month=' . rawurlencode($archiveFilterMonth) : '')) ?>">Monate</a>
</nav>
<form method="get" action="/archive" class="archive-filter">
<input type="hidden" name="view" value="<?= e($archiveView) ?>">
<label>
<span>Zeitraum</span>
<select name="filter_month" onchange="this.form.submit()">
<option value="">Alle Monate</option>
<?php foreach ($archiveMonthOptions as $monthOption): ?>
<option value="<?= e($monthOption) ?>" <?= $archiveFilterMonth === $monthOption ? 'selected' : '' ?>><?= e(month_label($monthOption)) ?></option>
<?php endforeach; ?>
</select>
</label>
</form>
</div>
<div class="archive-workspace">
<section class="archive-main">
<?php if ($archiveView === 'days'): ?>
<div class="archive-list-header">
<div>
<p class="eyebrow">Tage</p>
<h4>Gespeicherte Tage</h4>
</div>
<span class="chart-chip"><?= e((string) count($entries)) ?> Tage</span>
</div>
<?php if ($entries === []): ?>
<p class="empty-state">Für diesen Zeitraum gibt es noch keine getrackten Tage.</p>
<?php else: ?>
<div class="archive-rows">
<?php foreach ($entries as $entry): ?>
<a class="archive-row archive-row--day <?= $selectedEntry !== null && $selectedEntry['date'] === $entry['date'] ? 'active' : '' ?>" href="<?= e($archiveUrl(['date' => $entry['date'], 'week' => null, 'month_key' => null])) ?>">
<div class="archive-row__main">
<strong><?= e(format_compact_date($entry['date'])) ?></strong>
<span><?= e($entry['evaluation']['label']) ?></span>
</div>
<div class="archive-row__meta">
<span><?= e(format_points((float) $entry['evaluation']['total'])) ?> Punkte</span>
<span>Stimmung <?= e((string) $entry['mood']) ?>/10</span>
</div>
<span class="archive-row__hint">Ansehen</span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php elseif ($archiveView === 'weeks'): ?>
<div class="archive-list-header">
<div>
<p class="eyebrow">Wochen</p>
<h4>Wöchentliche KI-Rückblicke</h4>
</div>
<span class="chart-chip"><?= e((string) count($weeklyArchive)) ?> Wochen</span>
</div>
<?php if ($weeklyArchive === []): ?>
<p class="empty-state">Für diesen Zeitraum sind noch keine Wochen im Archiv vorhanden.</p>
<?php else: ?>
<div class="archive-rows archive-rows--summary">
<?php foreach ($weeklyArchive as $week): ?>
<a class="archive-row archive-row--summary archive-row--week <?= $selectedWeek !== null && $selectedWeek['summary_key'] === $week['summary_key'] ? 'active' : '' ?>" href="<?= e($archiveUrl(['week' => $week['summary_key'], 'date' => null, 'month_key' => null])) ?>">
<div class="archive-row__main archive-row__main--week">
<div class="archive-row__title-group">
<strong><?= e($week['label']) ?></strong>
<span><?= e(format_compact_date((string) $week['date_from'])) ?> bis <?= e(format_compact_date((string) $week['date_to'])) ?></span>
</div>
<span class="status-badge status-badge--<?= e($week['status_tone']) ?>"><?= e($week['status_label']) ?></span>
</div>
<div class="archive-row__meta archive-row__meta--stack">
<span><?= e((string) $week['note_entries_count']) ?> Texteinträge</span>
<span><?= e((string) $week['tracked_days']) ?> getrackte Tage</span>
<span><?= e($week['trend_label']) ?></span>
</div>
<span class="archive-row__hint"><?= !empty($week['has_summary']) ? 'Öffnen' : 'Details' ?></span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php else: ?>
<div class="archive-list-header">
<div>
<p class="eyebrow">Monate</p>
<h4>Monatliche KI-Rückblicke</h4>
</div>
<span class="chart-chip"><?= e((string) count($monthlyArchive)) ?> Monate</span>
</div>
<?php if ($monthlyArchive === []): ?>
<p class="empty-state">Für diesen Zeitraum sind noch keine Monatsobjekte im Archiv vorhanden.</p>
<?php else: ?>
<div class="archive-rows archive-rows--summary">
<?php foreach ($monthlyArchive as $month): ?>
<a class="archive-row archive-row--summary archive-row--month <?= $selectedMonth !== null && $selectedMonth['summary_key'] === $month['summary_key'] ? 'active' : '' ?>" href="<?= e($archiveUrl(['month_key' => $month['summary_key'], 'date' => null, 'week' => null])) ?>">
<div class="archive-row__main archive-row__main--month">
<div class="archive-row__title-group">
<strong><?= e($month['label']) ?></strong>
<span><?= e(format_compact_date((string) $month['date_from'])) ?> bis <?= e(format_compact_date((string) $month['date_to'])) ?></span>
</div>
<span class="status-badge status-badge--<?= e($month['status_tone']) ?>"><?= e($month['status_label']) ?></span>
</div>
<div class="archive-row__meta archive-row__meta--stack">
<span><?= e($month['weekly_progress_label']) ?></span>
<span><?= e((string) $month['tracked_days']) ?> getrackte Tage</span>
</div>
<span class="archive-row__hint"><?= !empty($month['has_summary']) ? 'Öffnen' : 'Details' ?></span>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endif; ?>
</section>
<aside class="archive-detail <?= $detailOpen ? 'is-open' : '' ?>" id="archive-detail-panel" data-detail-open="<?= $detailOpen ? '1' : '0' ?>">
<div class="glass-panel archive-detail__panel">
<div class="archive-detail__top">
<div>
<p class="eyebrow">Details</p>
<?php if ($detailType === 'day'): ?>
<h3><?= e(format_compact_date($selectedEntry['date'])) ?></h3>
<?php elseif ($detailType === 'week'): ?>
<h3><?= e($selectedWeek['label']) ?></h3>
<?php elseif ($detailType === 'month'): ?>
<h3><?= e($selectedMonth['label']) ?></h3>
<?php else: ?>
<h3>Archivansicht</h3>
<?php endif; ?>
</div>
<?php if ($detailOpen): ?>
<a class="ghost-link archive-detail__close" href="<?= e($archiveUrl(['date' => null, 'week' => null, 'month_key' => null])) ?>">Schließen</a>
<?php endif; ?>
</div>
<?php if ($detailType === 'day'): ?>
<p class="hero-label"><?= e($selectedEntry['evaluation']['label']) ?> · <?= e(format_points((float) $selectedEntry['evaluation']['total'])) ?> Punkte</p>
<a class="primary-button button-link" href="/track?date=<?= e(rawurlencode($selectedEntry['date'])) ?>">Diesen Tag bearbeiten</a>
<dl class="detail-grid detail-grid--archive-day">
<div><dt>Stimmung</dt><dd><?= e((string) $selectedEntry['mood']) ?>/10</dd></div>
<div><dt>Energie</dt><dd><?= e((string) $selectedEntry['energy']) ?>/10</dd></div>
<div><dt>Stress</dt><dd><?= e((string) $selectedEntry['stress']) ?>/10</dd></div>
<?php if (!empty($settings['tracking']['pain_enabled'])): ?>
<div><dt>Schmerzen</dt><dd><?= e((string) $selectedEntry['pain']) ?>/10</dd></div>
<?php endif; ?>
<div><dt>Schlaf</dt><dd><?= e((string) $selectedEntry['sleep_hours']) ?> h</dd></div>
<div><dt>Schlafgefühl</dt><dd><?= e((string) $selectedEntry['sleep_feeling']) ?>/5</dd></div>
<div><dt>Sport</dt><dd><?= e((string) $selectedEntry['sport_minutes']) ?> min</dd></div>
<div><dt>Spaziergang</dt><dd><?= e(format_walk_value($selectedEntry)) ?></dd></div>
<div><dt>Alkohol</dt><dd><?= !empty($selectedEntry['alcohol']) ? 'ja' : 'nein' ?></dd></div>
</dl>
<div class="note-box">
<h4>Notiz</h4>
<p><?= nl2br(e($selectedEntry['note'] !== '' ? $selectedEntry['note'] : 'Keine Notiz hinterlegt.')) ?></p>
</div>
<?php elseif ($detailType === 'week'): ?>
<p class="hero-label"><?= e(format_compact_date((string) $selectedWeek['date_from'])) ?> bis <?= e(format_compact_date((string) $selectedWeek['date_to'])) ?></p>
<div class="archive-detail__status-row">
<span class="status-badge status-badge--<?= e($selectedWeek['status_tone']) ?>"><?= e($selectedWeek['status_label']) ?></span>
<span class="chart-chip"><?= e($selectedWeek['trend_label']) ?></span>
</div>
<dl class="detail-grid detail-grid--archive">
<div><dt>Texteinträge</dt><dd><?= e((string) $selectedWeek['note_entries_count']) ?></dd></div>
<div><dt>Getrackte Tage</dt><dd><?= e((string) $selectedWeek['tracked_days']) ?></dd></div>
<?php if (!empty($selectedWeek['summary'])): ?>
<div><dt>Erstellt am</dt><dd><?= e(format_compact_datetime((string) $selectedWeek['summary']['created_at'])) ?></dd></div>
<?php endif; ?>
</dl>
<div class="note-box archive-detail__status-note">
<h4>KI-Status</h4>
<p><?= e($selectedWeek['status_hint']) ?></p>
</div>
<?php if (!empty($selectedWeek['summary'])): ?>
<div class="archive-detail__actions">
<a class="ghost-link archive-action" href="<?= e($archiveUrl(['week' => $selectedWeek['summary_key'], 'date' => null, 'month_key' => null])) ?>">Öffnen</a>
<form method="post" action="/archive">
<?= csrf_field() ?>
<input type="hidden" name="form_name" value="generate_weekly_summary">
<input type="hidden" name="view" value="weeks">
<input type="hidden" name="filter_month" value="<?= e($archiveFilterMonth) ?>">
<input type="hidden" name="week_key" value="<?= e((string) $selectedWeek['summary_key']) ?>">
<button class="ghost-button" type="submit" <?= empty($aiAvailable) ? 'disabled' : '' ?>>Neu generieren</button>
</form>
</div>
<div class="note-box note-box--summary">
<h4>KI-Wochenzusammenfassung</h4>
<p><?= e((string) ($selectedWeek['summary']['text'] ?? '')) ?></p>
</div>
<?php else: ?>
<form method="post" action="/archive" class="archive-detail__single-action">
<?= csrf_field() ?>
<input type="hidden" name="form_name" value="generate_weekly_summary">
<input type="hidden" name="view" value="weeks">
<input type="hidden" name="filter_month" value="<?= e($archiveFilterMonth) ?>">
<input type="hidden" name="week_key" value="<?= e((string) $selectedWeek['summary_key']) ?>">
<button class="primary-button" type="submit" <?= !$selectedWeek['can_generate'] || empty($aiAvailable) ? 'disabled' : '' ?>>KI-Wochenzusammenfassung erzeugen</button>
</form>
<?php endif; ?>
<?php elseif ($detailType === 'month'): ?>
<p class="hero-label"><?= e(format_compact_date((string) $selectedMonth['date_from'])) ?> bis <?= e(format_compact_date((string) $selectedMonth['date_to'])) ?></p>
<div class="archive-detail__status-row">
<span class="status-badge status-badge--<?= e($selectedMonth['status_tone']) ?>"><?= e($selectedMonth['status_label']) ?></span>
<span class="chart-chip"><?= e($selectedMonth['weekly_progress_label']) ?></span>
</div>
<dl class="detail-grid detail-grid--archive">
<div><dt>KI-Wochen vorhanden</dt><dd><?= e((string) $selectedMonth['weekly_summary_count']) ?> / <?= e((string) ((int) $selectedMonth['weekly_total_count'])) ?></dd></div>
<?php if (!empty($selectedMonth['summary'])): ?>
<div><dt>Erstellt am</dt><dd><?= e(format_compact_datetime((string) $selectedMonth['summary']['created_at'])) ?></dd></div>
<?php endif; ?>
</dl>
<div class="note-box archive-detail__status-note">
<h4>Monatsstatus</h4>
<p><?= e($selectedMonth['status_hint']) ?></p>
</div>
<div class="note-box archive-detail__week-status">
<h4>Wochen in diesem Monat</h4>
<div class="archive-mini-list">
<?php foreach ($selectedMonth['weeks'] as $week): ?>
<div class="archive-mini-list__row">
<span><?= e($week['label']) ?></span>
<span class="status-badge status-badge--<?= !empty($week['has_summary']) ? 'ready' : 'blocked' ?>"><?= !empty($week['has_summary']) ? 'vorhanden' : 'fehlt' ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
<?php if (!empty($selectedMonth['summary'])): ?>
<div class="archive-detail__actions">
<a class="ghost-link archive-action" href="<?= e($archiveUrl(['month_key' => $selectedMonth['summary_key'], 'date' => null, 'week' => null])) ?>">Öffnen</a>
<form method="post" action="/archive">
<?= csrf_field() ?>
<input type="hidden" name="form_name" value="generate_monthly_summary">
<input type="hidden" name="view" value="months">
<input type="hidden" name="filter_month" value="<?= e($archiveFilterMonth) ?>">
<input type="hidden" name="month_key" value="<?= e((string) $selectedMonth['summary_key']) ?>">
<button class="ghost-button" type="submit" <?= empty($aiAvailable) ? 'disabled' : '' ?>>Neu generieren</button>
</form>
</div>
<div class="note-box note-box--summary">
<h4>KI-Monatszusammenfassung</h4>
<p><?= e((string) ($selectedMonth['summary']['text'] ?? '')) ?></p>
</div>
<?php else: ?>
<form method="post" action="/archive" class="archive-detail__single-action">
<?= csrf_field() ?>
<input type="hidden" name="form_name" value="generate_monthly_summary">
<input type="hidden" name="view" value="months">
<input type="hidden" name="filter_month" value="<?= e($archiveFilterMonth) ?>">
<input type="hidden" name="month_key" value="<?= e((string) $selectedMonth['summary_key']) ?>">
<button class="primary-button" type="submit" <?= !$selectedMonth['can_generate'] || empty($aiAvailable) ? 'disabled' : '' ?>>KI-Monatszusammenfassung erzeugen</button>
</form>
<?php endif; ?>
<?php else: ?>
<p class="helper-text">Wähle links einen Tag, eine Woche oder einen Monat aus.</p>
<?php endif; ?>
</div>
</aside>
</div>
</article>
</section>