diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php index cb09912..5b22ce6 100644 --- a/Controllers/RecipeController.php +++ b/Controllers/RecipeController.php @@ -9,31 +9,14 @@ final class RecipeController echo "404"; return; } - + $O_recipeModel = new RecipeModel(); - $O_recipe = $O_recipeModel->getByID($A_urlParams[0]); - if($O_recipe === null){ + $A_returnArray = $O_recipeModel->getFullRecipeWithComments($A_urlParams[0]); + if ($A_returnArray === null) { echo "404"; return; } - $O_ingredientModel = new IngredientModel(); - $A_ingredients = $O_ingredientModel->searchByRecipe($O_recipe["id"]); - - $O_userModel = new UserModel(); - $A_authorName = $O_userModel->getNameByID($O_recipe["author_id"]); - - $O_userModel = new DifficultyModel(); - $A_difficultyName = $O_userModel->getByID($O_recipe["difficulty_id"]); - - $A_returnArray = array( - "recipe_name" => $O_recipe["name"], - "recipe_desc" => $O_recipe["desc"], - "author_name" => $A_authorName, - "recipe_ingredients" => $A_ingredients, - "difficulty_name" => $A_difficultyName, - ); - View::show("recipe/view", $A_returnArray); // print_r($A_urlParams); diff --git a/Models/RecipeModel.php b/Models/RecipeModel.php index 7f367a9..1b0ca1f 100644 --- a/Models/RecipeModel.php +++ b/Models/RecipeModel.php @@ -3,19 +3,33 @@ final class RecipeModel { - public function getByID($I_id) + public function getRecipeByID($I_id) { - if ($I_id == 36) { - return array( - "id" => 36, - "name" => "Ma recette num 36", - "desc" => "Une brève description de la recette 36", - "recipe" => "Etape 1\nEtape 2\nEtape 3", - "difficulty_id" => 1, - "author_id" => 1, - ); - } else { - return null; - } + $O_model = Model::get(); + $stmt = $O_model->prepare("SELECT * FROM RECIPE WHERE ID=:id"); + $stmt->bindParam("id", $I_id); + $stmt->execute(); + + $row = $stmt->fetch(); + if ($row === false) return null; + return $row; + } + + public function getFullRecipeWithComments($I_id) + { + $A_recipe = self::getRecipeByID($I_id); + if ($A_recipe === null)return null; + + + $O_ingredientModel = new IngredientModel(); + $A_recipe["INGREDIENTS"] = $O_ingredientModel->searchByRecipe($A_recipe["ID"]); + + $O_userModel = new UserModel(); + $A_recipe["AUTHOR_NAME"] = $O_userModel->getNameByID($A_recipe["AUTHOR_ID"]); + + $O_userModel = new DifficultyModel(); + $A_recipe["DIFFICULTY_NAME"] = $O_userModel->getByID($A_recipe["DIFFICULTY_ID"]); + + return $A_recipe; } } diff --git a/Views/recipe/view.php b/Views/recipe/view.php index 8cb32d2..ec33823 100644 --- a/Views/recipe/view.php +++ b/Views/recipe/view.php @@ -1,10 +1,10 @@ -
= $A_view["recipe_name"] ?>
-Auteur: = $A_view["author_name"] ?>
-Difficulté: = $A_view["difficulty_name"] ?>
+= $A_view["NAME"] ?>
+Auteur: = $A_view["AUTHOR_NAME"] ?>
+Difficulté: = $A_view["DIFFICULTY_NAME"] ?>
Ingrédients:
{$i['name']}: {$i['quantity']} "; } ?> \ No newline at end of file