commit
278e09c468
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace model;
|
||||||
|
use config\Connection;
|
||||||
|
require_once('../config/Connection.php');
|
||||||
|
require_once('Group.php');
|
||||||
|
use PDO;
|
||||||
|
class GroupGateway
|
||||||
|
{
|
||||||
|
private Connection $con;
|
||||||
|
public function __construct(Connection $con){
|
||||||
|
$this->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"));
|
||||||
|
*/
|
@ -1,8 +1,126 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace model;
|
namespace model;
|
||||||
|
use config\Connection;
|
||||||
class VocabularyGateway
|
require_once('../config/Connection.php');
|
||||||
|
require_once('Vocabulary.php');
|
||||||
|
use PDO;
|
||||||
|
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{
|
||||||
|
|
||||||
|
$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 "<br> avant <br>";
|
||||||
|
|
||||||
|
$g->addVocab(3,"gogo","img",2);
|
||||||
|
$g->addVocab(4,"gogo","img",2);
|
||||||
|
$g->addVocab(5,"troto","img",2);
|
||||||
|
echo"apres <br>";
|
||||||
|
var_dump($g->findAllVoc());
|
||||||
|
//print_r($g->findByName('gogo'));
|
||||||
|
|
||||||
|
echo" <br> suppression normalement <br>";
|
||||||
|
|
||||||
|
$g->delVocabById(3);
|
||||||
|
|
||||||
|
var_dump($g->findByName('gogo'));
|
||||||
|
|
||||||
}
|
echo "<br> modifié normalement <br>";
|
||||||
|
$g->ModifVocabById(4,"changer","new_img",4);
|
||||||
|
var_dump($g->findByName('gogo'));
|
||||||
|
var_dump($g->findByName('changer'));
|
||||||
|
*/
|
Loading…
Reference in new issue