From a561e00fe589fc40a75eda34a6cf62412c803aec Mon Sep 17 00:00:00 2001 From: Antoine Jourdain Date: Sat, 11 Nov 2023 17:38:08 +0100 Subject: [PATCH] Correspondance avec la nouvelle conception de la BD pour liste de vocabulaire --- ...yGateway.php => VocabularyListGateway.php} | 31 ++++++++++++------- .../{Vocabulary.php => VocabularyList.php} | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) rename Project/php/gateway/{VocabularyGateway.php => VocabularyListGateway.php} (69%) rename Project/php/model/{Vocabulary.php => VocabularyList.php} (99%) diff --git a/Project/php/gateway/VocabularyGateway.php b/Project/php/gateway/VocabularyListGateway.php similarity index 69% rename from Project/php/gateway/VocabularyGateway.php rename to Project/php/gateway/VocabularyListGateway.php index b0ed969..6bfcd5c 100755 --- a/Project/php/gateway/VocabularyGateway.php +++ b/Project/php/gateway/VocabularyListGateway.php @@ -4,9 +4,9 @@ namespace gateway; use PDO; use PDOException; use Exception; -use model\Vocabulary; +use model\VocabularyList; -class VocabularyGateway extends AbsGateway +class VocabularyListGateway extends AbsGateway { public function __construct(){ parent::__construct(); @@ -15,7 +15,7 @@ class VocabularyGateway extends AbsGateway public function add(array $parameters): int // require 4 elements { try{ - $query = "INSERT INTO Vocabulary values(:id,:name,:img,:aut)"; + $query = "INSERT INTO VocabularyList VALUES(:id,:name,:img,:aut)"; $args = array(':id'=>array($parameters[0],PDO::PARAM_INT), ':name'=>array($parameters[1],PDO::PARAM_STR), ':img'=>array($parameters[2],PDO::PARAM_STR), @@ -31,7 +31,7 @@ class VocabularyGateway extends AbsGateway public function remove(int $id): void { try{ - $query = "DELETE FROM Vocabulary v WHERE v.id=:id "; + $query = "DELETE FROM VocabularyList v WHERE v.id=:id "; $args = array(':id'=>array($id,PDO::PARAM_INT)); $this->con->ExecuteQuery($query,$args); } @@ -44,13 +44,13 @@ class VocabularyGateway extends AbsGateway { try{ - $query = "SELECT * FROM Vocabulary"; + $query = "SELECT * FROM VocabularyList"; $this->con->ExecuteQuery($query); $res = $this->con->getResults(); $tab_vocab=[]; foreach($res as $r){ - $tab_vocab[]=new Vocabulary($r['id'],$r['name'],$r['image'],$r['creator']); + $tab_vocab[]=new VocabularyList($r['id'],$r['name'],$r['image'],$r['userID']); } Return $tab_vocab; } @@ -61,20 +61,29 @@ class VocabularyGateway extends AbsGateway public function findById(int $id) { - // TODO: Implement findById() method. + try{ + $query = "SELECT * FROM VocabularyList WHERE id = :id"; + $args = array(':id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + + return $this->con->getResults(); + } + catch (PDOException $e){ + throw new Exception($e->getMessage()); + } } public function findByName(String $name): array { try{ - $query = "SELECT * FROM Vocabulary v WHERE v.name = :name"; + $query = "SELECT * FROM VocabularyList v WHERE v.name = :name"; $args = array(':name'=>array($name,PDO::PARAM_STR)); $this->con->ExecuteQuery($query,$args); $res = $this->con->getResults(); $tab_vocab=[]; foreach($res as $r){ - $tab_vocab[]=new Vocabulary($r['id'],$r['name'],$r['image'],$r['creator']); + $tab_vocab[]=new VocabularyList($r['id'],$r['name'],$r['image'],$r['userID']); } Return $tab_vocab; } @@ -85,9 +94,9 @@ class VocabularyGateway extends AbsGateway } - public function ModifVocabById(int $id, String $name,String $img,String $aut):void{ + public function ModifVocabListById(int $id, String $name,String $img,String $aut):void{ try{ - $query = "UPDATE Vocabulary SET name=:name, image=:img, creator=:aut WHERE id=:id"; + $query = "UPDATE VocabularyList SET name=:name, image=:img, userID=:aut WHERE id=:id"; $args = array(':id'=>array($id,PDO::PARAM_INT), ':name'=>array($name,PDO::PARAM_STR), ':img'=>array($img,PDO::PARAM_STR), diff --git a/Project/php/model/Vocabulary.php b/Project/php/model/VocabularyList.php similarity index 99% rename from Project/php/model/Vocabulary.php rename to Project/php/model/VocabularyList.php index 353aa68..4c1ae50 100755 --- a/Project/php/model/Vocabulary.php +++ b/Project/php/model/VocabularyList.php @@ -2,7 +2,7 @@ namespace model; -class Vocabulary +class VocabularyList { protected String $name; protected String $image;