From 54e03f94fc09f3869b40fac35193687eb56a6ab7 Mon Sep 17 00:00:00 2001 From: brongniart Date: Wed, 27 Nov 2024 09:25:08 +0100 Subject: [PATCH] rajoue class abstraite global pour les models/Gateway --- src/Gateway/CharacterGateway.php | 9 +-- src/Gateway/CommentaryGateway.php | 6 +- src/Gateway/FavoriteGateway.php | 8 +-- .../{AccueilGateway.php => Gateway.php} | 6 +- src/Gateway/ImageGateway.php | 8 +-- src/Gateway/QuestionGateway.php | 8 +-- src/Gateway/QuizGateway.php | 8 +-- src/Gateway/QuizQuestionGateway.php | 8 +-- src/Gateway/QuoteGateway.php | 47 +++++++--------- src/Gateway/ResultsGateway.php | 8 +-- src/Gateway/UserGateway.php | 56 +++++++++---------- src/Gateway/sourceGateway.php | 9 +-- src/Model/CharacterModel.php | 10 +--- src/Model/CommentaryModel.php | 19 +++---- src/Model/FavoriteModel.php | 20 +++---- src/Model/ImageModel.php | 22 +++----- src/Model/Model.php | 14 +++++ src/Model/QuestionModel.php | 10 +--- src/Model/QuizModel.php | 12 +--- src/Model/QuizQuestionModel.php | 26 +++------ src/Model/QuoteModel.php | 8 +-- src/Model/ResultsModel.php | 23 +++----- src/Model/SearchModel.php | 8 +-- src/Model/UserModel.php | 8 +-- src/Model/sourceModel.php | 10 +--- vue/templates/quoteLittle.html.twig | 10 ++-- 26 files changed, 132 insertions(+), 249 deletions(-) rename src/Gateway/{AccueilGateway.php => Gateway.php} (56%) create mode 100644 src/Model/Model.php diff --git a/src/Gateway/CharacterGateway.php b/src/Gateway/CharacterGateway.php index 27f7b9d..abc941d 100644 --- a/src/Gateway/CharacterGateway.php +++ b/src/Gateway/CharacterGateway.php @@ -5,16 +5,9 @@ use Connection; 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 { $query = " diff --git a/src/Gateway/CommentaryGateway.php b/src/Gateway/CommentaryGateway.php index 110850c..0885ec1 100644 --- a/src/Gateway/CommentaryGateway.php +++ b/src/Gateway/CommentaryGateway.php @@ -2,11 +2,7 @@ namespace Gateway; use PDO; -class CommentaryGateway { - private Connection $co ; - public function __construct(Connection $co) { - $this->co = $co; - } +class CommentaryGateway extends Gateway{ public function firstIdComment():int{ $query = "Select id_comment from Commentary;"; diff --git a/src/Gateway/FavoriteGateway.php b/src/Gateway/FavoriteGateway.php index bc5156b..495eef4 100644 --- a/src/Gateway/FavoriteGateway.php +++ b/src/Gateway/FavoriteGateway.php @@ -3,14 +3,8 @@ namespace Gateway; 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 { diff --git a/src/Gateway/AccueilGateway.php b/src/Gateway/Gateway.php similarity index 56% rename from src/Gateway/AccueilGateway.php rename to src/Gateway/Gateway.php index 03e684c..7da95b7 100644 --- a/src/Gateway/AccueilGateway.php +++ b/src/Gateway/Gateway.php @@ -3,12 +3,12 @@ namespace Gateway; use PDO; -class AccueilGateway { +class Gateway { - private Connection $con; + protected Connection $co; public function __construct(Connection $con) { - $this->con = $con; + $this->co = $con; } diff --git a/src/Gateway/ImageGateway.php b/src/Gateway/ImageGateway.php index 9cd9c7b..e05609a 100644 --- a/src/Gateway/ImageGateway.php +++ b/src/Gateway/ImageGateway.php @@ -3,14 +3,8 @@ namespace Gateway; 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 { diff --git a/src/Gateway/QuestionGateway.php b/src/Gateway/QuestionGateway.php index 6b4b246..d67e175 100644 --- a/src/Gateway/QuestionGateway.php +++ b/src/Gateway/QuestionGateway.php @@ -3,14 +3,8 @@ namespace Gateway; use Gateway\Connection; 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 { diff --git a/src/Gateway/QuizGateway.php b/src/Gateway/QuizGateway.php index 05e464f..9bf4ff1 100644 --- a/src/Gateway/QuizGateway.php +++ b/src/Gateway/QuizGateway.php @@ -5,14 +5,8 @@ use Gateway\Connection; 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 { diff --git a/src/Gateway/QuizQuestionGateway.php b/src/Gateway/QuizQuestionGateway.php index ebed811..8ae776e 100644 --- a/src/Gateway/QuizQuestionGateway.php +++ b/src/Gateway/QuizQuestionGateway.php @@ -3,14 +3,8 @@ namespace Gateway; 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 { diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php index f04318a..60bac0f 100644 --- a/src/Gateway/QuoteGateway.php +++ b/src/Gateway/QuoteGateway.php @@ -1,19 +1,14 @@ con=$con; - } +Class QuoteGateway extends Gateway{ public function searchQuote(string $quote,int $numpage,string $language):array{ //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;"; - $this->con->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(); + $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->co->getResults(); return $result; } @@ -21,8 +16,8 @@ Class QuoteGateway{ //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;"; - $this->con->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(); + $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->co->getResults(); return $result; } @@ -30,8 +25,8 @@ Class QuoteGateway{ //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;"; - $this->con->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(); + $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->co->getResults(); return $result; } @@ -39,8 +34,8 @@ Class QuoteGateway{ //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;"; - $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); - $result=$this->con->getResults(); + $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); + $result=$this->co->getResults(); return $result; } @@ -66,9 +61,9 @@ Class QuoteGateway{ $query = $query . " AND " . $fil }*/ - $this->con->executeQuery($query,array()); + $this->co->executeQuery($query,array()); - $result=$this->con->getResults(); + $result=$this->co->getResults(); return $result; } @@ -81,8 +76,8 @@ Class QuoteGateway{ WHERE q.isValide = true AND q.isCitationDuJour = true AND q.langue = :language ORDER BY id_quote DESC LIMIT 1;"; try { - $this->con->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); - $result = $this->con->getResults(); + $this->co->executeQuery($query, [':language' => [$language, PDO::PARAM_STR]]); + $result = $this->co->getResults(); return $result[0] ?? []; } catch (PDOException $e) { echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage(); @@ -101,11 +96,11 @@ Class QuoteGateway{ ORDER BY RANDOM() LIMIT 20 OFFSET :offset;"; - $this->con->executeQuery($query, [ + $this->co->executeQuery($query, [ ':language' => [$language, PDO::PARAM_STR], ':offset' => [$numpage * 20, PDO::PARAM_INT] ]); - return $this->con->getResults(); + return $this->co->getResults(); } public function getFavorites(string $userId): array { @@ -118,10 +113,10 @@ Class QuoteGateway{ WHERE f.users = :userId"; try { - $this->con->executeQuery($query, [ + $this->co->executeQuery($query, [ ':userId' => [$userId, PDO::PARAM_STR] ]); - return $this->con->getResults(); + return $this->co->getResults(); } catch (PDOException $e) { echo "Erreur dans getFavorites: " . $e->getMessage(); return []; @@ -134,21 +129,21 @@ Class QuoteGateway{ public function getQuoteIsValide():array{ //obtenir les quotes en attentes de validation par l'admin $query = 'SELECT * FROM Quote WHERE isValid=:bool'; - $this->con->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL))); - $result=$this->con->getResults(); + $this->co->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL))); + $result=$this->co->getResults(); return $result; } public function validQuote(int $id){ //Valider la quote par l'admin $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){ //Invalide la quote par l'admin (suppression) $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{ diff --git a/src/Gateway/ResultsGateway.php b/src/Gateway/ResultsGateway.php index 628e14e..d800fdf 100644 --- a/src/Gateway/ResultsGateway.php +++ b/src/Gateway/ResultsGateway.php @@ -4,14 +4,8 @@ namespace Gateway; 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 { diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index 9074f22..0aab0dd 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -2,27 +2,21 @@ namespace Gateway; use PDO; -Class UserGateway{ - - private Connection $con; - - public function __construct(Connection $con){ - $this->con=$con; - } +Class UserGateway extends Gateway{ public function getNumberOfUsers() : array { $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{ $query = "Select id_user from Users;"; - $this -> con -> executeQuery($query); - $res = $this -> con -> getResults(); + $this -> co -> executeQuery($query); + $res = $this -> co -> getResults(); foreach($res as $r){ $tab[] = $r["id_user"]; } @@ -37,7 +31,7 @@ Class UserGateway{ INSERT INTO Users(id_user,username,email,password,creation,img) VALUES (:id, :pseudo, :email, :password, CURRENT_DATE, :imgPrfl); "; - return $this -> con -> executeQuery($query, [ + return $this -> co -> executeQuery($query, [ ":id" => [$id, PDO::PARAM_INT], ":pseudo" => [$pseudo, PDO::PARAM_STR], ":email" => [$email, PDO::PARAM_STR], @@ -51,15 +45,15 @@ Class UserGateway{ // supretion user $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{ //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);'; - $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); - $result=$this->con->getResults(); + $this->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); + $result=$this->co->getResults(); return $result; } @@ -67,22 +61,22 @@ Class UserGateway{ //obtenir les information d'un user public function findDataUser(int $id):array{ $query = 'SELECT * FROM Users WHERE id_user=:idUser'; - $this->con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR))); - $result = $this->con->getResults(); + $this->co->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR))); + $result = $this->co->getResults(); return $result; } // obtenir les informations d'un user selon son pseudo 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'; - $this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); - return $this->con->getResults(); + $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); + return $this->co->getResults(); } public function findEmail(string $email):array{ $query = 'SELECT * FROM Users WHERE email = :email'; - $this->con->executeQuery($query, array(':email'=>array($email, PDO::PARAM_STR))); - return $this->con->getResults(); + $this->co->executeQuery($query, array(':email'=>array($email, PDO::PARAM_STR))); + return $this->co->getResults(); } // ===================== UPDATE FUNCTION ===================== @@ -90,46 +84,46 @@ Class UserGateway{ public function updateUsername(int $id, string $newUsername):bool{ //Update le nom du user passé en paramètre $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 $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{ //Update le email du user passé en paramètre $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 $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{ //Update l'image du user passé en paramètre $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 $queryReponse = 'SELECT img_prfl FROM Users WHERE id_user=:idUser'; - $this->con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); - $result = $this->con->getResults(); + $this->co->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); + $result = $this->co->getResults(); return $result; } public function updatePasswd(int $id, string $newPassWd):array{ //Update le passwd du user passé en paramètre $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{ $query = 'SELECT id_user FROM Users WHERE username=:username'; - $this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); - $result = $this->con->getResults(); + $this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR))); + $result = $this->co->getResults(); return $result; } diff --git a/src/Gateway/sourceGateway.php b/src/Gateway/sourceGateway.php index 1b8dd08..a746ec8 100644 --- a/src/Gateway/sourceGateway.php +++ b/src/Gateway/sourceGateway.php @@ -2,14 +2,7 @@ namespace Gateway; use Connection; -class SourceGateway { - - private Connection $co; - - public function __construct(Connection $co) - { - $this -> co = $co; - } +class SourceGateway extends Gateway{ public function create(sourceEntity $s) : bool { diff --git a/src/Model/CharacterModel.php b/src/Model/CharacterModel.php index 83b12e0..53eb21c 100644 --- a/src/Model/CharacterModel.php +++ b/src/Model/CharacterModel.php @@ -3,18 +3,12 @@ namespace Model; use Entity\CharacterEntity; 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 { return $this -> gateway -> create($id_character, $name, $img_char); diff --git a/src/Model/CommentaryModel.php b/src/Model/CommentaryModel.php index cf68d3c..0e947e9 100644 --- a/src/Model/CommentaryModel.php +++ b/src/Model/CommentaryModel.php @@ -2,22 +2,17 @@ namespace Model; use Entity\CommentaryEntity; use Gateway\CommentaryGateway; +use Gateway\Gateway; -class CommentaryModel { - - private commentaryGateway $gw; - - function __construct(commentaryGateway $gw) { - $this->gw = $gw; - } +class CommentaryModel extends Model { 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 { $com = []; - $res = $this->gw->findByQuote($id); + $res = $this->gateway->findByQuote($id); foreach ($res as $comments){ $com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["datec"], $comments["username"]); } @@ -25,7 +20,7 @@ class CommentaryModel { } public function getComments(): array { - $res = $this->gw->findAll(); + $res = $this->gateway->findAll(); foreach ($res as $comments) { $com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["date"]); } @@ -33,7 +28,7 @@ class CommentaryModel { } 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 { @@ -42,7 +37,7 @@ class CommentaryModel { if($c){ $c -> setComment($comment); - return $this->gw -> update($c); + return $this->gateway -> update($c); } return false; } diff --git a/src/Model/FavoriteModel.php b/src/Model/FavoriteModel.php index 789af4f..cdf11d4 100644 --- a/src/Model/FavoriteModel.php +++ b/src/Model/FavoriteModel.php @@ -3,24 +3,18 @@ namespace Model; use Gateway\FavoriteGateway; 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 { - return $this -> gw -> createFavoriteGateway($idUser, $idQuote); + return $this -> gateway -> createFavoriteGateway($idUser, $idQuote); } public function getFavoriteById(int $idUser, int $idQuote) : ?FavoriteEntity { - $res = $this -> gw -> findFavoriteById($idUser, $idQuote); + $res = $this -> gateway -> findFavoriteById($idUser, $idQuote); if ($res) { @@ -34,7 +28,7 @@ class FavoriteModel public function getFavoriteByUser(int $idUser) : array { - $res = $this -> gw -> findFavoriteByUser($idUser); + $res = $this -> gateway -> findFavoriteByUser($idUser); $favorites = []; @@ -50,7 +44,7 @@ class FavoriteModel public function getAllFavorite() : array { - $res = $this -> gw -> findAllFavorite(); + $res = $this -> gateway -> findAllFavorite(); $favorites = []; @@ -66,6 +60,6 @@ class FavoriteModel public function removeFavorite(int $idUser, int $idQuote) : bool { - return $this -> gw -> deleteFavoriteGateway($idUser, $idQuote); + return $this -> gateway -> deleteFavoriteGateway($idUser, $idQuote); } } \ No newline at end of file diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php index 59aba54..e9ac02b 100644 --- a/src/Model/ImageModel.php +++ b/src/Model/ImageModel.php @@ -4,24 +4,18 @@ namespace Model; use Entity\ImageEntity; 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 { - return $this -> gw -> createImgGateway($idImg, $imgPath, $isImgProfile); + return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile); } public function getImgById(int $idImg) : ?ImageEntity { - $res = $this -> gw -> findImgById($idImg); + $res = $this -> gateway -> findImgById($idImg); if ($res) { @@ -36,7 +30,7 @@ class ImageModel public function getAllImg() : array { - $res = $this -> gw -> findAllImg(); + $res = $this -> gateway -> findAllImg(); $images = []; @@ -53,7 +47,7 @@ class ImageModel public function getAllImgProfile() : array { - $res = $this -> gw -> findAllImgProfile(); + $res = $this -> gateway -> findAllImgProfile(); $images = []; @@ -70,11 +64,11 @@ class ImageModel public function deleteImgModel(int $idImg) : bool { - return $this -> gw -> deleteImgGateway($idImg); + return $this -> gateway -> deleteImgGateway($idImg); } public function updateImgModel(int $idImg, string $imgPath) : bool { - return $this -> gw -> updateImgGateway($idImg, $imgPath); + return $this -> gateway -> updateImgGateway($idImg, $imgPath); } } \ No newline at end of file diff --git a/src/Model/Model.php b/src/Model/Model.php new file mode 100644 index 0000000..a0b0fd4 --- /dev/null +++ b/src/Model/Model.php @@ -0,0 +1,14 @@ +gateway = $gate; + } + } + +?> diff --git a/src/Model/QuestionModel.php b/src/Model/QuestionModel.php index c58a186..d560b18 100644 --- a/src/Model/QuestionModel.php +++ b/src/Model/QuestionModel.php @@ -3,16 +3,10 @@ namespace Model; use Gateway\QuestionGateway; 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 { return $this -> gateway -> create($id_question, $question, $answerA, $answerB, $answerC, $answerD, $cAnswer); diff --git a/src/Model/QuizModel.php b/src/Model/QuizModel.php index 155a512..c38581e 100644 --- a/src/Model/QuizModel.php +++ b/src/Model/QuizModel.php @@ -4,16 +4,10 @@ namespace Model; use Entity\quizEntity; use Gateway\QuizGateway; +use Gateway\Gateway; -class QuizModel { - - private QuizGateway $gateway; - - public function __construct(QuizGateway $gw) - { - $this -> gateway = $gw; - } - +class QuizModel extends Model{ + public function createQuiz(int $id_quiz, int $nb_questions) : bool { return $this -> gateway -> create($id_quiz, $nb_questions); diff --git a/src/Model/QuizQuestionModel.php b/src/Model/QuizQuestionModel.php index 915f95b..417e397 100644 --- a/src/Model/QuizQuestionModel.php +++ b/src/Model/QuizQuestionModel.php @@ -9,27 +9,19 @@ use Gateway\Connection; use Gateway\QuestionGateway; use Gateway\QuizGateway; 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 { - return $this->gw->create($idQuiz,$idQuestion); + return $this->gateway->create($idQuiz,$idQuestion); } public function findQuizQuestionByIdQuiz(int $id): ?QuizQuestionEntity { - $q = $this ->gw->findQuizQuestionByIdQuiz($id); + $q = $this ->gateway->findQuizQuestionByIdQuiz($id); if ($q) { return new QuizQuestionEntity( $q['idQuiz'], @@ -41,11 +33,11 @@ class QuizQuestionModel public function getAllQuestionByQuiz(int $id, Connection $co): array { - $q = $this->gw->findQuestionsFromQuiz($id); + $q = $this->gateway->findQuestionsFromQuiz($id); $questions = []; - $gw = new QuestionGateway($co); - $qmdl = new QuestionModel($gw); + $gateway = new QuestionGateway($co); + $qmdl = new QuestionModel($gateway); foreach ($q as $question){ $questions [] = $qmdl->getQuestion($question[1]); @@ -56,7 +48,7 @@ class QuizQuestionModel public function findAll(): array { - $q = $this -> gw -> findAll(); + $q = $this -> gateway -> findAll(); $quizzes = []; @@ -71,7 +63,7 @@ class QuizQuestionModel public function deleteQuizQuestion(int $id): bool { - return $this -> gw -> delete($id); + return $this -> gateway -> delete($id); } diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php index b924b6f..38f336f 100644 --- a/src/Model/QuoteModel.php +++ b/src/Model/QuoteModel.php @@ -2,14 +2,10 @@ namespace Model; use Entity\Quote; 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{ $res = $this->gateway->searchId($id); diff --git a/src/Model/ResultsModel.php b/src/Model/ResultsModel.php index 3e717f9..ef55844 100644 --- a/src/Model/ResultsModel.php +++ b/src/Model/ResultsModel.php @@ -4,24 +4,19 @@ namespace Model; use Entity\ResultsEntity; 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 { - return $this -> gw -> createResultsGateway($idQuiz, $idUser, $score, $time); + return $this -> gateway -> createResultsGateway($idQuiz, $idUser, $score, $time); } public function getResultsByQuiz(int $idQuiz) : array { - $res = $this -> gw -> findResultsByQuiz($idQuiz); + $res = $this -> gateway -> findResultsByQuiz($idQuiz); $results = []; @@ -39,7 +34,7 @@ class ResultsModel public function getResultsByUser(int $idUser) : array { - $res = $this -> gw -> findResultsByUser($idUser); + $res = $this -> gateway -> findResultsByUser($idUser); $results = []; @@ -57,7 +52,7 @@ class ResultsModel public function getResultsById(int $idQuiz, int $idUser) : ?ResultsEntity { - $res = $this -> gw -> findResultsById($idQuiz, $idUser); + $res = $this -> gateway -> findResultsById($idQuiz, $idUser); if ($res) { @@ -73,7 +68,7 @@ class ResultsModel public function getAllResults() : array { - $res = $this -> gw -> findAllResults(); + $res = $this -> gateway -> findAllResults(); $results = []; @@ -91,6 +86,6 @@ class ResultsModel 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); } } \ No newline at end of file diff --git a/src/Model/SearchModel.php b/src/Model/SearchModel.php index 4a81b17..5742270 100644 --- a/src/Model/SearchModel.php +++ b/src/Model/SearchModel.php @@ -2,14 +2,10 @@ namespace Model; use Entity\Quote; 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{ diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php index c7f2040..40b6eca 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -3,14 +3,10 @@ use Entity\User; use Entity\UserEntity; 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{ /*global $rep,$image;*/ diff --git a/src/Model/sourceModel.php b/src/Model/sourceModel.php index 4db7509..9430baa 100644 --- a/src/Model/sourceModel.php +++ b/src/Model/sourceModel.php @@ -2,17 +2,11 @@ namespace Model; use Entity\SourceEntity; 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 { $q = new SourceEntity($id_source , $title, $date); diff --git a/vue/templates/quoteLittle.html.twig b/vue/templates/quoteLittle.html.twig index bc9f397..858f718 100644 --- a/vue/templates/quoteLittle.html.twig +++ b/vue/templates/quoteLittle.html.twig @@ -2,14 +2,14 @@ {% if quotes|length > 0 %}
{% for quote in quotes %} - +
- {{ quote.caracter }} + {{ quote.carac }}

"{{ quote.content }}"

-

- {{ quote.title }}

-

Personnage : {{ quote.caracter }}

-

Année : {{ quote.dates }}

+

- {{ quote.titleSrc }}

+

Personnage : {{ quote.carac }}

+

Année : {{ quote.dateSrc }}