diff --git a/Controllers/ApprController.php b/Controllers/ApprController.php new file mode 100644 index 0000000..ffc1453 --- /dev/null +++ b/Controllers/ApprController.php @@ -0,0 +1,44 @@ +createAppr($_SESSION["ID"], $I_recipe_id, $S_comment, $I_score); + + } + + public function deleteAction(Array $A_urlParams = null, Array $A_postParams = null) + { + Session::login_or_die(); + + $I_appr_id = $A_urlParams[0]; + + $O_apprModel = new ApprModel(); + $A_appr = $O_apprModel->getApprById($I_appr_id); + + if ($A_appr === null) { + echo "404"; + return; + } + + if ($A_appr["AUTHOR_ID"] !== $_SESSION["ID"]) { + Session::admin_or_die(); + } + + $O_apprModel->deleteAppr($I_appr_id); + + echo "Appreciation $I_appr_id supprimée avec succès"; + } + + +} \ No newline at end of file diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index a453f75..00118e7 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -10,7 +10,7 @@ final class RecipeController } $O_recipeModel = new RecipeModel(); - $A_returnArray = $O_recipeModel->getFullRecipeWithComments($A_urlParams[0]); + $A_returnArray = $O_recipeModel->getFullRecipeWithApprs($A_urlParams[0]); if ($A_returnArray === null) { return View::show("errors/404"); } diff --git a/Models/ApprModel.php b/Models/ApprModel.php new file mode 100644 index 0000000..d1bc917 --- /dev/null +++ b/Models/ApprModel.php @@ -0,0 +1,53 @@ +prepare("SELECT * FROM APPRECIATION WHERE ID = :recipe_id"); + $stmt->bindParam("recipe_id",$I_recipe_id); + $stmt->execute(); + return $stmt->fetch(); + } + + public function createAppr($I_user_id, $I_recipe_id, $S_Comment, $I_score) + { + $O_model = Model::get(); + $stmt = $O_model->prepare(" + INSERT INTO APPRECIATION (COMMENT,SCORE,DATE,AUTHOR_ID,RECIPE_ID) VALUES (:comment, :score, :date, :author_id, :recipe_id) + "); + $stmt->bindParam("comment",$S_Comment); + $stmt->bindParam("score",$I_score); + $_date = date("Y-m-d"); + $stmt->bindParam("date",$_date); + $stmt->bindParam("author_id",$I_user_id); + $stmt->bindParam("recipe_id",$I_recipe_id); + $stmt->execute(); + return $stmt->fetch(); + } + + public function deleteAppr($I_appr_id) + { + $O_model = Model::get(); + $stmt = $O_model->prepare("DELETE FROM APPRECIATION WHERE ID = :appr_id"); + $stmt->bindParam("appr_id", $I_appr_id); + $stmt->execute(); + } + + public function getApprByID($I_appr_id) + { + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT * FROM APPRECIATION WHERE ID = :appr_id"); + $stmt->bindParam("appr_id", $I_appr_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return null; + return $row; + } + + public function updateAppreciation($I_appr_id) + { + + } +} diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index 978fa70..0a2010b 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -15,7 +15,7 @@ final class RecipeModel return $row; } - public function getFullRecipeWithComments($I_id) + public function getFullRecipeWithApprs($I_id) { $A_recipe = self::getRecipeByID($I_id); if ($A_recipe === null)return null;