diff --git a/Models/DifficultyModel.php b/Models/DifficultyModel.php index 874c235..5b6293f 100644 --- a/Models/DifficultyModel.php +++ b/Models/DifficultyModel.php @@ -3,12 +3,16 @@ final class DifficultyModel { - public function getByID($I_difficuly_id) + public function getByID($I_id) { - if ($I_difficuly_id == 1) { - return "Facile"; - } else { - return null; - } + + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT * FROM DIFFICULTY WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return null; + return $row["NAME"]; } } diff --git a/Models/IngredientModel.php b/Models/IngredientModel.php index b1d11b3..1f28d9a 100644 --- a/Models/IngredientModel.php +++ b/Models/IngredientModel.php @@ -5,17 +5,15 @@ final class IngredientModel public function searchByRecipe($I_recipe_id) { - return array( - array( - "id" => 1, - "name" => "oeuf", - "quantity" => "6", - ), - array( - "id" => 2, - "name" => "lait", - "quantity" => "1/2L", - ), - ); + $O_model = Model::get(); + $stmt = $O_model->prepare(" + SELECT * FROM INGREDIENT + JOIN RECIPE_INGREDIENT ON RECIPE_INGREDIENT.INGREDIENT_ID=INGREDIENT.ID + WHERE RECIPE_INGREDIENT.RECIPE_ID = :recipe_id + "); + $stmt->bindParam("recipe_id", $I_recipe_id); + $stmt->execute(); + + return $stmt->fetchAll(); } } diff --git a/Models/UserModel.php b/Models/UserModel.php index 4add48a..4919f55 100644 --- a/Models/UserModel.php +++ b/Models/UserModel.php @@ -5,10 +5,13 @@ final class UserModel public function getNameByID($I_id) { - if ($I_id == 1) { - return "Thomas"; - } else { - return null; - } + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT NAME FROM USER WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return null; + return $row["NAME"]; } } diff --git a/Views/recipe/view.php b/Views/recipe/view.php index ec33823..3f49e0e 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -5,6 +5,6 @@ {$i['name']}: {$i['quantity']}

"; + echo "

{$i['NAME']}: {$i['QUANTITY']}

"; } ?> \ No newline at end of file