From 069fca704e0525310fc52493949f61546dea56d7 Mon Sep 17 00:00:00 2001 From: SIMAILA Djalim Date: Thu, 26 Jan 2023 19:13:39 +0100 Subject: [PATCH] categories --- Controllers/CategoryController.php | 55 +++++++++++++++++++++++++++--- Models/ParticularityModel.php | 24 +++++++++++++ README.md | 2 +- Views/category/view.php | 9 ++--- Views/common/category_list.php | 10 +++--- 5 files changed, 82 insertions(+), 18 deletions(-) diff --git a/Controllers/CategoryController.php b/Controllers/CategoryController.php index a6af7d7..eff76e8 100644 --- a/Controllers/CategoryController.php +++ b/Controllers/CategoryController.php @@ -5,13 +5,58 @@ final class CategoryController public function defaultAction(Array $A_urlParams = null, Array $A_postParams = null) { - $A_recipes = RecipeModel::getRandomRecipes(3); + $A_vegeta = ParticularityModel::getByName("végétarien")->getRecipes(); + $A_vegan = ParticularityModel::getByName("végan")->getRecipes(); + $A_gluten = ParticularityModel::getByName("sans gluten")->getRecipes(); + $A_lactose = ParticularityModel::getByName("sans lactose")->getRecipes(); - // TODO actually fill out by particularity instead $A_array_categories = array( - "Végan" => $A_recipes, - "Sans gluten" => $A_recipes, - "Sans lactose" => $A_recipes + "Végan" => $A_vegan, + "Végétarien" => $A_vegeta, + "Sans gluten" => $A_gluten, + "Sans lactose" => $A_lactose + ); + + View::show("category/view", $A_array_categories); + } + + public function lactoseLessAction(Array $A_urlParams = null, Array $A_postParams = null) + { + $A_lactose = ParticularityModel::getByName("sans lactose")->getRecipes(); + + $A_array_categories = array( + "Sans lactose" => $A_lactose + ); + + View::show("category/view", $A_array_categories); + } + public function glutenLessAction(Array $A_urlParams = null, Array $A_postParams = null) + { + $A_gluten = ParticularityModel::getByName("sans gluten")->getRecipes(); + + $A_array_categories = array( + "Sans gluten" => $A_gluten + ); + + View::show("category/view", $A_array_categories); + } + public function veganAction(Array $A_urlParams = null, Array $A_postParams = null) + { + $A_vegan = ParticularityModel::getByName("végan")->getRecipes(); + + $A_array_categories = array( + "Végan" => $A_vegan + ); + + View::show("category/view", $A_array_categories); + } + + public function vegetarianAction(Array $A_urlParams = null, Array $A_postParams = null) + { + $A_vegeta = ParticularityModel::getByName("végétarien")->getRecipes(); + + $A_array_categories = array( + "Végétarien" => $A_vegeta ); View::show("category/view", $A_array_categories); diff --git a/Models/ParticularityModel.php b/Models/ParticularityModel.php index a94e07c..acc1e00 100644 --- a/Models/ParticularityModel.php +++ b/Models/ParticularityModel.php @@ -36,6 +36,30 @@ final class ParticularityModel $stmt->execute(); } + public static function getByName($S_name){ + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT * FROM PARTICULARITY WHERE NAME=:name"); + $stmt->bindParam("name", $S_name); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return null; + + $O_part = new ParticularityModel($row["NAME"],null); + $O_part->I_PARTICULARITY_ID = $row["ID"]; + return $O_part; + } + public function getRecipes(){ + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT RECIPE_ID FROM RECIPE_PARTICULARITY WHERE PARTICULARITY_ID=:id"); + $stmt->bindParam("id", $this->I_PARTICULARITY_ID); + $stmt->execute(); + $A_recipes = array(); + foreach($stmt->fetchAll() as $row){ + array_push($A_recipes, RecipeModel::getByID($row["RECIPE_ID"])); + } + return $A_recipes; + } public function delete(){ $O_model = Model::get(); diff --git a/README.md b/README.md index 2f05f20..b858db7 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,4 @@ Découverte d'un MVC pas à pas avec PHP 2 - Routage simple et Exceptions 3 - Modèles et connexion BDD (coming soon...) - + \ No newline at end of file diff --git a/Views/category/view.php b/Views/category/view.php index b8ca07f..c2e079b 100644 --- a/Views/category/view.php +++ b/Views/category/view.php @@ -1,12 +1,9 @@ "type_de_cuisson", - "Temps de préparation" => "temps_de_preparation", - "Difficulté" => "difficulte", "Végan" => "vegan", - "Sans gluten" => "sans_gluten", - "Sans lactose" => "sans_lactose" -); + "Végétarien" => "vegetarian", + "Sans gluten" => "glutenLess", + "Sans lactose" => "lactoseLess"); ?>
diff --git a/Views/common/category_list.php b/Views/common/category_list.php index dcbf492..a181a91 100644 --- a/Views/common/category_list.php +++ b/Views/common/category_list.php @@ -1,11 +1,9 @@ "type_de_cuisson", - "Temps de préparation" => "temps_de_preparation", - "Difficulté" => "difficulte", "Végan" => "vegan", - "Sans gluten" => "sans_gluten", - "Sans lactose" => "sans_lactose"); + "Végetarien" => "vegetarian", + "Sans gluten" => "glutenLess", + "Sans lactose" => "lactoseLess"); ?>