From 1140dcf06483d74f29763d1ab3193140e1cc00e7 Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:44:41 +0100 Subject: [PATCH] add createFromRow() --- Models/RecipeModel.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index 5eaa87a..93fdd58 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -62,6 +62,12 @@ final class RecipeModel $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["DESCR"], $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) { $O_model = Model::get(); @@ -72,10 +78,7 @@ final class RecipeModel $row = $stmt->fetch(); 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"]); - - $O_recipe->I_ID = $I_id; - return $O_recipe; + return self::createFromRow($row, $I_id); } public function getImage(){