début des vocabs

php
Anthony RICHARD 1 year ago
parent 59bd40aea2
commit 4dfa84006f

@ -18,7 +18,7 @@ abstract class AbsGateway
} }
public abstract function add(array $parameters): int; 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 findAll(): array;
public abstract function findById(int $id); public abstract function findById(int $id);
} }

@ -0,0 +1,85 @@
<?php
namespace gateway;
use Exception;
use model\Translation;
use PDO;
use PDOException;
class TranslationGateway extends AbsGateway
{
public function addWord(string $word): void {
try {
$query = "INSERT INTO Vocabulary VALUES (:word) ON DUPLICATE KEY UPDATE word=:word";
$args = array(':word' => 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());
}
}
}

@ -31,6 +31,10 @@ class VocabularyListGateway extends AbsGateway
public function remove(int $id): void public function remove(int $id): void
{ {
try{ 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 "; $query = "DELETE FROM VocabularyList v WHERE v.id=:id ";
$args = array(':id'=>array($id,PDO::PARAM_INT)); $args = array(':id'=>array($id,PDO::PARAM_INT));
$this->con->ExecuteQuery($query,$args); $this->con->ExecuteQuery($query,$args);
@ -107,4 +111,19 @@ class VocabularyListGateway extends AbsGateway
throw new Exception('problème pour modifier les vocabulaires'); 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());
}
}
} }

@ -0,0 +1,37 @@
<?php
namespace model;
class Translation
{
private string $word1;
private string $word2;
private int $listVocab;
/**
* @param string $word1
* @param string $word2
* @param int $listVocab
*/
public function __construct(string $word1, string $word2, int $listVocab)
{
$this->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;
}
}

@ -91,11 +91,6 @@ class User
return $this->roles; 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;
}
} }

@ -4,26 +4,28 @@ namespace model;
class VocabularyList class VocabularyList
{ {
private int $id;
private String $name; private String $name;
private String $image; private String $image;
private int $id;
private ?int $aut; private ?int $aut;
private array $vocabList;
/** /**
* @param int $id
* @param String $name * @param String $name
* @param String $image * @param String $image
* @param int $id
* @param int|null $aut * @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->name = $name;
$this->image = $image; $this->image = $image;
$this->id = $id;
$this->aut = $aut; $this->aut = $aut;
$this->vocabList = $vocabList; }
public function getId(): int
{
return $this->id;
} }
public function getName(): string public function getName(): string
@ -36,23 +38,8 @@ class VocabularyList
return $this->image; return $this->image;
} }
public function getId(): int
{
return $this->id;
}
public function getAut(): ?int public function getAut(): ?int
{ {
return $this->aut; return $this->aut;
} }
public function getVocabList(): array
{
return $this->vocabList;
}
public function __toString(): string
{
return "Vocabulaire :" . $this->id . $this->name . $this->image . $this->aut;
}
} }
Loading…
Cancel
Save