diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 65421c0..8bb979e 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -17,7 +17,7 @@ Class FrontControler{ $this->listAction = ['visitor' => array('accueil','search','quote','login','signin'), - 'user' => array('quiz','commentary','favorite','logout'), + 'user' => array('quiz','commentary','favorite','logout','addComment'), 'admin' => array('null')]; $dVueEreur = []; @@ -40,7 +40,7 @@ Class FrontControler{ $router->map('GET|POST', '/quote/[i:idQuote]', 'VisitorControler','quote'); $router->map('GET|POST', '/login', 'VisitorControler','login'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); - + $router->map('GET|POST', '/addComment', 'UserControler','addComment'); $router->map('GET|POST', '/quiz/[i:id]?', 'QuizControler','quiz'); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 2cc513a..5153905 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -1,10 +1,23 @@ cMod = new CommentaryModel(new CommentaryGateway($co)); + } + public function quiz(){ global $vues; require_once $vues['quiz']; } + + public function addComment(){ + echo $_POST['content']; + } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index fd855c7..3f78b37 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -1,16 +1,20 @@ qMod = new QuoteModel(new QuoteGateway($co)); + $this->cMod = new CommentaryModel(new CommentaryGateway($co)); } public function accueil(){ @@ -22,6 +26,7 @@ Class VisitorControler{ global $vues; $id=$arg['idQuote']; $q = $this->qMod->searchId($id); + $c = $this->cMod->getComment($id); require_once $vues['quote']; } @@ -36,4 +41,6 @@ Class VisitorControler{ global $vues; require_once $vues['signin']; } + + } diff --git a/src/Entity/commentaryEntity.php b/src/Entity/CommentaryEntity.php similarity index 81% rename from src/Entity/commentaryEntity.php rename to src/Entity/CommentaryEntity.php index bbf1fda..3398d68 100644 --- a/src/Entity/commentaryEntity.php +++ b/src/Entity/CommentaryEntity.php @@ -6,6 +6,7 @@ class CommentaryEntity { private int $id_comment; private string $comment; private string $date; + private string $user; /** * @param int $id_comment @@ -67,6 +68,21 @@ class CommentaryEntity { $this->date = $date; } + /** + * @return string $user + */ + public function getUser(): string + { + return $this->user; + } + + /** + * @param string $user + */ + public function setUser(int $user): void + { + $this->user = $user; + } } diff --git a/src/Gateway/commentaryGateway.php b/src/Gateway/CommentaryGateway.php similarity index 73% rename from src/Gateway/commentaryGateway.php rename to src/Gateway/CommentaryGateway.php index dee084a..4a16884 100644 --- a/src/Gateway/commentaryGateway.php +++ b/src/Gateway/CommentaryGateway.php @@ -2,7 +2,6 @@ namespace Gateway; namespace Gateway; -use Connection; use PDO; class CommentaryGateway { @@ -13,15 +12,17 @@ class CommentaryGateway { public function create(commentaryEntity $c) :bool { - $query="INSERT INTO Commentary VALUES(:id_comment, :comment , :date)"; + $query="INSERT INTO Commentary VALUES(:id_comment, :comment , :date, :idQuote, :idUser)"; return $this -> co -> executeQuery($query, array( "id_comment" => array($c->getIdComment(), PDO::PARAM_INT), "comment" => array($c->getComment(), PDO::PARAM_STR), + "idUser" => array($c->getUser(), PDO::PARAM_STR), + "idQuote" => array($id, PDO::PARAM_INT), "date" => array($c->getDate(), PDO::PARAM_STR))); } - public function findById(int $id) : ?commentaryEntity { + public function findById(int $id) : array { $query="SELECT * FROM Commentary WHERE id_comment = :id_comment"; @@ -29,6 +30,12 @@ class CommentaryGateway { return $res = $this -> co -> getResults(); } + public function findByQuote(int $id) : array{ + $query="SELECT c.id_comment, c.dateC, c.comment, u.username FROM Commentary c JOIN Users u ON u.id_user = c.users WHERE quote = :idQuote"; + $this -> co -> executeQuery($query, array("idQuote" => array($id,PDO::PARAM_STR))); + return $res = $this -> co -> getResults(); + } + public function findAll() : array { $query="SELECT * FROM Commentary"; diff --git a/src/Model/commentaryModel.php b/src/Model/CommentaryModel.php similarity index 66% rename from src/Model/commentaryModel.php rename to src/Model/CommentaryModel.php index acb2156..b698687 100644 --- a/src/Model/commentaryModel.php +++ b/src/Model/CommentaryModel.php @@ -11,17 +11,19 @@ class CommentaryModel { $this->gw = $gw; } - public function createComment(int $id_comment, string $comment, string $date): bool { + public function createComment(string $comment, string $date, string $idQuote, string $idUser): bool { - $c = new CommentaryEntity($id_comment, $comment, $date); + $c = new CommentaryEntity($id_comment, $comment, $date, $idUser); return $this->gw->create($c); } - public function getComment(int $id_comment): ?commentaryEntity { - $res = $this->gw->findById($id_comment); - if($res){ - return new CommentaryEntity($res[0]["id_comment"], $res[0]["comment"], $res[0]["date"]); + public function getComment(int $id): array { + $com = []; + $res = $this->gw->findByQuote($id); + foreach ($res as $comments){ + $com[] = new CommentaryEntity($comments["id_comment"], $comments["comment"], $comments["datec"], $comments["username"]); } + return $com; } public function getComments(): array { diff --git a/vue/quote.php b/vue/quote.php index 9466ceb..585cf53 100644 --- a/vue/quote.php +++ b/vue/quote.php @@ -15,6 +15,7 @@ 'sourceName' => $q->getTitleSrc(), 'dateSortie' => $q->getDateSrc(), 'nbLike' => $q->getLike(), - + 'com' => $c,)); + $_POST['idQuote'] = $q->getId(); )); ?> \ No newline at end of file diff --git a/vue/templates/quote.html b/vue/templates/quote.html index 7395b09..6fc7ecc 100644 --- a/vue/templates/quote.html +++ b/vue/templates/quote.html @@ -17,7 +17,19 @@
❤️
🔗
- + +
+
+
+ + +
+
+ {% if com|length > 0 %} + {% endif %}
\ No newline at end of file