add recipe note

This commit is contained in:
Thomas Rubini 2023-01-25 16:42:30 +01:00
parent 438738dde4
commit f08f6ab102
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
2 changed files with 18 additions and 1 deletions

View File

@ -99,6 +99,22 @@ final class RecipeModel
return $row["IMG"];
}
public function queryNote(){
$O_model = Model::get();
$stmt = $O_model->prepare("
SELECT avg(NOTE) AS AVG FROM APPRECIATION
WHERE RECIPE_ID = :id
");
$stmt->bindParam("id", $this->I_ID);
$stmt->execute();
$row = $stmt->fetch();
if ($row === false) return null;
$avg = $row["AVG"];
return round($avg*2)/2;
}
public function getAuthor(){
if($this->O_AUTHOR === null){
$this->O_AUTHOR = UserModel::getByID($this->I_AUTHOR_ID);
@ -133,6 +149,7 @@ final class RecipeModel
$this->getDifficulty();
$this->getIngredients();
}
public static function getFullRecipeById($I_id)
{
$O_recipe = self::getRecipeByID($I_id);

View File

@ -5,6 +5,6 @@ $O_recipe = $A_view["RECIPE"];
<img src="<?= $O_recipe->getImageLink() ?>" alt="<?= $O_recipe->S_NAME ?>">
<section>
<h2> <?= $O_recipe->S_NAME ?> </h2>
<p> <?= $O_recipe->I_NOTE ?> </p>
<p> <?= $O_recipe->queryNote() ?> </p>
</section>
</a>