diff --git a/Controllers/HelloworldController.php b/Controllers/HelloworldController.php deleted file mode 100644 index 4215141..0000000 --- a/Controllers/HelloworldController.php +++ /dev/null @@ -1,19 +0,0 @@ - $O_helloworld->getMessage())); - - } - - public function testformAction(Array $A_urlParams = null, Array $A_postParams = null) - { - - View::show('helloworld/testform', array('formData' => $A_postParams)); - - } - -} \ No newline at end of file diff --git a/Controllers/RecipeController.php b/Controllers/RecipeController.php new file mode 100644 index 0000000..5b22ce6 --- /dev/null +++ b/Controllers/RecipeController.php @@ -0,0 +1,29 @@ +getFullRecipeWithComments($A_urlParams[0]); + if ($A_returnArray === null) { + echo "404"; + return; + } + + View::show("recipe/view", $A_returnArray); + + // print_r($A_urlParams); + // $O_recetteModel = new RecipeIngredientsModel(); + // $O_recetteModel->getByID(""); + // View::show('helloworld/testform', array('formData' => $A_postParams)); + + } + +} \ No newline at end of file diff --git a/Kernel/Model.php b/Kernel/Model.php index 5c45e3d..4ce8fb8 100644 --- a/Kernel/Model.php +++ b/Kernel/Model.php @@ -5,17 +5,17 @@ final class Model private static $conn = null; public static function get(){ - if($conn === null){ - init(); + if(self::$conn === null){ + self::init(); } - return $conn; + return self::$conn; } private static function init(){ $PDO_URI = sprintf("mysql:host=%s;dbname=%s", $_ENV["DB_HOST"], $_ENV["DB_DBNAME"]); try{ - $conn = new PDO($PDO_URI, $_ENV["DB_USER"], $_ENV["DB_PASSWORD"]); + self::$conn = new PDO($PDO_URI, $_ENV["DB_USERNAME"], $_ENV["DB_PASSWORD"]); }catch(PDOException $e){ die("Connection to the database failed"); } diff --git a/Models/DifficultyModel.php b/Models/DifficultyModel.php new file mode 100644 index 0000000..5b6293f --- /dev/null +++ b/Models/DifficultyModel.php @@ -0,0 +1,18 @@ +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/Helloworld.php b/Models/Helloworld.php deleted file mode 100644 index fbfeb5b..0000000 --- a/Models/Helloworld.php +++ /dev/null @@ -1,12 +0,0 @@ -_S_message ; - } - -} \ No newline at end of file diff --git a/Models/IngredientModel.php b/Models/IngredientModel.php new file mode 100644 index 0000000..1f28d9a --- /dev/null +++ b/Models/IngredientModel.php @@ -0,0 +1,19 @@ +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/RecipeModel.php b/Models/RecipeModel.php new file mode 100644 index 0000000..1b0ca1f --- /dev/null +++ b/Models/RecipeModel.php @@ -0,0 +1,35 @@ +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/Models/UserModel.php b/Models/UserModel.php new file mode 100644 index 0000000..4919f55 --- /dev/null +++ b/Models/UserModel.php @@ -0,0 +1,17 @@ +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/helloworld/view.php b/Views/helloworld/view.php deleted file mode 100644 index 8749713..0000000 --- a/Views/helloworld/view.php +++ /dev/null @@ -1,3 +0,0 @@ -" . $A_view['helloworld'] . "

"; diff --git a/Views/helloworld/testform.php b/Views/recipe/edit.php similarity index 100% rename from Views/helloworld/testform.php rename to Views/recipe/edit.php diff --git a/Views/recipe/view.php b/Views/recipe/view.php new file mode 100644 index 0000000..3f49e0e --- /dev/null +++ b/Views/recipe/view.php @@ -0,0 +1,10 @@ +

+

Auteur:

+

Difficulté:

+

Ingrédients:

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

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