|
|
|
@ -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),
|