From 2847231376ffa77c5bcbcab08b2cb9a7b9e768e9 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Fri, 27 Dec 2024 02:06:32 +0100 Subject: [PATCH] Added: favicon, Dashboard, Habits list, some styles, dashboard redirect --- TODO.md | 9 ++++- app/controllers/DashboardController.php | 16 ++++++++ app/controllers/HabitController.php | 9 ++--- app/models/Habit.php | 14 +++++++ app/views/auth/signin.php | 3 +- app/views/auth/signup.php | 3 +- app/views/dashboard/index.php | 45 +++++++++++++++++++++- app/views/habits/create.php | 49 +++++++++++++++++------- app/views/habits/index.php | 35 +++++++++++++++++ app/views/layouts/base.php | 1 + public/css/dashboard.css | 22 +++++++++++ public/css/{login.css => form.css} | 19 +++++---- public/css/global.css | 30 ++++++++++----- public/css/habits_create.css | 21 ++++++++++ public/css/habits_dashboard.css | 26 +++++++++++++ public/img/favicon.ico | Bin 0 -> 4286 bytes public/index.php | 9 +++-- 17 files changed, 266 insertions(+), 45 deletions(-) create mode 100644 app/controllers/DashboardController.php create mode 100644 app/views/habits/index.php create mode 100644 public/css/dashboard.css rename public/css/{login.css => form.css} (81%) create mode 100644 public/css/habits_create.css create mode 100644 public/css/habits_dashboard.css create mode 100644 public/img/favicon.ico diff --git a/TODO.md b/TODO.md index a9b6648..42b1da9 100644 --- a/TODO.md +++ b/TODO.md @@ -6,6 +6,13 @@ - [ ] edit user data - change password, mail... ## Core of the app -- [ ] Habits list +- [ ] header and navbar +- [ ] dashboard + - [x] css + - [ ] its just plain + - [ ] graphs +- [x] Habits list + - [ ] css - [ ] Habits create + - [ ] validate cron input - [ ] Habits track diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php new file mode 100644 index 0000000..647d6d5 --- /dev/null +++ b/app/controllers/DashboardController.php @@ -0,0 +1,16 @@ +getHabitsByUser($_SESSION['user']['id']); + + $this->view('dashboard/index', [ + 'title' => 'Dashboard', + 'habits' => $habits, + ]); + } + + public function reroute(){ + $this->redirect('/dashboard'); + } +} diff --git a/app/controllers/HabitController.php b/app/controllers/HabitController.php index 9f7f6ce..9221113 100644 --- a/app/controllers/HabitController.php +++ b/app/controllers/HabitController.php @@ -2,7 +2,9 @@ class HabitController extends Controller { public function index() { - // Display the list of habits (to be implemented later) + $habit = new Habit(); + $habits = $habit->getHabitsByUser($_SESSION['user']['id']); + $this->view('habits/index', ['title' => 'Habits', 'habits' => $habits]); } public function create() { @@ -17,15 +19,12 @@ class HabitController extends Controller { } if ($frequency === 'Custom') { - var_dump($_POST); $daysOfWeek = $_POST['days_of_week'] ?? []; $daysOfMonth = $_POST['days_of_month'] ?? '*'; $months = $_POST['months'] ?? '*'; // Combine into crontab-like string $customFrequency = implode(',', $daysOfWeek) . " $daysOfMonth $months"; - var_dump($customFrequency); - } $habit = new Habit(); @@ -38,7 +37,7 @@ class HabitController extends Controller { ]); if ($result) { - //$this->redirect('/habits'); + $this->redirect('/habits'); } else { $this->view('habits/create', ['error' => 'Failed to create habit.']); } diff --git a/app/models/Habit.php b/app/models/Habit.php index 26d0df5..f7078b8 100644 --- a/app/models/Habit.php +++ b/app/models/Habit.php @@ -29,4 +29,18 @@ class Habit { return false; } } + + public function getHabitsByUser($userId) { + $stmt = $this->db->prepare("SELECT id, title, frequency, custom_frequency, reward_points, created_at FROM habits WHERE user_id = ?"); + $stmt->bind_param("i", $userId); + $stmt->execute(); + $result = $stmt->get_result(); + + $habits = []; + while ($row = $result->fetch_assoc()) { + $habits[] = $row; + } + + return $habits; + } } diff --git a/app/views/auth/signin.php b/app/views/auth/signin.php index d624326..7d9dbdd 100644 --- a/app/views/auth/signin.php +++ b/app/views/auth/signin.php @@ -1,5 +1,6 @@ -
+ +