Merge pull request 'solidification' (#21) from solidification into master

Reviewed-on: WikiFantasy/WF-Website#21
pull/22/head
Kentin BRONGNIART 5 months ago
commit f41903f36f

@ -5,16 +5,9 @@ use Connection;
use PDO; use PDO;
class CharacterGateway class CharacterGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function create(int $id_character, string $name , string $img_char) : bool public function create(int $id_character, string $name , string $img_char) : bool
{ {
$query = " $query = "

@ -2,11 +2,7 @@
namespace Gateway; namespace Gateway;
use PDO; use PDO;
class CommentaryGateway { class CommentaryGateway extends Gateway{
private Connection $co ;
public function __construct(Connection $co) {
$this->co = $co;
}
public function firstIdComment():int{ public function firstIdComment():int{
$query = "Select id_comment from Commentary;"; $query = "Select id_comment from Commentary;";

@ -3,14 +3,8 @@
namespace Gateway; namespace Gateway;
use PDO; use PDO;
class FavoriteGateway class FavoriteGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function createFavoriteGateway(int $idUser, int $idQuote) : bool public function createFavoriteGateway(int $idUser, int $idQuote) : bool
{ {

@ -3,12 +3,12 @@ namespace Gateway;
use PDO; use PDO;
class AccueilGateway { class Gateway {
private Connection $con; protected Connection $co;
public function __construct(Connection $con) { public function __construct(Connection $con) {
$this->con = $con; $this->co = $con;
} }

@ -3,14 +3,8 @@
namespace Gateway; namespace Gateway;
use PDO; use PDO;
class ImageGateway class ImageGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool
{ {

@ -3,14 +3,8 @@ namespace Gateway;
use Gateway\Connection; use Gateway\Connection;
use PDO; use PDO;
class QuestionGateway class QuestionGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function create(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool public function create(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool
{ {

@ -5,14 +5,8 @@ use Gateway\Connection;
use PDO; use PDO;
class QuizGateway class QuizGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function create(int $id_quiz, int $nb_questions) : bool public function create(int $id_quiz, int $nb_questions) : bool
{ {

@ -3,14 +3,8 @@
namespace Gateway; namespace Gateway;
use PDO; use PDO;
class QuizQuestionGateway class QuizQuestionGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function createQuizQuestionGateway(int $idQuiz, int $idQuestion): bool public function createQuizQuestionGateway(int $idQuiz, int $idQuestion): bool
{ {

@ -1,19 +1,14 @@
<?php <?php
namespace Gateway; namespace Gateway;
use PDO; use PDO;
Class QuoteGateway{ Class QuoteGateway extends Gateway{
private Connection $con;
public function __construct(Connection $con){
$this->con=$con;
}
public function searchQuote(string $quote,int $numpage,string $language):array{ public function searchQuote(string $quote,int $numpage,string $language):array{
//recherche par citation //recherche par citation
$query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE content LIKE '%:quote%' AND isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE content LIKE '%:quote%' AND isValid = true AND language = :language LIMIT 20 OFFSET :page*20;";
$this->con->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); $this->co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -21,8 +16,8 @@ Class QuoteGateway{
//recherche par source //recherche par source
$query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;";
$this->con->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); $this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -30,8 +25,8 @@ Class QuoteGateway{
//recherche par personnage //recherche par personnage
$query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE c.caracter LIKE '%:pers%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;"; $query="SELECT q.id_quote, q.content, c.caracter, c.img_path, s.title, s.date, q.like, q.language FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source WHERE c.caracter LIKE '%:pers%' AND q.isValid = true AND language = :language LIMIT 20 OFFSET :page*20;";
$this->con->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR))); $this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -39,8 +34,8 @@ Class QuoteGateway{
//recherche par id //recherche par id
$query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;"; $query="SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Caracter c ON c.id_caracter = q.id_caracter JOIN Source s ON s.id_source = q.id_source JOIN Image i ON c.id_img = i.id_img WHERE q.id_quote = :id AND q.isvalide = true;";
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -66,9 +61,9 @@ Class QuoteGateway{
$query = $query . " AND " . $fil $query = $query . " AND " . $fil
}*/ }*/
$this->con->executeQuery($query,array()); $this->co->executeQuery($query,array());
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -83,8 +78,8 @@ Class QuoteGateway{
ORDER BY q.id_quote DESC ORDER BY q.id_quote DESC
LIMIT 1;"; LIMIT 1;";
try { try {
$this->con->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); $this->co->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]);
$result = $this->con->getResults(); $result = $this->co->getResults();
return $result[0] ?? []; return $result[0] ?? [];
} catch (PDOException $e) { } catch (PDOException $e) {
echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage(); echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage();
@ -93,6 +88,7 @@ Class QuoteGateway{
} }
public function getSuggestions(int $numpage, string $language): array { public function getSuggestions(int $numpage, string $language): array {
$query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue $query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue
FROM Quote q FROM Quote q
@ -103,11 +99,11 @@ Class QuoteGateway{
ORDER BY RANDOM() ORDER BY RANDOM()
LIMIT 20 OFFSET :offset;"; LIMIT 20 OFFSET :offset;";
$this->con->executeQuery($query, [ $this->co->executeQuery($query, [
':language' => [$language, PDO::PARAM_STR], ':language' => [$language, PDO::PARAM_STR],
':offset' => [$numpage * 20, PDO::PARAM_INT] ':offset' => [$numpage * 20, PDO::PARAM_INT]
]); ]);
return $this->con->getResults(); return $this->co->getResults();
} }
public function getFavorites(string $userId): array { public function getFavorites(string $userId): array {
@ -120,10 +116,10 @@ Class QuoteGateway{
WHERE f.users = :userId"; WHERE f.users = :userId";
try { try {
$this->con->executeQuery($query, [ $this->co->executeQuery($query, [
':userId' => [$userId, PDO::PARAM_STR] ':userId' => [$userId, PDO::PARAM_STR]
]); ]);
return $this->con->getResults(); return $this->co->getResults();
} catch (PDOException $e) { } catch (PDOException $e) {
echo "Erreur dans getFavorites: " . $e->getMessage(); echo "Erreur dans getFavorites: " . $e->getMessage();
return []; return [];
@ -136,21 +132,21 @@ Class QuoteGateway{
public function getQuoteIsValide():array{ public function getQuoteIsValide():array{
//obtenir les quotes en attentes de validation par l'admin //obtenir les quotes en attentes de validation par l'admin
$query = 'SELECT * FROM Quote WHERE isValid=:bool'; $query = 'SELECT * FROM Quote WHERE isValid=:bool';
$this->con->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL))); $this->co->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
public function validQuote(int $id){ public function validQuote(int $id){
//Valider la quote par l'admin //Valider la quote par l'admin
$query ='UPDATE Quote SET isValid=:newValide WHERE id_Quote=:id'; $query ='UPDATE Quote SET isValid=:newValide WHERE id_Quote=:id';
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
} }
public function invalidQuote(int $id){ public function invalidQuote(int $id){
//Invalide la quote par l'admin (suppression) //Invalide la quote par l'admin (suppression)
$query ='DELETE FROM Quote WHERE id_Quote=:id'; $query ='DELETE FROM Quote WHERE id_Quote=:id';
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
} }
public function updateContent(int $id, string $newContent):array{ public function updateContent(int $id, string $newContent):array{

@ -4,14 +4,8 @@ namespace Gateway;
use PDO; use PDO;
class ResultsGateway class ResultsGateway extends Gateway
{ {
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co ;
}
public function createResultsGateway(int $idQuiz, int $idUser, int $nbPts, int $time) : bool public function createResultsGateway(int $idQuiz, int $idUser, int $nbPts, int $time) : bool
{ {

@ -2,27 +2,21 @@
namespace Gateway; namespace Gateway;
use PDO; use PDO;
Class UserGateway{ Class UserGateway extends Gateway{
private Connection $con;
public function __construct(Connection $con){
$this->con=$con;
}
public function getNumberOfUsers() : array public function getNumberOfUsers() : array
{ {
$query = "SELECT Count(*) FROM Users"; $query = "SELECT Count(*) FROM Users";
$this -> con -> executeQuery($query); $this -> co -> executeQuery($query);
return $this -> con -> getResults(); return $this -> co -> getResults();
} }
public function firstIdUser():int{ public function firstIdUser():int{
$query = "Select id_user from Users;"; $query = "Select id_user from Users;";
$this -> con -> executeQuery($query); $this -> co -> executeQuery($query);
$res = $this -> con -> getResults(); $res = $this -> co -> getResults();
foreach($res as $r){ foreach($res as $r){
$tab[] = $r["id_user"]; $tab[] = $r["id_user"];
} }
@ -37,7 +31,7 @@ Class UserGateway{
INSERT INTO Users(id_user,username,email,password,creation,img) INSERT INTO Users(id_user,username,email,password,creation,img)
VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :imgPrfl); VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :imgPrfl);
"; ";
return $this -> con -> executeQuery($query, [ return $this -> co -> executeQuery($query, [
":id" => [$id, PDO::PARAM_INT], ":id" => [$id, PDO::PARAM_INT],
":pseudo" => [$pseudo, PDO::PARAM_STR], ":pseudo" => [$pseudo, PDO::PARAM_STR],
":email" => [$email, PDO::PARAM_STR], ":email" => [$email, PDO::PARAM_STR],
@ -51,15 +45,15 @@ Class UserGateway{
// supretion user // supretion user
$query='DELETE FROM Users WHERE id_user = :id;'; $query='DELETE FROM Users WHERE id_user = :id;';
return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); return $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
} }
public function getFavorite(string $id):array{ public function getFavorite(string $id):array{
//obtention favoris d'un user //obtention favoris d'un user
$query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote FROM Favorite f JOIN users u ON u.id_user = f.user_f WHERE u.id_user = :id);'; $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote FROM Favorite f JOIN users u ON u.id_user = f.user_f WHERE u.id_user = :id);';
$this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
$result=$this->con->getResults(); $result=$this->co->getResults();
return $result; return $result;
} }
@ -67,22 +61,22 @@ Class UserGateway{
//obtenir les information d'un user //obtenir les information d'un user
public function findDataUser(int $id):array{ public function findDataUser(int $id):array{
$query = 'SELECT * FROM Users WHERE id_user=:idUser'; $query = 'SELECT * FROM Users WHERE id_user=:idUser';
$this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR)));
$result = $this->con->getResults(); $result = $this->co->getResults();
return $result; return $result;
} }
// obtenir les informations d'un user selon son pseudo // obtenir les informations d'un user selon son pseudo
public function findUsername(string $username):array{ public function findUsername(string $username):array{
$query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users u Join Image i on i.id_img=u.img WHERE username= :username'; $query = 'SELECT u.id_user , u.username , u.email , u.password , i.imgPath , u.creation FROM Users u Join Image i on i.id_img=u.img WHERE username= :username';
$this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
return $this->con->getResults(); return $this->co->getResults();
} }
public function findEmail(string $email):array{ public function findEmail(string $email):array{
$query = 'SELECT * FROM Users WHERE email = :email'; $query = 'SELECT * FROM Users WHERE email = :email';
$this->con->executeQuery($query, array(':email'=>array($email, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':email'=>array($email, PDO::PARAM_STR)));
return $this->con->getResults(); return $this->co->getResults();
} }
// ===================== UPDATE FUNCTION ===================== // ===================== UPDATE FUNCTION =====================
@ -90,46 +84,46 @@ Class UserGateway{
public function updateUsername(int $id, string $newUsername):bool{ public function updateUsername(int $id, string $newUsername):bool{
//Update le nom du user passé en paramètre //Update le nom du user passé en paramètre
$queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser'; $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
$this->con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR))); $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
//Renvoie le nouveau nom du user //Renvoie le nouveau nom du user
$queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser'; $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';
return $this->con->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR))); return $this->co->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR)));
} }
public function updateEmail(int $id, string $newEmail):bool{ public function updateEmail(int $id, string $newEmail):bool{
//Update le email du user passé en paramètre //Update le email du user passé en paramètre
$queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser'; $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
$this->con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR))); $this->co->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
//Renvoie le nouveau email du user //Renvoie le nouveau email du user
$queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser'; $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
return $this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); return $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
} }
public function updateImg(int $id, int $newImg):array{ public function updateImg(int $id, int $newImg):array{
//Update l'image du user passé en paramètre //Update l'image du user passé en paramètre
$query = 'UPDATE Users SET img_prfl=:newImg WHERE id_user=:idUser'; $query = 'UPDATE Users SET img_prfl=:newImg WHERE id_user=:idUser';
$this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR)));
//Renvoie la nouvelle image du user //Renvoie la nouvelle image du user
$queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser'; $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser';
$this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
$result = $this->con->getResults(); $result = $this->co->getResults();
return $result; return $result;
} }
public function updatePasswd(int $id, string $newPassWd):array{ public function updatePasswd(int $id, string $newPassWd):array{
//Update le passwd du user passé en paramètre //Update le passwd du user passé en paramètre
$query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser'; $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser';
$this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
} }
public function getIdUser(string $username):array{ public function getIdUser(string $username):array{
$query = 'SELECT id_user FROM Users WHERE username=:username'; $query = 'SELECT id_user FROM Users WHERE username=:username';
$this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
$result = $this->con->getResults(); $result = $this->co->getResults();
return $result; return $result;
} }

@ -2,14 +2,7 @@
namespace Gateway; namespace Gateway;
use Connection; use Connection;
class SourceGateway { class SourceGateway extends Gateway{
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function create(sourceEntity $s) : bool public function create(sourceEntity $s) : bool
{ {

@ -3,18 +3,12 @@
namespace Model; namespace Model;
use Entity\CharacterEntity; use Entity\CharacterEntity;
use Gateway\CharacterGateway; use Gateway\CharacterGateway;
use Gateway\Gateway;
class CharacterModel class CharacterModel extends Model
{ {
private CharacterGateway $gateway;
public function __construct(characterGateway $gw)
{
$this -> gateway = $gw;
}
public function createCharacter(int $id_character, string $name , string $img_char) : bool public function createCharacter(int $id_character, string $name , string $img_char) : bool
{ {
return $this -> gateway -> create($id_character, $name, $img_char); return $this -> gateway -> create($id_character, $name, $img_char);

@ -2,22 +2,17 @@
namespace Model; namespace Model;
use Entity\CommentaryEntity; use Entity\CommentaryEntity;
use Gateway\CommentaryGateway; use Gateway\CommentaryGateway;
use Gateway\Gateway;
class CommentaryModel { class CommentaryModel extends Model {
private commentaryGateway $gw;
function __construct(commentaryGateway $gw) {
$this->gw = $gw;
}
public function createComment(string $comment, string $idQuote, string $idUser): bool { public function createComment(string $comment, string $idQuote, string $idUser): bool {
return $this->gw->create($comment, $idUser, $idQuote); return $this->gateway->create($comment, $idUser, $idQuote);
} }
public function getComment(int $id): array { public function getComment(int $id): array {
$com = []; $com = [];
$res = $this->gw->findByQuote($id); $res = $this->gateway->findByQuote($id);
foreach ($res as $comments){ foreach ($res as $comments){
$com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["datec"], $comments["username"]); $com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["datec"], $comments["username"]);
} }
@ -25,7 +20,7 @@ class CommentaryModel {
} }
public function getComments(): array { public function getComments(): array {
$res = $this->gw->findAll(); $res = $this->gateway->findAll();
foreach ($res as $comments) { foreach ($res as $comments) {
$com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["date"]); $com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["date"]);
} }
@ -33,7 +28,7 @@ class CommentaryModel {
} }
public function deleteComment(int $id_comment): bool { public function deleteComment(int $id_comment): bool {
return $this -> gw -> delete($id_comment); return $this -> gateway -> delete($id_comment);
} }
public function updateComment(int $id_comment, string $comment): bool { public function updateComment(int $id_comment, string $comment): bool {
@ -42,7 +37,7 @@ class CommentaryModel {
if($c){ if($c){
$c -> setComment($comment); $c -> setComment($comment);
return $this->gw -> update($c); return $this->gateway -> update($c);
} }
return false; return false;
} }

@ -3,24 +3,18 @@
namespace Model; namespace Model;
use Gateway\FavoriteGateway; use Gateway\FavoriteGateway;
use Entity\FavoriteEntity; use Entity\FavoriteEntity;
use Gateway\Gateway;
class FavoriteModel class FavoriteModel extends Model
{ {
private FavoriteGateway $gw;
public function __construct(FavoriteGateway $gw)
{
$this -> gw = $gw;
}
public function createFavoriteModel(int $idUser, int $idQuote) : bool public function createFavoriteModel(int $idUser, int $idQuote) : bool
{ {
return $this -> gw -> createFavoriteGateway($idUser, $idQuote); return $this -> gateway -> createFavoriteGateway($idUser, $idQuote);
} }
public function getFavoriteById(int $idUser, int $idQuote) : ?FavoriteEntity public function getFavoriteById(int $idUser, int $idQuote) : ?FavoriteEntity
{ {
$res = $this -> gw -> findFavoriteById($idUser, $idQuote); $res = $this -> gateway -> findFavoriteById($idUser, $idQuote);
if ($res) if ($res)
{ {
@ -34,7 +28,7 @@ class FavoriteModel
public function getFavoriteByUser(int $idUser) : array public function getFavoriteByUser(int $idUser) : array
{ {
$res = $this -> gw -> findFavoriteByUser($idUser); $res = $this -> gateway -> findFavoriteByUser($idUser);
$favorites = []; $favorites = [];
@ -50,7 +44,7 @@ class FavoriteModel
public function getAllFavorite() : array public function getAllFavorite() : array
{ {
$res = $this -> gw -> findAllFavorite(); $res = $this -> gateway -> findAllFavorite();
$favorites = []; $favorites = [];
@ -66,6 +60,6 @@ class FavoriteModel
public function removeFavorite(int $idUser, int $idQuote) : bool public function removeFavorite(int $idUser, int $idQuote) : bool
{ {
return $this -> gw -> deleteFavoriteGateway($idUser, $idQuote); return $this -> gateway -> deleteFavoriteGateway($idUser, $idQuote);
} }
} }

@ -4,24 +4,18 @@ namespace Model;
use Entity\ImageEntity; use Entity\ImageEntity;
use Gateway\ImageGateway; use Gateway\ImageGateway;
use Gateway\Gateway;
class ImageModel class ImageModel extends Model
{ {
private ImageGateway $gw;
public function __construct(ImageGateway $gw)
{
$this -> gw = $gw;
}
public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool
{ {
return $this -> gw -> createImgGateway($idImg, $imgPath, $isImgProfile); return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile);
} }
public function getImgById(int $idImg) : ?ImageEntity public function getImgById(int $idImg) : ?ImageEntity
{ {
$res = $this -> gw -> findImgById($idImg); $res = $this -> gateway -> findImgById($idImg);
if ($res) if ($res)
{ {
@ -36,7 +30,7 @@ class ImageModel
public function getAllImg() : array public function getAllImg() : array
{ {
$res = $this -> gw -> findAllImg(); $res = $this -> gateway -> findAllImg();
$images = []; $images = [];
@ -53,7 +47,7 @@ class ImageModel
public function getAllImgProfile() : array public function getAllImgProfile() : array
{ {
$res = $this -> gw -> findAllImgProfile(); $res = $this -> gateway -> findAllImgProfile();
$images = []; $images = [];
@ -70,11 +64,11 @@ class ImageModel
public function deleteImgModel(int $idImg) : bool public function deleteImgModel(int $idImg) : bool
{ {
return $this -> gw -> deleteImgGateway($idImg); return $this -> gateway -> deleteImgGateway($idImg);
} }
public function updateImgModel(int $idImg, string $imgPath) : bool public function updateImgModel(int $idImg, string $imgPath) : bool
{ {
return $this -> gw -> updateImgGateway($idImg, $imgPath); return $this -> gateway -> updateImgGateway($idImg, $imgPath);
} }
} }

@ -0,0 +1,14 @@
<?php
namespace Model;
use Gateway\Gateway;
class Model
{
protected Gateway $gateway;
public function __construct(Gateway $gate){
$this->gateway = $gate;
}
}
?>

@ -3,16 +3,10 @@
namespace Model; namespace Model;
use Gateway\QuestionGateway; use Gateway\QuestionGateway;
use Entity\QuestionEntity; use Entity\QuestionEntity;
use Gateway\Gateway;
class QuestionModel class QuestionModel extends Model
{ {
private QuestionGateway $gateway;
public function __construct(QuestionGateway $gw)
{
$this -> gateway = $gw;
}
public function createQuestion(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool public function createQuestion(int $id_question, string $question, string $answerA, string $answerB, string $answerC, string $answerD, string $cAnswer): bool
{ {
return $this -> gateway -> create($id_question, $question, $answerA, $answerB, $answerC, $answerD, $cAnswer); return $this -> gateway -> create($id_question, $question, $answerA, $answerB, $answerC, $answerD, $cAnswer);

@ -4,15 +4,9 @@ namespace Model;
use Entity\quizEntity; use Entity\quizEntity;
use Gateway\QuizGateway; use Gateway\QuizGateway;
use Gateway\Gateway;
class QuizModel { class QuizModel extends Model{
private QuizGateway $gateway;
public function __construct(QuizGateway $gw)
{
$this -> gateway = $gw;
}
public function createQuiz(int $id_quiz, int $nb_questions) : bool public function createQuiz(int $id_quiz, int $nb_questions) : bool
{ {

@ -9,27 +9,19 @@ use Gateway\Connection;
use Gateway\QuestionGateway; use Gateway\QuestionGateway;
use Gateway\QuizGateway; use Gateway\QuizGateway;
use Gateway\QuizQuestionGateway; use Gateway\QuizQuestionGateway;
use Gateway\Gateway;
class QuizQuestionModel class QuizQuestionModel extends Model
{ {
private QuizQuestionGateway $gw;
/**
* @param QuizGateway $gw
*/
public function __construct(QuizQuestionGateway $gw)
{
$this->gw = $gw;
}
public function createQuizQuestion(int $idQuiz, int $idQuestion): bool public function createQuizQuestion(int $idQuiz, int $idQuestion): bool
{ {
return $this->gw->create($idQuiz,$idQuestion); return $this->gateway->create($idQuiz,$idQuestion);
} }
public function findQuizQuestionByIdQuiz(int $id): ?QuizQuestionEntity public function findQuizQuestionByIdQuiz(int $id): ?QuizQuestionEntity
{ {
$q = $this ->gw->findQuizQuestionByIdQuiz($id); $q = $this ->gateway->findQuizQuestionByIdQuiz($id);
if ($q) { if ($q) {
return new QuizQuestionEntity( return new QuizQuestionEntity(
$q['idQuiz'], $q['idQuiz'],
@ -41,11 +33,11 @@ class QuizQuestionModel
public function getAllQuestionByQuiz(int $id, Connection $co): array public function getAllQuestionByQuiz(int $id, Connection $co): array
{ {
$q = $this->gw->findQuestionsFromQuiz($id); $q = $this->gateway->findQuestionsFromQuiz($id);
$questions = []; $questions = [];
$gw = new QuestionGateway($co); $gateway = new QuestionGateway($co);
$qmdl = new QuestionModel($gw); $qmdl = new QuestionModel($gateway);
foreach ($q as $question){ foreach ($q as $question){
$questions [] = $qmdl->getQuestion($question[1]); $questions [] = $qmdl->getQuestion($question[1]);
@ -56,7 +48,7 @@ class QuizQuestionModel
public function findAll(): array public function findAll(): array
{ {
$q = $this -> gw -> findAll(); $q = $this -> gateway -> findAll();
$quizzes = []; $quizzes = [];
@ -71,7 +63,7 @@ class QuizQuestionModel
public function deleteQuizQuestion(int $id): bool public function deleteQuizQuestion(int $id): bool
{ {
return $this -> gw -> delete($id); return $this -> gateway -> delete($id);
} }

@ -2,14 +2,10 @@
namespace Model; namespace Model;
use Entity\Quote; use Entity\Quote;
use Gateway\QuoteGateway; use Gateway\QuoteGateway;
use Gateway\Gateway;
class QuoteModel class QuoteModel extends Model
{ {
private QuoteGateway $gateway;
public function __construct(QuoteGateway $gate){
$this->gateway = $gate;
}
public function searchId(int $id): Quote{ public function searchId(int $id): Quote{
$res = $this->gateway->searchId($id); $res = $this->gateway->searchId($id);

@ -4,24 +4,19 @@ namespace Model;
use Entity\ResultsEntity; use Entity\ResultsEntity;
use Gateway\ResultsGateway; use Gateway\ResultsGateway;
use Gateway\Gateway;
class ResultsModel class ResultsModel extends Model
{ {
private ResultsGateway $gw;
public function __construct(ResultsGateway $gw)
{
$this -> gw = $gw;
}
public function createResultsModel(int $idQuiz, int $idUser, int $score, int $time) : bool public function createResultsModel(int $idQuiz, int $idUser, int $score, int $time) : bool
{ {
return $this -> gw -> createResultsGateway($idQuiz, $idUser, $score, $time); return $this -> gateway -> createResultsGateway($idQuiz, $idUser, $score, $time);
} }
public function getResultsByQuiz(int $idQuiz) : array public function getResultsByQuiz(int $idQuiz) : array
{ {
$res = $this -> gw -> findResultsByQuiz($idQuiz); $res = $this -> gateway -> findResultsByQuiz($idQuiz);
$results = []; $results = [];
@ -39,7 +34,7 @@ class ResultsModel
public function getResultsByUser(int $idUser) : array public function getResultsByUser(int $idUser) : array
{ {
$res = $this -> gw -> findResultsByUser($idUser); $res = $this -> gateway -> findResultsByUser($idUser);
$results = []; $results = [];
@ -57,7 +52,7 @@ class ResultsModel
public function getResultsById(int $idQuiz, int $idUser) : ?ResultsEntity public function getResultsById(int $idQuiz, int $idUser) : ?ResultsEntity
{ {
$res = $this -> gw -> findResultsById($idQuiz, $idUser); $res = $this -> gateway -> findResultsById($idQuiz, $idUser);
if ($res) if ($res)
{ {
@ -73,7 +68,7 @@ class ResultsModel
public function getAllResults() : array public function getAllResults() : array
{ {
$res = $this -> gw -> findAllResults(); $res = $this -> gateway -> findAllResults();
$results = []; $results = [];
@ -91,6 +86,6 @@ class ResultsModel
public function updateResultsModel(int $idQuiz, int $idUser, ?int $score, ?int $time) : bool public function updateResultsModel(int $idQuiz, int $idUser, ?int $score, ?int $time) : bool
{ {
return $this -> gw -> updateResults($idQuiz, $idUser, $score, $time); return $this -> gateway -> updateResults($idQuiz, $idUser, $score, $time);
} }
} }

@ -2,14 +2,10 @@
namespace Model; namespace Model;
use Entity\Quote; use Entity\Quote;
use Gateway\QuoteGateway; use Gateway\QuoteGateway;
use Gateway\Gateway;
class SearchModel class SearchModel extends Model
{ {
private QuoteGateway $gateway;
public function __construct(QuoteGateway $gate){
$this->gateway = $gate;
}
public function searchQuote(?string $type,?string $search,array $filtre): array{ public function searchQuote(?string $type,?string $search,array $filtre): array{

@ -3,14 +3,10 @@
use Entity\User; use Entity\User;
use Entity\UserEntity; use Entity\UserEntity;
use Gateway\UserGateway; use Gateway\UserGateway;
use Gateway\Gateway;
class UserModel class UserModel extends Model
{ {
private UserGateway $gateway;
public function __construct(UserGateway $gate){
$this->gateway = $gate;
}
public function insertUser(string $username,string $email,string $passwd) : bool{ public function insertUser(string $username,string $email,string $passwd) : bool{
/*global $rep,$image;*/ /*global $rep,$image;*/

@ -2,17 +2,11 @@
namespace Model; namespace Model;
use Entity\SourceEntity; use Entity\SourceEntity;
use Gateway\SourceGateway; use Gateway\SourceGateway;
use Gateway\Gateway;
class SourceModel class SourceModel extends Model
{ {
private sourceGateway $gateway;
public function __construct(SourceGateway $gateway)
{
$this -> gateway = $gateway;
}
public function createSource(int $id_source, string $title, string $date) : bool public function createSource(int $id_source, string $title, string $date) : bool
{ {
$q = new SourceEntity($id_source , $title, $date); $q = new SourceEntity($id_source , $title, $date);

Loading…
Cancel
Save