From f6a6ebb40f386a8f9f5903f01612eb673e6bab2b Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:12:02 +0100 Subject: [PATCH 1/3] fix missing quote --- Views/recipe/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Views/recipe/view.php b/Views/recipe/view.php index f247b58..bed85d1 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -1,7 +1,7 @@ -
Image d'illustration de la recette From 85a7ba34f359cdcaf09fe78963e686f7fff6b290 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:19:00 +0100 Subject: [PATCH 2/3] add buttons ot edit and delete in recipe view --- Views/recipe/view.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Views/recipe/view.php b/Views/recipe/view.php index bed85d1..03f8cf3 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -44,6 +44,11 @@ $O_recipe = $A_view["RECIPE"]; } ?> +
+ Modifier la recette + Supprimer la recette +
+ From 2898ca3345863db8376678ab60aec412d54be4d8 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Thu, 26 Jan 2023 16:19:11 +0100 Subject: [PATCH 3/3] add recipe/delete action --- Controllers/RecipeController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index 96a0049..df03f86 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -99,6 +99,21 @@ final class RecipeController header("Location: /recipe/view/".$O_recipe->I_ID); } + public function deleteAction(Array $A_urlParams = null, Array $A_postParams = null) + { + Session::login_or_die(); + + $O_recipe = RecipeModel::getByID(Utils::intOrDie(Utils::getOrDie($A_postParams, "recipe_id"))); + + if ($O_recipe->I_AUTHOR_ID !== $_SESSION["ID"]) { + if(!Session::is_admin()){ + throw new HTTPSpecialCaseException(400, "You are not the owner of this recipe"); + } + } + + $O_recipe->delete(); + } + public function searchAction(Array $A_urlParams = null, Array $A_postParams = null, Array $A_getParams = null) { if (isset($A_getParams["query"])) {