From f91feadedfdb507931ab2683f585928c3f9da5d5 Mon Sep 17 00:00:00 2001 From: arslandevelopments Date: Wed, 19 Aug 2026 14:01:43 +0200 Subject: [PATCH] =?UTF-8?q?comments=20in=20controllers=20hinzugef=C3=BCgt?= =?UTF-8?q?=20+=20review=20+=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controllers/AuthController.php | 8 +++++++- app/Controllers/HabitController.php | 10 +++++++++- app/Controllers/ReminderController.php | 14 ++++++++++---- app/Models/Category.php | 0 app/Models/Reminder.php | 5 ++++- 5 files changed, 30 insertions(+), 7 deletions(-) mode change 100644 => 100755 app/Controllers/AuthController.php mode change 100644 => 100755 app/Controllers/HabitController.php mode change 100644 => 100755 app/Controllers/ReminderController.php mode change 100644 => 100755 app/Models/Category.php mode change 100644 => 100755 app/Models/Reminder.php diff --git a/app/Controllers/AuthController.php b/app/Controllers/AuthController.php old mode 100644 new mode 100755 index 7b11963..35f4c4a --- a/app/Controllers/AuthController.php +++ b/app/Controllers/AuthController.php @@ -2,6 +2,7 @@ class AuthController { + // Zeigt das Login-Formular public function showLogin(): void { View::render('auth/login', [ @@ -10,6 +11,7 @@ class AuthController ]); } + // Prueft die Anmeldedaten und startet die Sitzung public function login(): void { verify_csrf_token(); @@ -50,6 +52,7 @@ class AuthController redirect('dashboard'); } + // Zeigt das Registrierungsformular public function showRegister(): void { View::render('auth/register', [ @@ -58,6 +61,7 @@ class AuthController ]); } + // Legt ein neues Konto an public function register(): void { verify_csrf_token(); @@ -109,11 +113,13 @@ class AuthController redirect('login'); } + // Beendet die Sitzung public function logout(): void { verify_csrf_token(); $_SESSION = []; + if (ini_get('session.use_cookies')) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']); @@ -151,4 +157,4 @@ class AuthController return is_string($value) ? $value : ''; } -} +} \ No newline at end of file diff --git a/app/Controllers/HabitController.php b/app/Controllers/HabitController.php old mode 100644 new mode 100755 index 9b488a0..4ac4a25 --- a/app/Controllers/HabitController.php +++ b/app/Controllers/HabitController.php @@ -2,6 +2,7 @@ class HabitController { + // Zeigt das Dashboard mit allen Habits des Benutzers public function dashboard(): void { require_login(); @@ -26,6 +27,7 @@ class HabitController ]); } + // Zeigt das leere Formular zum Anlegen public function create(): void { require_login(); @@ -37,6 +39,7 @@ class HabitController ]); } + // Speichert einen neuen Habit public function store(): void { require_login(); @@ -58,6 +61,7 @@ class HabitController redirect('dashboard'); } + // Zeigt das Formular zum Bearbeiten public function edit(): void { require_login(); @@ -76,6 +80,7 @@ class HabitController ]); } + // Uebernimmt die Aenderungen eines bestehenden Habits public function update(): void { require_login(); @@ -85,6 +90,7 @@ class HabitController $data = $this->validatedData(); if (!empty($data['errors'])) { + // ID mitgeben, sonst zeigt das Formular auf keinen Datensatz mehr View::render('habits/form', [ 'habit' => array_merge($_POST, ['id' => $id]), 'categories' => Category::all(), @@ -98,6 +104,7 @@ class HabitController redirect('dashboard'); } + // Loescht einen Habit public function delete(): void { require_login(); @@ -135,6 +142,7 @@ class HabitController $errors['description'] = 'Die Beschreibung darf maximal 1000 Zeichen lang sein.'; } + // Gegen die Datenbank pruefen, damit keine erfundene ID durchkommt if ($categoryId !== '' && !Category::exists((int) $categoryId)) { $errors['category_id'] = 'Bitte waehle eine gueltige Kategorie aus.'; } @@ -151,4 +159,4 @@ class HabitController 'errors' => $errors, ]; } -} +} \ No newline at end of file diff --git a/app/Controllers/ReminderController.php b/app/Controllers/ReminderController.php old mode 100644 new mode 100755 index 2651425..a717d6f --- a/app/Controllers/ReminderController.php +++ b/app/Controllers/ReminderController.php @@ -2,6 +2,7 @@ class ReminderController { + // Zeigt das Formular zum Anlegen einer Erinnerung public function create(): void { require_login(); @@ -20,6 +21,7 @@ class ReminderController ]); } + // Speichert eine neue Erinnerung public function store(): void { require_login(); @@ -52,6 +54,7 @@ class ReminderController redirect('dashboard'); } + // Zeigt das Formular zum Bearbeiten public function edit(): void { require_login(); @@ -105,6 +108,7 @@ class ReminderController redirect('dashboard'); } + // Loescht eine Erinnerung public function delete(): void { require_login(); @@ -144,10 +148,12 @@ class ReminderController $activeValue = $this->postString('is_active'); $errors = []; - if (!preg_match('/^(?:[01]\\d|2[0-3]):[0-5]\\d$/', $time)) { + // Uhrzeit muss dem Format HH:MM zwischen 00:00 und 23:59 + if (!preg_match('/^(?:[01]\d|2[0-3]):[0-5]\d$/', $time)) { $errors['reminder_time'] = 'Bitte gib eine Uhrzeit im Format HH:MM ein.'; } + // Leerer Wochentag ist erlaubt und bedeutet taeglich if ($weekdayValue !== '' && !preg_match('/^[1-7]$/', $weekdayValue)) { $errors['weekday'] = 'Bitte waehle einen gueltigen Wochentag aus.'; } @@ -168,14 +174,14 @@ class ReminderController { $value = $_GET[$key] ?? ''; - return is_string($value) && preg_match('/^[1-9]\\d*$/', $value) ? (int) $value : 0; + return is_string($value) && preg_match('/^[1-9]\d*$/', $value) ? (int) $value : 0; } private function postId(string $key): int { $value = $_POST[$key] ?? ''; - return is_string($value) && preg_match('/^[1-9]\\d*$/', $value) ? (int) $value : 0; + return is_string($value) && preg_match('/^[1-9]\d*$/', $value) ? (int) $value : 0; } private function postString(string $key): string @@ -184,4 +190,4 @@ class ReminderController return is_string($value) ? trim($value) : ''; } -} +} \ No newline at end of file diff --git a/app/Models/Category.php b/app/Models/Category.php old mode 100644 new mode 100755 diff --git a/app/Models/Reminder.php b/app/Models/Reminder.php old mode 100644 new mode 100755 index daebd66..a35111a --- a/app/Models/Reminder.php +++ b/app/Models/Reminder.php @@ -31,6 +31,7 @@ class Reminder return $statement->fetchAll(); } + // Legt eine Erinnerung an public static function createForHabit(int $habitId, int $userId, array $data): bool { $statement = Database::connection()->prepare( @@ -50,6 +51,7 @@ class Reminder return $statement->rowCount() === 1; } + // Aktualisiert eine Erinnerung public static function update(int $id, int $userId, array $data): bool { $statement = Database::connection()->prepare( @@ -82,6 +84,7 @@ class Reminder return $statement->execute(['id' => $id, 'user_id' => $userId]); } + // Schaltet zwischen aktiv und pausiert um public static function toggle(int $id, int $userId): bool { $statement = Database::connection()->prepare( @@ -93,4 +96,4 @@ class Reminder return $statement->execute(['id' => $id, 'user_id' => $userId]); } -} +} \ No newline at end of file