Show reminders on dashboard
This commit is contained in:
@@ -6,15 +6,23 @@ class HabitController
|
||||
{
|
||||
require_login();
|
||||
|
||||
$userId = (int) current_user_id();
|
||||
|
||||
$filters = [
|
||||
'category_id' => $_GET['category_id'] ?? '',
|
||||
'status' => $_GET['status'] ?? '',
|
||||
];
|
||||
|
||||
$remindersByHabit = [];
|
||||
foreach (Reminder::allForUser($userId) as $reminder) {
|
||||
$remindersByHabit[(int) $reminder['habit_id']][] = $reminder;
|
||||
}
|
||||
|
||||
View::render('habits/dashboard', [
|
||||
'habits' => Habit::allForUser(current_user_id(), $filters),
|
||||
'habits' => Habit::allForUser($userId, $filters),
|
||||
'categories' => Category::all(),
|
||||
'filters' => $filters,
|
||||
'remindersByHabit' => $remindersByHabit,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
<?php
|
||||
|
||||
$weekdayLabels = [
|
||||
1 => 'Montag',
|
||||
2 => 'Dienstag',
|
||||
3 => 'Mittwoch',
|
||||
4 => 'Donnerstag',
|
||||
5 => 'Freitag',
|
||||
6 => 'Samstag',
|
||||
7 => 'Sonntag',
|
||||
];
|
||||
?>
|
||||
|
||||
<section class="dashboard-head">
|
||||
<div>
|
||||
<p class="eyebrow">Heute</p>
|
||||
@@ -35,6 +48,7 @@
|
||||
|
||||
<section class="habit-list">
|
||||
<?php foreach ($habits as $habit): ?>
|
||||
<?php $habitReminders = $remindersByHabit[(int) $habit['id']] ?? []; ?>
|
||||
<article class="habit-card <?= $habit['done_today'] ? 'done' : '' ?>">
|
||||
<div class="habit-main">
|
||||
<span class="category-dot" style="background-color: <?= e($habit['category_color'] ?? '#9ca3af') ?>"></span>
|
||||
@@ -61,6 +75,46 @@
|
||||
<button class="danger" type="submit">Loeschen</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<section class="habit-reminders" aria-labelledby="reminders-<?= (int) $habit['id'] ?>">
|
||||
<div class="reminder-heading">
|
||||
<h3 id="reminders-<?= (int) $habit['id'] ?>">Erinnerungen</h3>
|
||||
<a href="index.php?route=reminders/create&habit_id=<?= (int) $habit['id'] ?>">Erinnerung hinzufuegen</a>
|
||||
</div>
|
||||
|
||||
<?php if (empty($habitReminders)): ?>
|
||||
<p class="reminder-empty">Noch keine Erinnerung eingerichtet.</p>
|
||||
<?php else: ?>
|
||||
<ul class="reminder-list">
|
||||
<?php foreach ($habitReminders as $reminder): ?>
|
||||
<?php
|
||||
$weekday = $reminder['weekday'] === null
|
||||
? 'Taeglich'
|
||||
: ($weekdayLabels[(int) $reminder['weekday']] ?? 'Unbekannt');
|
||||
$isActive = (int) $reminder['is_active'] === 1;
|
||||
?>
|
||||
<li class="reminder-item <?= $isActive ? '' : 'paused' ?>">
|
||||
<strong class="reminder-time"><?= e(substr($reminder['reminder_time'], 0, 5)) ?></strong>
|
||||
<span><?= e($weekday) ?></span>
|
||||
<span class="reminder-status"><?= $isActive ? 'Aktiv' : 'Pausiert' ?></span>
|
||||
<div class="reminder-actions">
|
||||
<form method="post" action="index.php?route=reminders/toggle">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
|
||||
<button type="submit"><?= $isActive ? 'Pausieren' : 'Aktivieren' ?></button>
|
||||
</form>
|
||||
<a href="index.php?route=reminders/edit&id=<?= (int) $reminder['id'] ?>">Bearbeiten</a>
|
||||
<form method="post" action="index.php?route=reminders/delete" onsubmit="return confirm('Diese Erinnerung wirklich loeschen?');">
|
||||
<?= csrf_field() ?>
|
||||
<input type="hidden" name="id" value="<?= (int) $reminder['id'] ?>">
|
||||
<button class="danger" type="submit">Loeschen</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</section>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user