move recipe data creation to RecipeModel and use real SQL database
This commit is contained in:
parent
788f224629
commit
87e8f9247e
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
<p> <?= $A_view["recipe_name"] ?> </p>
|
||||
<p> Auteur: <?= $A_view["author_name"] ?> </p>
|
||||
<p> Difficulté: <?= $A_view["difficulty_name"] ?> </p>
|
||||
<p> <?= $A_view["NAME"] ?> </p>
|
||||
<p> Auteur: <?= $A_view["AUTHOR_NAME"] ?> </p>
|
||||
<p> Difficulté: <?= $A_view["DIFFICULTY_NAME"] ?> </p>
|
||||
<p> Ingrédients: </p>
|
||||
<?php
|
||||
|
||||
foreach($A_view["recipe_ingredients"] as $i){
|
||||
foreach($A_view["INGREDIENTS"] as $i){
|
||||
echo "<p> {$i['name']}: {$i['quantity']} </p>";
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user