diff --git a/Project/php/gateway/AbsGateway.php b/Project/php/gateway/AbsGateway.php index 0b3ebfc..6c9c8f1 100755 --- a/Project/php/gateway/AbsGateway.php +++ b/Project/php/gateway/AbsGateway.php @@ -18,7 +18,7 @@ abstract class AbsGateway } public abstract function add(array $parameters): int; - public abstract function remove(int $id): void; + //public abstract function remove(int $id): void; public abstract function findAll(): array; public abstract function findById(int $id); } \ No newline at end of file diff --git a/Project/php/gateway/TranslationGateway.php b/Project/php/gateway/TranslationGateway.php new file mode 100644 index 0000000..124842e --- /dev/null +++ b/Project/php/gateway/TranslationGateway.php @@ -0,0 +1,85 @@ + array($word, PDO::PARAM_STR)); + $this->con->executeQuery($query, $args); + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } + + public function add(array $parameters): int // require 3 elements + { + try { + $this->addWord($parameters[0]); + $this->addWord($parameters[1]); + $query = "INSERT INTO Translate VALUES(:word1, :word2, :id)"; + $args = array(':word1' => array($parameters[0], PDO::PARAM_STR), + ':word2' => array($parameters[1], PDO::PARAM_STR), + ':id' => array($parameters[2], PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + return $this->con->lastInsertId(); + } + catch (PDOException $e) { + throw new Exception($e->getMessage().+$e->getLine()); + } + } + + public function remove(string $word1, string $word2, int $id): void { + try { + $query = "DELETE FROM Translate WHERE firstWord=:word1 AND secondWord=:word2 AND listVoc=:id"; + $args = array(':word1' => array($word1, PDO::PARAM_STR), + ':word2' => array($word2, PDO::PARAM_STR), + ':id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + } + catch (PDOException $e) { + throw new Exception($e->getMessage().+$e->getLine()); + } + } + + public function findAll(): array + { + try { + $query = "SELECT * FROM Translate"; + $this->con->executeQuery($query); + $results = $this->con->getResults(); + $tab = array(); + foreach ($results as $row) $tab[] = new Translation($row['firstWord'], $row['secondWord'], $row['listVoc']); + + return $tab; + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } + + public function findById(int $id) + { + try { + $query = "SELECT * FROM Translate WHERE listVoc=:id"; + $args = array(':id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + $results = $this->con->getResults(); + $tab = array(); + foreach ($results as $row) $tab[] = new Translation($row['firstWord'], $row['secondWord'], $row['listVoc']); + + return $tab; + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/Project/php/gateway/VocabularyListGateway.php b/Project/php/gateway/VocabularyListGateway.php index 6bfcd5c..ff0c037 100755 --- a/Project/php/gateway/VocabularyListGateway.php +++ b/Project/php/gateway/VocabularyListGateway.php @@ -31,6 +31,10 @@ class VocabularyListGateway extends AbsGateway public function remove(int $id): void { try{ + $query = "DELETE FROM Practice WHERE vocabID=:id"; + $args = array(':id'=>array($id,PDO::PARAM_INT)); + $this->con->ExecuteQuery($query,$args); + $query = "DELETE FROM VocabularyList v WHERE v.id=:id "; $args = array(':id'=>array($id,PDO::PARAM_INT)); $this->con->ExecuteQuery($query,$args); @@ -107,4 +111,19 @@ class VocabularyListGateway extends AbsGateway throw new Exception('problème pour modifier les vocabulaires'); } } + + public function findByGroup(int $id): array { + try { + $query = "SELECT v.* FROM VocabularyList v, Practice p WHERE v.id=p.vocabID AND p.groupID=:id"; + $args = array(':id' => array($id, PDO::PARAM_INT)); + $this->con->executeQuery($query, $args); + $results = $this->con->getResults(); + $tab = array(); + foreach ($results as $row) $tab[] = new VocabularyList($row['id'], $row['name'], $row['image'], $row['userID']); + return $tab; + } + catch (PDOException $e) { + throw new Exception($e->getMessage()); + } + } } \ No newline at end of file diff --git a/Project/php/model/Translation.php b/Project/php/model/Translation.php new file mode 100644 index 0000000..bb6af63 --- /dev/null +++ b/Project/php/model/Translation.php @@ -0,0 +1,37 @@ +word1 = $word1; + $this->word2 = $word2; + $this->listVocab = $listVocab; + } + + public function getWord1(): string + { + return $this->word1; + } + + public function getWord2(): string + { + return $this->word2; + } + + public function getListVocab(): int + { + return $this->listVocab; + } +} \ No newline at end of file diff --git a/Project/php/model/User.php b/Project/php/model/User.php index 71ac8b6..162bfe8 100755 --- a/Project/php/model/User.php +++ b/Project/php/model/User.php @@ -91,11 +91,6 @@ class User return $this->roles; } - public function __toString(): string - { - $s = "User : ".$this->id." ".$this->name." ".$this->surname." ".$this->nickname." ".$this->email; - foreach ($this->roles as $role) $s = $s." ".$role; - return $s; - } + } diff --git a/Project/php/model/VocabularyList.php b/Project/php/model/VocabularyList.php index d5d8b72..02751fd 100755 --- a/Project/php/model/VocabularyList.php +++ b/Project/php/model/VocabularyList.php @@ -4,26 +4,28 @@ namespace model; class VocabularyList { + private int $id; private String $name; private String $image; - private int $id; private ?int $aut; - private array $vocabList; /** + * @param int $id * @param String $name * @param String $image - * @param int $id * @param int|null $aut - * @param array $vocabList */ - public function __construct(string $name, string $image, int $id, ?int $aut, array $vocabList) + public function __construct(int $id, string $name, string $image, ?int $aut) { + $this->id = $id; $this->name = $name; $this->image = $image; - $this->id = $id; $this->aut = $aut; - $this->vocabList = $vocabList; + } + + public function getId(): int + { + return $this->id; } public function getName(): string @@ -36,23 +38,8 @@ class VocabularyList return $this->image; } - public function getId(): int - { - return $this->id; - } - public function getAut(): ?int { return $this->aut; } - - public function getVocabList(): array - { - return $this->vocabList; - } - - public function __toString(): string - { - return "Vocabulaire :" . $this->id . $this->name . $this->image . $this->aut; - } } \ No newline at end of file