Merge pull request #85 from ThomasRubini/fix

This commit is contained in:
Thomas Rubini 2023-01-25 15:59:06 +01:00 committed by GitHub
commit d356a4d816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 27 deletions

View File

@ -10,14 +10,15 @@ final class RecipeController
} }
//TODO MAKE THE VIEW USE THE NEW DATA FORMAT //TODO MAKE THE VIEW USE THE NEW DATA FORMAT
$A_returnArray = RecipeModel::getFullRecipeWithApprs($A_urlParams[0]); $O_recipe = RecipeModel::getFullRecipeWithApprs($A_urlParams[0]);
if ($A_returnArray === null) { if ($O_recipe === null) {
throw new HTTPSpecialCaseException(404); throw new HTTPSpecialCaseException(404);
} }
$A_returnArray["ADMIN"] = Session::is_admin(); View::show("recipe/view", array(
"ADMIN" => Session::is_admin(),
View::show("recipe/view", $A_returnArray); "RECIPE" => $O_recipe
));
} }
public function editAction(Array $A_urlParams = null, Array $A_postParams = null) public function editAction(Array $A_urlParams = null, Array $A_postParams = null)

View File

@ -6,7 +6,7 @@ final class RecipeModel
public $S_NAME = null; public $S_NAME = null;
public $I_TIME = null; public $I_TIME = null;
public $I_COST = null; public $I_COST = null;
public $S_DESCR = null; public $S_DESC = null;
public $S_RECIPE = null; public $S_RECIPE = null;
public $I_DIFFICULTY_ID = null; public $I_DIFFICULTY_ID = null;
public $I_AUTHOR_ID = null; public $I_AUTHOR_ID = null;
@ -16,12 +16,12 @@ final class RecipeModel
public $A_APPRS = null; public $A_APPRS = null;
public $A_INGREDIENTS = null; public $A_INGREDIENTS = null;
public function __construct($S_NAME, $I_TIME, $I_COST, $S_DESCR, $S_RECIPE, $I_DIFFICULTY_ID, $I_AUTHOR_ID) public function __construct($S_NAME, $I_TIME, $I_COST, $S_DESC, $S_RECIPE, $I_DIFFICULTY_ID, $I_AUTHOR_ID)
{ {
$this->S_NAME = $S_NAME; $this->S_NAME = $S_NAME;
$this->I_TIME = $I_TIME; $this->I_TIME = $I_TIME;
$this->I_COST = $I_COST; $this->I_COST = $I_COST;
$this->S_DESCR = $S_DESCR; $this->S_DESC = $S_DESC;
$this->S_RECIPE = $S_RECIPE; $this->S_RECIPE = $S_RECIPE;
$this->I_DIFFICULTY_ID = $I_DIFFICULTY_ID; $this->I_DIFFICULTY_ID = $I_DIFFICULTY_ID;
$this->I_AUTHOR_ID = $I_AUTHOR_ID; $this->I_AUTHOR_ID = $I_AUTHOR_ID;
@ -34,7 +34,7 @@ final class RecipeModel
$stmt->bindParam("name", $this->S_NAME); $stmt->bindParam("name", $this->S_NAME);
$stmt->bindParam("time", $this->I_TIME); $stmt->bindParam("time", $this->I_TIME);
$stmt->bindParam("cost", $this->I_COST); $stmt->bindParam("cost", $this->I_COST);
$stmt->bindParam("desc", $this->S_DESCR); $stmt->bindParam("desc", $this->S_DESC);
$stmt->bindParam("recipe", $this->S_RECIPE); $stmt->bindParam("recipe", $this->S_RECIPE);
$stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID); $stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID);
$stmt->bindParam("author_id", $this->I_AUTHOR_ID); $stmt->bindParam("author_id", $this->I_AUTHOR_ID);
@ -49,7 +49,7 @@ final class RecipeModel
$stmt->bindParam("name", $this->S_NAME); $stmt->bindParam("name", $this->S_NAME);
$stmt->bindParam("time", $this->I_TIME); $stmt->bindParam("time", $this->I_TIME);
$stmt->bindParam("cost", $this->I_COST); $stmt->bindParam("cost", $this->I_COST);
$stmt->bindParam("desc", $this->S_DESCR); $stmt->bindParam("desc", $this->S_DESC);
$stmt->bindParam("recipe", $this->S_RECIPE); $stmt->bindParam("recipe", $this->S_RECIPE);
$stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID); $stmt->bindParam("difficulty_id", $this->I_DIFFICULTY_ID);
$stmt->bindParam("author_id", $this->I_AUTHOR_ID); $stmt->bindParam("author_id", $this->I_AUTHOR_ID);
@ -62,6 +62,12 @@ final class RecipeModel
$stmt->execute(); $stmt->execute();
} }
private static function createFromRow($A_row, $I_ID){
$O_recipe = new RecipeModel($A_row["NAME"], $A_row["TIME"], $A_row["COST"], $A_row["DESC"], $A_row["RECIPE"], $A_row["DIFFICULTY_ID"], $A_row["AUTHOR_ID"]);
$O_recipe->I_ID = $I_ID;
return $O_recipe;
}
public static function getRecipeByID($I_id) public static function getRecipeByID($I_id)
{ {
$O_model = Model::get(); $O_model = Model::get();
@ -72,10 +78,15 @@ final class RecipeModel
$row = $stmt->fetch(); $row = $stmt->fetch();
if ($row === false) return null; if ($row === false) return null;
$O_recipe = new RecipeModel($row["NAME"], $row["TIME"], $row["COST"], $row["DESCR"], $row["RECIPE"], $row["DIFFICULTY_ID"], $row["AUTHOR_ID"]); return self::createFromRow($row, $I_id);
}
$O_recipe->I_ID = $I_id; public function getImageLink(){
return $O_recipe; return '/static/img/recipes/'.$this->I_ID;
}
public function getLink(){
return '/recipe/view/'.$this->I_ID;
} }
public function getImage(){ public function getImage(){
@ -159,9 +170,7 @@ final class RecipeModel
) )
-- get a row per occurrence and sort by occurrences number -- get a row per occurrence and sort by occurrences number
select RECIPE.ID, RECIPE.NAME, select RECIPE.*
CONCAT('/recipe/view/', RECIPE.ID) AS RECIPE_LINK,
CONCAT('/static/img/recipes/', RECIPE.ID) AS IMG_LINK,
1 AS NOTE 1 AS NOTE
from CTE from CTE
JOIN RECIPE JOIN RECIPE
@ -174,7 +183,12 @@ final class RecipeModel
$stmt->bindParam("query", $S_query); $stmt->bindParam("query", $S_query);
$stmt->execute(); $stmt->execute();
$A_recipes = array();
foreach($stmt->fetchAll() as $row){
array_push($A_recipes, self::createFromRow($row, $row["ID"]));
}
return $stmt->fetchAll(); return $A_recipes;
} }
} }

View File

@ -1,23 +1,26 @@
<?php
$O_recipe = $A_view["RECIPE"];
?>
<main> <main>
<?php View::show("common/category_list") ?> <?php View::show("common/category_list") ?>
<article> <article>
<img src="<?= $A_view["IMG_LINK"] ?>" alt="Image d'illustration de la recette"> <img src="<?= $O_recipe->getImageLink() ?>" alt="Image d'illustration de la recette">
<section class="infosRecette"> <section class="infosRecette">
<header> <header>
<h1><?= $A_view["NAME"] ?></h1> <h1><?= $O_recipe->S_NAME ?></h1>
<p><?= $A_view["TIME"] ?>&nbsp;—&nbsp;<?= $A_view["DIFFICULTY_NAME"] ?></p> <p><?= $O_recipe->I_TIME ?>&nbsp;—&nbsp;<?= $O_recipe->O_DIFFICULTY->S_NAME ?></p>
</header> </header>
<p><?= $A_view["DESC"] ?></p> <p><?= $O_recipe->S_DESC ?></p>
</section> </section>
<section class="ingredientsRecette"> <section class="ingredientsRecette">
<h2>Ingrédients</h2> <h2>Ingrédients</h2>
<ul> <ul>
<?php <?php
foreach($A_view["INGREDIENTS"] as $ingredient) foreach($O_recipe->getIngredients() as $O_ingredient){
echo "<li> {$ingredient["NAME"]}: {$ingredient["QUANTITY"]} </li>"; echo "<li> $O_ingredient->S_NAME: $O_ingredient->I_QUANTITY </li>";
}
?> ?>
</ul> </ul>
</section> </section>
@ -26,13 +29,13 @@
<h2>Préparation</h2> <h2>Préparation</h2>
<ol> <ol>
<?php <?php
foreach(explode("\n", $A_view["RECIPE"]) as $instructions) foreach(explode("\n", $O_recipe->S_RECIPE) as $S_instr)
echo "<li>".$instructions."</li>"; echo "<li>".$S_instr."</li>";
?> ?>
</ol> </ol>
</section> </section>
<p>By <?= $A_view["AUTHOR_USERNAME"] ?></p> <p>By <?= $O_recipe->getAuthor()->S_USERNAME ?></p>
<?php <?php
View::show("appreciations/view_all", $A_view) View::show("appreciations/view_all", $A_view)