Merge pull request #51 from ThomasRubini/recipe_struct

This commit is contained in:
Thomas Rubini 2023-01-23 13:34:32 +01:00 committed by GitHub
commit b239e220cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 38 deletions

View File

@ -15,6 +15,8 @@ final class RecipeController
return View::show("errors/404"); return View::show("errors/404");
} }
$A_returnArray["ADMIN"] = Session::is_admin();
View::show("recipe/view", $A_returnArray); View::show("recipe/view", $A_returnArray);
// print_r($A_urlParams); // print_r($A_urlParams);

View File

@ -1,13 +1,34 @@
<?php <?php
final class ApprModel { final class ApprModel {
public function getRecipeApprs($I_recipe_id)
public function searchRecipeApprsWithAuthors($I_recipe_id)
{ {
$O_model = Model::get(); $O_model = Model::get();
$stmt = $O_model->prepare("SELECT * FROM APPRECIATION WHERE ID = :recipe_id"); $stmt = $O_model->prepare("
$stmt->bindParam("recipe_id",$I_recipe_id); 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(); $stmt->execute();
return $stmt->fetch();
$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();
$stmt = $O_model->prepare("SELECT * FROM APPRECIATION WHERE RECIPE_ID = :recipe_id");
$stmt->bindParam("recipe_id", $I_recipe_id);
$stmt->execute();
return $stmt->fetchAll();
} }
public function createAppr($I_user_id, $I_recipe_id, $S_Comment, $I_score) public function createAppr($I_user_id, $I_recipe_id, $S_Comment, $I_score)

View File

@ -15,7 +15,7 @@ final class RecipeModel
return $row; return $row;
} }
public function getFullRecipeWithApprs($I_id) public function getFullRecipe($I_id)
{ {
$A_recipe = self::getRecipeByID($I_id); $A_recipe = self::getRecipeByID($I_id);
if ($A_recipe === null)return null; if ($A_recipe === null)return null;
@ -34,6 +34,17 @@ final class RecipeModel
return $A_recipe; return $A_recipe;
} }
public function getFullRecipeWithApprs($I_id)
{
$A_recipe = self::getFullRecipe($I_id);
$O_apprModel = new ApprModel();
$A_recipe["APPRS"] = $O_apprModel->searchRecipeApprsWithAuthors($I_id);
return $A_recipe;
}
public function searchRecipesByName($S_query) public function searchRecipesByName($S_query)
{ {

View File

@ -1,7 +1,7 @@
<section> <section>
<header> <header>
<img src="<?= $A_view["PROFILE_IMG"] ?>" alt="profile picture"> <img src="<?= $A_view["AUTHOR_IMG_LINK"] ?>" alt="profile picture">
<h3> <?= $A_view["NAME"] ?> </h3> <h3> <?= $A_view["AUTHOR_NAME"] ?> </h3>
<p> <?= $A_view["COMMENT"] ?> </p> <p> <?= $A_view["COMMENT"] ?> </p>
</header> </header>
<p> <?= $A_view["NOTE"] ?> </p> <p> <?= $A_view["NOTE"] ?> </p>

View File

@ -16,8 +16,9 @@
</form> </form>
<?php <?php
foreach ($A_view as $appreciation){ foreach ($A_view["APPRS"] as $A_appr){
View::show("appreciations/appreciation", $appreciation); $A_appr["ADMIN"] = $A_view["ADMIN"];
View::show("appreciations/appreciation", $A_appr);
} }
?> ?>
</section> </section>

View File

@ -35,37 +35,13 @@
<p>By <?= $A_view["AUTHOR_USERNAME"] ?></p> <p>By <?= $A_view["AUTHOR_USERNAME"] ?></p>
<?php <?php
$appreciations = array( View::show(
"appreciations/view",
array( array(
"NAME" => "test", "APPRS" => $A_view["APPRS"],
"PROFILE_IMG" => "/static/img/users/1.jpg", "ADMIN" => $A_view["ADMIN"]
"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")
),
); );
View::show("appreciations/view", $appreciations)//need to be linked with recipe?
?> ?>
</main> </main>