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 3be2c7c..0f11c36 100755 --- a/Project/php/model/Vocabulary.php +++ b/Project/php/model/Vocabulary.php @@ -4,50 +4,53 @@ namespace model; class Vocabulary { - protected $map = array( - "fr" => "eng" - ); protected String $name; protected String $image; + protected int $id; + protected int|null $aut; /** - * @param string[] $map * @param String $name * @param String $image + * @param int $id + * @param int|null $aut */ - public function __construct(array $map, $name, $image) + public function __construct(int $id,string $name, string $image, ?int $aut= null) { - $this->map = $map; $this->name = $name; $this->image = $image; + $this->id = $id; + $this->aut = $aut; } -/* - public function translateToEnglish($fr) { - return isset($this->map[$fr]) ? $this->map[$fr] : $fr; - } - 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; - } -*/ - /** - * @return string[] - */ - public function getMap() + public function __toString(): string { - return $this->map; + return "Vocabulaire :" . $this->id . $this->name . $this->image . $this->aut; } + /* + public function translateToEnglish($fr) { + return isset($this->map[$fr]) ? $this->map[$fr] : $fr; + } + + 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; + } + */ + + + /** * @return String */ @@ -64,14 +67,19 @@ class Vocabulary return $this->image; } - /** - * @param string[] $map - */ - public function setMap($map) + public function getId(): int + { + return $this->id; + } + + public function getAut(): int { - $this->map = $map; + return $this->aut; } + + + /** * @param String $nom */ @@ -88,6 +96,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 old mode 100644 new mode 100755 index 5d56341..ce392f6 --- a/Project/php/model/VocabularyGateway.php +++ b/Project/php/model/VocabularyGateway.php @@ -1,8 +1,126 @@ 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{ + + $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'],$r['creator']); + } + Return $tab_vocab; + } + + catch(PDOException $e ){ + error_log('PDOException: ' . $e->getMessage(), 3, 'error.log'); + } + + } + + 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); +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
"; +var_dump($g->findAllVoc()); +//print_r($g->findByName('gogo')); + +echo"
suppression normalement
"; + +$g->delVocabById(3); + +var_dump($g->findByName('gogo')); -} \ No newline at end of file +echo "
modifié normalement
"; +$g->ModifVocabById(4,"changer","new_img",4); +var_dump($g->findByName('gogo')); +var_dump($g->findByName('changer')); +*/ \ No newline at end of file