From 4026ea52452371633f3d45300a9dd8c7babe37be Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Wed, 25 Oct 2023 15:31:55 +0200 Subject: [PATCH 1/4] travail sur le vocabulaire et sa gateway --- Project/php/model/Teacher.php | 1 - Project/php/model/Vocabulary.php | 53 ++++++++++--------------- Project/php/model/VocabularyGateway.php | 35 +++++++++++++++- 3 files changed, 54 insertions(+), 35 deletions(-) mode change 100644 => 100755 Project/php/model/VocabularyGateway.php diff --git a/Project/php/model/Teacher.php b/Project/php/model/Teacher.php index 5b5820d..3f4a494 100755 --- a/Project/php/model/Teacher.php +++ b/Project/php/model/Teacher.php @@ -1,7 +1,6 @@ "eng" - ); protected String $name; protected String $image; /** - * @param string[] $map * @param String $name * @param String $image */ - public function __construct(array $map, $name, $image) + public function __construct( $name, $image) { - $this->map = $map; $this->name = $name; $this->image = $image; } -/* - public function translateToEnglish($fr) { - return isset($this->map[$fr]) ? $this->map[$fr] : $fr; + public function __toString(): string + { + return "Vocabulaire :" . $this->name . $this->image; } - public function translateToFrench($eng) { - // Chercher la clé correspondante pour la valeur en anglais - $key = array_search($eng, $this->map); + /* + public function translateToEnglish($fr) { + return isset($this->map[$fr]) ? $this->map[$fr] : $fr; + } - // Si la traduction est trouvée, retourner la clé (en français) - return $key !== false ? $key : $eng; - } + public function translateToFrench($eng) { + // Chercher la clé correspondante pour la valeur en anglais + $key = array_search($eng, $this->map); + + // Si la traduction est trouvée, retourner la clé (en français) + return $key !== false ? $key : $eng; + } + + public function addTranslation($fr, $eng) { + $this->map[$fr] = $eng; + } + */ - public function addTranslation($fr, $eng) { - $this->map[$fr] = $eng; - } -*/ - /** - * @return string[] - */ - public function getMap() - { - return $this->map; - } /** * @return String @@ -64,13 +58,6 @@ class Vocabulary return $this->image; } - /** - * @param string[] $map - */ - public function setMap($map) - { - $this->map = $map; - } /** * @param String $nom diff --git a/Project/php/model/VocabularyGateway.php b/Project/php/model/VocabularyGateway.php old mode 100644 new mode 100755 index 5d56341..f224de1 --- a/Project/php/model/VocabularyGateway.php +++ b/Project/php/model/VocabularyGateway.php @@ -1,8 +1,41 @@ con = $con; + } + + + public function findByName(String $name){ + try{ + + $query = "SELECT * FROM Vocabulary 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']); + } + Return $tab_vocab; + } + + catch(PDOException $e ){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + } + + } + + +} + + -} \ No newline at end of file From 9f92881e3f28b5de7d447809a1e4817b461d18a9 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Tue, 31 Oct 2023 18:53:31 +0100 Subject: [PATCH 2/4] modification sur le vocabulaire et sa gateway --- Project/php/model/Vocabulary.php | 34 +++++++++++- Project/php/model/VocabularyGateway.php | 72 +++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 7 deletions(-) diff --git a/Project/php/model/Vocabulary.php b/Project/php/model/Vocabulary.php index a7c00bf..b8e3dc8 100755 --- a/Project/php/model/Vocabulary.php +++ b/Project/php/model/Vocabulary.php @@ -6,20 +6,27 @@ class Vocabulary { protected String $name; protected String $image; + protected int $id; + protected int $aut; /** * @param String $name * @param String $image + * @param int $id + * @param int $aut */ - public function __construct( $name, $image) + public function __construct( int $id,string $name, string $image, int $aut) { $this->name = $name; $this->image = $image; + $this->id = $id; + $this->aut = $aut; } + public function __toString(): string { - return "Vocabulaire :" . $this->name . $this->image; + return "Vocabulaire :" . $this->id . $this->name . $this->image . $this->aut; } /* @@ -58,6 +65,18 @@ class Vocabulary return $this->image; } + public function getId(): int + { + return $this->id; + } + + public function getAut(): int + { + return $this->aut; + } + + + /** * @param String $nom @@ -75,6 +94,17 @@ class Vocabulary $this->image = $image; } + public function setId(int $id): void + { + $this->id = $id; + } + + public function setAut(int $aut): void + { + $this->aut = $aut; + } + + } /* diff --git a/Project/php/model/VocabularyGateway.php b/Project/php/model/VocabularyGateway.php index f224de1..143cea9 100755 --- a/Project/php/model/VocabularyGateway.php +++ b/Project/php/model/VocabularyGateway.php @@ -1,9 +1,8 @@ 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']); + $tab_vocab[]=new Vocabulary($r['id'],$r['name'],$r['image'],$r['creator']); } Return $tab_vocab; } @@ -34,8 +33,71 @@ class VocabularyGateway } + public function addVocab(int $id, String $name, String $img, int $aut):void{ + try{ + $query = "INSERT INTO Vocabulary values(:id,:name,:img,:aut)"; + $args = array(':id'=>array($id,PDO::PARAM_INT), + ':name'=>array($name,PDO::PARAM_STR), + ':img'=>array($img,PDO::PARAM_STR), + ':aut'=>array($aut,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + + public function delVocabById(int $id):void{ + try{ + $query = "DELETE FROM Vocabulary v WHERE v.id=:id "; + $args = array(':id'=>array($id,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + + public function ModifVocabById(int $id, String $name,String $img,String $aut):void{ + try{ + $query = "UPDATE Vocabulary SET name=:name, image=:img, creator=:aut WHERE id=:id"; + $args = array(':id'=>array($id,PDO::PARAM_INT), + ':name'=>array($name,PDO::PARAM_STR), + ':img'=>array($img,PDO::PARAM_STR), + ':aut'=>array($aut,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + } +$con = new Connection('mysql:host=localhost;dbname=project','root',''); +$g = new VocabularyGateway($con); +print_r($g->findByName('gogo')); +echo "
avant
"; + +$g->addVocab(3,"gogo","img",2); +$g->addVocab(4,"gogo","img",2); +echo"apres
"; +print_r($g->findByName('gogo')); + +echo"
suppression normalement
"; + +$g->delVocabById(3); +print_r($g->findByName('gogo')); +echo "
modifié normalement
"; +$g->ModifVocabById(4,"changer","new_img",4); +print_r($g->findByName('gogo')); +print_r($g->findByName('changer')); \ No newline at end of file From 80929a6cd15a4eff10f61ebe2edb54a34cb81539 Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Tue, 31 Oct 2023 19:43:41 +0100 Subject: [PATCH 3/4] =?UTF-8?q?mise=20en=20commentaire=20des=20tests=20(fa?= =?UTF-8?q?is=20avec=20ma=20base=20de=20donn=C3=A9es,=20donc=20ne=20peut?= =?UTF-8?q?=20pas=20fonctionner=20pour=20tous=20le=20monde)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/model/VocabularyGateway.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Project/php/model/VocabularyGateway.php b/Project/php/model/VocabularyGateway.php index 143cea9..9c9a294 100755 --- a/Project/php/model/VocabularyGateway.php +++ b/Project/php/model/VocabularyGateway.php @@ -80,6 +80,7 @@ class VocabularyGateway } +/* $con = new Connection('mysql:host=localhost;dbname=project','root',''); $g = new VocabularyGateway($con); print_r($g->findByName('gogo')); @@ -100,4 +101,5 @@ echo "
modifié normalement
"; $g->ModifVocabById(4,"changer","new_img",4); print_r($g->findByName('gogo')); -print_r($g->findByName('changer')); \ No newline at end of file +print_r($g->findByName('changer')); +*/ \ No newline at end of file From 62de5a4c3a7aa02387510f9fb601acef51b9d8fc Mon Sep 17 00:00:00 2001 From: "patrick.brugiere" Date: Wed, 1 Nov 2023 13:54:38 +0100 Subject: [PATCH 4/4] =?UTF-8?q?travail=20sur=20la=20gateway=20de=20vocabul?= =?UTF-8?q?aire=20pour=20la=20finir=20et=20r=C3=A9alisation=20de=20la=20ga?= =?UTF-8?q?teway=20de=20group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/php/model/Group.php | 29 +++++- Project/php/model/GroupGateway.php | 112 ++++++++++++++++++++++++ Project/php/model/Vocabulary.php | 8 +- Project/php/model/VocabularyGateway.php | 37 ++++++-- 4 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 Project/php/model/GroupGateway.php diff --git a/Project/php/model/Group.php b/Project/php/model/Group.php index eacb6ed..9136987 100755 --- a/Project/php/model/Group.php +++ b/Project/php/model/Group.php @@ -5,10 +5,10 @@ use function Sodium\add; class Group { - private int $id; - private int $num; - private int $year; - private string $sector; + protected int $id; + protected int $num; + protected int $year; + protected string $sector; /** * @param int $id @@ -55,4 +55,25 @@ class Group { return $this->sector; } + + public function setId(int $id): void + { + $this->id = $id; + } + + public function setNum(int $num): void + { + $this->num = $num; + } + + public function setYear(int $year): void + { + $this->year = $year; + } + + public function setSector(string $sector): void + { + $this->sector = $sector; + } + } \ No newline at end of file diff --git a/Project/php/model/GroupGateway.php b/Project/php/model/GroupGateway.php new file mode 100644 index 0000000..b320dd9 --- /dev/null +++ b/Project/php/model/GroupGateway.php @@ -0,0 +1,112 @@ +con = $con; + } + + public function findAllGroup(){ + try{ + + $query = "SELECT * FROM Group_"; + $this->con->ExecuteQuery($query); + + $res = $this->con->getResults(); + $tab_group=[]; + foreach($res as $r){ + $tab_group[]=new Group($r['id'],$r['num'],$r['year'],$r['sector']); + } + Return $tab_group; + } + + catch(PDOException $e ){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + } + + } + public function findByNum(String $num){ + try{ + + $query = "SELECT * FROM Group_ g WHERE g.num = :num"; + $args = array(':num'=>array($num,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + + $res = $this->con->getResults(); + $tab_group=[]; + foreach($res as $r){ + $tab_group[]=new Group($r['id'],$r['num'],$r['year'],$r['sector']); + } + Return $tab_group; + } + + catch(PDOException $e ){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + } + + } + + public function addGroup(int $id, int $num, int $year,string $sector):void{ + try{ + $query = "INSERT INTO Group_ values(:id,:num,:year,:sec)"; + $args = array(':id'=>array($id,PDO::PARAM_INT), + ':num'=>array($num,PDO::PARAM_INT), + ':year'=>array($year,PDO::PARAM_INT), + ':sec'=>array($sector,PDO::PARAM_STR)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + + public function delGroupById(int $id):void{ + try{ + $query = "DELETE FROM Group_ g WHERE g.id=:id "; + $args = array(':id'=>array($id,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + + public function ModifGroupbById(int $id, int $num, int $year ,String $sector):void{ + try{ + $query = "UPDATE Group_ SET num=:num, year=:year, sector=:sector WHERE id=:id"; + $args = array(':id'=>array($id,PDO::PARAM_INT), + ':num'=>array($num,PDO::PARAM_INT), + ':year'=>array($year,PDO::PARAM_INT), + ':sector'=>array($sector,PDO::PARAM_STR)); + $this->con->ExecuteQuery($query,$args); + } + catch (\PDOException $e){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + + } + + } + +} +/* +$con = new Connection('mysql:host=localhost;dbname=project','root',''); +$g = new GroupGateway($con); +var_dump($g->findAllGroup()); +var_dump($g->findByNum(1)); +var_dump($g->addGroup(2,2,2,"b")); +var_dump($g->addGroup(1,1,1,"a")); +var_dump($g->findAllGroup()); +var_dump($g->delGroupById(1)); +var_dump($g->findAllGroup()); +var_dump($g->ModifGroupbById(2,3,3,"c")); +*/ \ No newline at end of file diff --git a/Project/php/model/Vocabulary.php b/Project/php/model/Vocabulary.php index b8e3dc8..0f11c36 100755 --- a/Project/php/model/Vocabulary.php +++ b/Project/php/model/Vocabulary.php @@ -7,15 +7,15 @@ class Vocabulary protected String $name; protected String $image; protected int $id; - protected int $aut; + protected int|null $aut; /** * @param String $name * @param String $image * @param int $id - * @param int $aut + * @param int|null $aut */ - public function __construct( int $id,string $name, string $image, int $aut) + public function __construct(int $id,string $name, string $image, ?int $aut= null) { $this->name = $name; $this->image = $image; @@ -24,6 +24,8 @@ class Vocabulary } + + public function __toString(): string { return "Vocabulaire :" . $this->id . $this->name . $this->image . $this->aut; diff --git a/Project/php/model/VocabularyGateway.php b/Project/php/model/VocabularyGateway.php index 9c9a294..ce392f6 100755 --- a/Project/php/model/VocabularyGateway.php +++ b/Project/php/model/VocabularyGateway.php @@ -4,13 +4,33 @@ use config\Connection; require_once('../config/Connection.php'); require_once('Vocabulary.php'); use PDO; -class VocabularyGateway +class VocabularyGateway { private Connection $con; public function __construct(Connection $con){ $this->con = $con; } + public function findAllVoc(){ + try{ + + $query = "SELECT * FROM Vocabulary"; + $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']); + } + Return $tab_vocab; + } + + catch(PDOException $e ){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + } + + } + public function findByName(String $name){ try{ @@ -33,7 +53,7 @@ class VocabularyGateway } - public function addVocab(int $id, String $name, String $img, int $aut):void{ + public function addVocab(int $id, String $name, String $img, ?int $aut):void{ try{ $query = "INSERT INTO Vocabulary values(:id,:name,:img,:aut)"; $args = array(':id'=>array($id,PDO::PARAM_INT), @@ -83,23 +103,24 @@ class VocabularyGateway /* $con = new Connection('mysql:host=localhost;dbname=project','root',''); $g = new VocabularyGateway($con); -print_r($g->findByName('gogo')); +var_dump($g->findByName('gogo')); echo "
avant
"; $g->addVocab(3,"gogo","img",2); $g->addVocab(4,"gogo","img",2); +$g->addVocab(5,"troto","img",2); echo"apres
"; -print_r($g->findByName('gogo')); +var_dump($g->findAllVoc()); +//print_r($g->findByName('gogo')); echo"
suppression normalement
"; $g->delVocabById(3); -print_r($g->findByName('gogo')); +var_dump($g->findByName('gogo')); echo "
modifié normalement
"; $g->ModifVocabById(4,"changer","new_img",4); - -print_r($g->findByName('gogo')); -print_r($g->findByName('changer')); +var_dump($g->findByName('gogo')); +var_dump($g->findByName('changer')); */ \ No newline at end of file