Add weekly progress and validation

This commit is contained in:
2026-07-10 16:23:50 +02:00
parent 23416ee382
commit 1cdef43a87
6 changed files with 39 additions and 11 deletions
+9 -1
View File
@@ -1,4 +1,4 @@
<?php
<?php
class Category
{
@@ -8,4 +8,12 @@ class Category
->query('SELECT id, name, color FROM categories ORDER BY name')
->fetchAll();
}
public static function exists(int $id): bool
{
$statement = Database::connection()->prepare('SELECT id FROM categories WHERE id = :id LIMIT 1');
$statement->execute(['id' => $id]);
return (bool) $statement->fetch();
}
}
+6 -2
View File
@@ -1,4 +1,4 @@
<?php
<?php
class Habit
{
@@ -19,7 +19,11 @@ class Habit
}
$sql = 'SELECT h.*, c.name AS category_name, c.color AS category_color,
CASE WHEN hl.id IS NULL THEN 0 ELSE 1 END AS done_today
CASE WHEN hl.id IS NULL THEN 0 ELSE 1 END AS done_today,
(SELECT COUNT(*)
FROM habit_logs hwl
WHERE hwl.habit_id = h.id
AND YEARWEEK(hwl.completed_on, 1) = YEARWEEK(CURRENT_DATE, 1)) AS completed_this_week
FROM habits h
LEFT JOIN categories c ON c.id = h.category_id
LEFT JOIN habit_logs hl