Loading index.php +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ try{ // Si ça ne correspond à aucune page, on renvoie vers la page d'erreur // (pour l'instant on a pas d'autre page, donc on retourne forcément une erreur) switch($_GET['action']){ case 'test': require 'test/tests.php'; break; default: throw new Exception("la page demandée n'a pas été trouvée"); } Loading src/model/ingredientManager.php +36 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,16 @@ require_once 'src/model/ingredient.php'; */ class IngredientManager extends Manager{ private function ingredientFromLigne(array $ligne): Ingredient{ $id = $ligne['ING_ID']; $intitule = $ligne['ING_INTITULE']; $description = $ligne['ING_DESCRIPTION']; if(is_null($description)){ $description = ''; } return new Ingredient($intitule, $id, $description); } /** * Renvoie un ingredient en fonction de son id. * Loading @@ -21,9 +31,14 @@ class IngredientManager extends Manager{ * @return ?Ingredient */ public function getIngredient(string $id): ?Ingredient{ throw new Exception('not implemented yet'); $resultat = $this->projectionBdd("select ING_ID, ING_INTITULE, ING_DESCRIPTION from CUI_INGREDIENT where ing_id = '$id'"); if(empty($resultat)){ return null; } $ligne = $resultat[0]; return $this->ingredientFromLigne($ligne); } /** * Renvoie tous les ingredients. Loading @@ -31,7 +46,12 @@ class IngredientManager extends Manager{ * @return array */ public function getIngredients(): array{ throw new Exception('not implemented yet'); $ingredients = []; $resultat = $this->projectionBdd("select ING_ID, ING_INTITULE, ING_DESCRIPTION from CUI_INGREDIENT"); foreach($resultat as $ligne){ $ingredients[] = $this->ingredientFromLigne($ligne); } return $ingredients; } /** Loading @@ -52,7 +72,13 @@ class IngredientManager extends Manager{ * @return void */ public function creerIngredient(Ingredient $ingredient): void{ throw new Exception('not implemented yet'); $requete = "insert into CUI_INGREDIENT(ING_INTITULE, ING_DESCRIPTION) values (?, NULLIF(?, ''))"; if(! $this->requetePrepare($requete, [$ingredient->getIntitule(), $ingredient->getDescription()])){ throw new Exception("échec de l'insertion du ingredient en base de données"); } } Loading @@ -63,6 +89,11 @@ class IngredientManager extends Manager{ * @return void */ public function supprimerIngredient(Ingredient $ingredient): void{ throw new Exception('not implemented yet'); $requete = "delete from CUI_INGREDIENT where ING_ID = ?"; if(! $this->requetePrepare($requete, [$ingredient->getId()])){ throw new Exception("échec de la suppression du ingredient"); } } } No newline at end of file src/model/manager.php +0 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,6 @@ abstract class Manager{ $statement = $this->bdd->query($requete); var_dump($statement); while($ligne = $statement->fetch()){ $lignes[] = $ligne; } Loading src/model/tagManager.php +36 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,16 @@ require_once 'src/model/tag.php'; */ class TagManager extends Manager{ private function tagFromLigne(array $ligne): Tag{ $id = $ligne['TAG_ID']; $intitule = $ligne['TAG_INTITULE']; $description = $ligne['TAG_DESCRIPTION']; if(is_null($description)){ $description = ''; } return new Tag($intitule, $id, $description); } /** * Renvoie un tag en fonction de son id. * Loading @@ -21,9 +31,14 @@ class TagManager extends Manager{ * @return ?Tag */ public function getTag(string $id): ?Tag{ throw new Exception('not implemented yet'); $resultat = $this->projectionBdd("select TAG_ID, TAG_INTITULE, TAG_DESCRIPTION from CUI_TAG where tag_id = '$id'"); if(empty($resultat)){ return null; } $ligne = $resultat[0]; return $this->tagFromLigne($ligne); } /** * Renvoie tous les tags. Loading @@ -31,7 +46,12 @@ class TagManager extends Manager{ * @return array */ public function getTags(): array{ throw new Exception('not implemented yet'); $tags = []; $resultat = $this->projectionBdd("select TAG_ID, TAG_INTITULE, TAG_DESCRIPTION from CUI_TAG"); foreach($resultat as $ligne){ $tags[] = $this->tagFromLigne($ligne); } return $tags; } /** Loading @@ -52,7 +72,13 @@ class TagManager extends Manager{ * @return void */ public function creerTag(Tag $tag): void{ throw new Exception('not implemented yet'); $requete = "insert into CUI_TAG(TAG_INTITULE, TAG_DESCRIPTION) values (?, NULLIF(?, ''))"; if(! $this->requetePrepare($requete, [$tag->getIntitule(), $tag->getDescription()])){ throw new Exception("échec de l'insertion du tag en base de données"); } } Loading @@ -63,6 +89,11 @@ class TagManager extends Manager{ * @return void */ public function supprimerTag(Tag $tag): void{ throw new Exception('not implemented yet'); $requete = "delete from CUI_TAG where TAG_ID = ?"; if(! $this->requetePrepare($requete, [$tag->getId()])){ throw new Exception("échec de la suppression du tag"); } } } No newline at end of file test/index.phpdeleted 100644 → 0 +0 −9 Original line number Diff line number Diff line <?php require_once '../src/lib/assertion.php'; require_once 'testEdito.php'; file_put_contents('test.txt', "test"); echo "<h2>Les tests ont passés avec succès</h2>"; No newline at end of file Loading
index.php +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ try{ // Si ça ne correspond à aucune page, on renvoie vers la page d'erreur // (pour l'instant on a pas d'autre page, donc on retourne forcément une erreur) switch($_GET['action']){ case 'test': require 'test/tests.php'; break; default: throw new Exception("la page demandée n'a pas été trouvée"); } Loading
src/model/ingredientManager.php +36 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,16 @@ require_once 'src/model/ingredient.php'; */ class IngredientManager extends Manager{ private function ingredientFromLigne(array $ligne): Ingredient{ $id = $ligne['ING_ID']; $intitule = $ligne['ING_INTITULE']; $description = $ligne['ING_DESCRIPTION']; if(is_null($description)){ $description = ''; } return new Ingredient($intitule, $id, $description); } /** * Renvoie un ingredient en fonction de son id. * Loading @@ -21,9 +31,14 @@ class IngredientManager extends Manager{ * @return ?Ingredient */ public function getIngredient(string $id): ?Ingredient{ throw new Exception('not implemented yet'); $resultat = $this->projectionBdd("select ING_ID, ING_INTITULE, ING_DESCRIPTION from CUI_INGREDIENT where ing_id = '$id'"); if(empty($resultat)){ return null; } $ligne = $resultat[0]; return $this->ingredientFromLigne($ligne); } /** * Renvoie tous les ingredients. Loading @@ -31,7 +46,12 @@ class IngredientManager extends Manager{ * @return array */ public function getIngredients(): array{ throw new Exception('not implemented yet'); $ingredients = []; $resultat = $this->projectionBdd("select ING_ID, ING_INTITULE, ING_DESCRIPTION from CUI_INGREDIENT"); foreach($resultat as $ligne){ $ingredients[] = $this->ingredientFromLigne($ligne); } return $ingredients; } /** Loading @@ -52,7 +72,13 @@ class IngredientManager extends Manager{ * @return void */ public function creerIngredient(Ingredient $ingredient): void{ throw new Exception('not implemented yet'); $requete = "insert into CUI_INGREDIENT(ING_INTITULE, ING_DESCRIPTION) values (?, NULLIF(?, ''))"; if(! $this->requetePrepare($requete, [$ingredient->getIntitule(), $ingredient->getDescription()])){ throw new Exception("échec de l'insertion du ingredient en base de données"); } } Loading @@ -63,6 +89,11 @@ class IngredientManager extends Manager{ * @return void */ public function supprimerIngredient(Ingredient $ingredient): void{ throw new Exception('not implemented yet'); $requete = "delete from CUI_INGREDIENT where ING_ID = ?"; if(! $this->requetePrepare($requete, [$ingredient->getId()])){ throw new Exception("échec de la suppression du ingredient"); } } } No newline at end of file
src/model/manager.php +0 −2 Original line number Diff line number Diff line Loading @@ -34,8 +34,6 @@ abstract class Manager{ $statement = $this->bdd->query($requete); var_dump($statement); while($ligne = $statement->fetch()){ $lignes[] = $ligne; } Loading
src/model/tagManager.php +36 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,16 @@ require_once 'src/model/tag.php'; */ class TagManager extends Manager{ private function tagFromLigne(array $ligne): Tag{ $id = $ligne['TAG_ID']; $intitule = $ligne['TAG_INTITULE']; $description = $ligne['TAG_DESCRIPTION']; if(is_null($description)){ $description = ''; } return new Tag($intitule, $id, $description); } /** * Renvoie un tag en fonction de son id. * Loading @@ -21,9 +31,14 @@ class TagManager extends Manager{ * @return ?Tag */ public function getTag(string $id): ?Tag{ throw new Exception('not implemented yet'); $resultat = $this->projectionBdd("select TAG_ID, TAG_INTITULE, TAG_DESCRIPTION from CUI_TAG where tag_id = '$id'"); if(empty($resultat)){ return null; } $ligne = $resultat[0]; return $this->tagFromLigne($ligne); } /** * Renvoie tous les tags. Loading @@ -31,7 +46,12 @@ class TagManager extends Manager{ * @return array */ public function getTags(): array{ throw new Exception('not implemented yet'); $tags = []; $resultat = $this->projectionBdd("select TAG_ID, TAG_INTITULE, TAG_DESCRIPTION from CUI_TAG"); foreach($resultat as $ligne){ $tags[] = $this->tagFromLigne($ligne); } return $tags; } /** Loading @@ -52,7 +72,13 @@ class TagManager extends Manager{ * @return void */ public function creerTag(Tag $tag): void{ throw new Exception('not implemented yet'); $requete = "insert into CUI_TAG(TAG_INTITULE, TAG_DESCRIPTION) values (?, NULLIF(?, ''))"; if(! $this->requetePrepare($requete, [$tag->getIntitule(), $tag->getDescription()])){ throw new Exception("échec de l'insertion du tag en base de données"); } } Loading @@ -63,6 +89,11 @@ class TagManager extends Manager{ * @return void */ public function supprimerTag(Tag $tag): void{ throw new Exception('not implemented yet'); $requete = "delete from CUI_TAG where TAG_ID = ?"; if(! $this->requetePrepare($requete, [$tag->getId()])){ throw new Exception("échec de la suppression du tag"); } } } No newline at end of file
test/index.phpdeleted 100644 → 0 +0 −9 Original line number Diff line number Diff line <?php require_once '../src/lib/assertion.php'; require_once 'testEdito.php'; file_put_contents('test.txt', "test"); echo "<h2>Les tests ont passés avec succès</h2>"; No newline at end of file