From ac78ec31fd6e7f012e9c6aac61bd445fb7968119 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:57:21 +0100 Subject: [PATCH] make final version of structure send to recipe view --- Controllers/RecipeController.php | 2 ++ Models/ApprModel.php | 20 ++++++++++++++++ Models/RecipeModel.php | 2 +- Views/appreciations/appreciation.php | 4 ++-- Views/appreciations/view.php | 5 ++-- Views/recipe/view.php | 34 ++++------------------------ 6 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index 00118e7..9fea79c 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -15,6 +15,8 @@ final class RecipeController return View::show("errors/404"); } + $A_returnArray["ADMIN"] = Session::is_admin(); + View::show("recipe/view", $A_returnArray); // print_r($A_urlParams); diff --git a/Models/ApprModel.php b/Models/ApprModel.php index b7e6d14..e716e52 100644 --- a/Models/ApprModel.php +++ b/Models/ApprModel.php @@ -2,6 +2,26 @@ final class ApprModel { + public function searchRecipeApprsWithAuthors($I_recipe_id) + { + $O_model = Model::get(); + $stmt = $O_model->prepare(" + SELECT APPRECIATION.*, USER.USERNAME as AUTHOR_NAME FROM APPRECIATION + JOIN USER ON USER.ID = APPRECIATION.AUTHOR_ID + WHERE RECIPE_ID = :recipe_id + "); + $stmt->bindParam("recipe_id", $I_recipe_id); + $stmt->execute(); + + $rows = $stmt->fetchAll(); + + foreach($rows as &$row) { + $row["AUTHOR_IMG_LINK"] = "/static/img/user.jpg"; + } + + return $rows; + } + public function searchRecipeApprs($I_recipe_id) { $O_model = Model::get(); diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index e26ed8c..1bc0641 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -40,7 +40,7 @@ final class RecipeModel $O_apprModel = new ApprModel(); - $A_recipe["APPRS"] = $O_apprModel->searchRecipeApprs($I_id); + $A_recipe["APPRS"] = $O_apprModel->searchRecipeApprsWithAuthors($I_id); return $A_recipe; } diff --git a/Views/appreciations/appreciation.php b/Views/appreciations/appreciation.php index f0d18b1..04ec6b7 100644 --- a/Views/appreciations/appreciation.php +++ b/Views/appreciations/appreciation.php @@ -1,7 +1,7 @@
- " alt="profile picture"> -

+ " alt="profile picture"> +

diff --git a/Views/appreciations/view.php b/Views/appreciations/view.php index c06ea5b..a31a5ad 100644 --- a/Views/appreciations/view.php +++ b/Views/appreciations/view.php @@ -16,8 +16,9 @@
diff --git a/Views/recipe/view.php b/Views/recipe/view.php index 62d305b..99bcce2 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -35,37 +35,13 @@

By

"test", - "PROFILE_IMG" => "/static/img/users/1.jpg", - "COMMENT" => "j'me présente, je m'appelle henry", - "NOTE" => "2", - "DATE" => DATE("2020-07-08") - ), - array( - "NAME" => "test", - "PROFILE_IMG" => "/static/img/users/1.jpg", - "COMMENT" => "j'me présente, je m'appelle henry", - "NOTE" => "2", - "DATE" => DATE("2020-07-08") - ), - array( - "NAME" => "test", - "PROFILE_IMG" => "/static/img/users/1.jpg", - "COMMENT" => "j'me présente, je m'appelle henry", - "NOTE" => "2", - "DATE" => DATE("2020-07-08") - ), - array( - "NAME" => "AAAA", - "PROFILE_IMG" => "/static/img/users/1.jpg", - "COMMENT" => "j'me présente, je m'appelle henry", - "NOTE" => "2", - "DATE" => DATE("2020-07-08") - ), + "APPRS" => $A_view["APPRS"], + "ADMIN" => $A_view["ADMIN"] + ) ); - View::show("appreciations/view", $appreciations)//need to be linked with recipe? ?>