ajout commentaire

pull/21/head
kevin.modejar 5 months ago
parent cecf746149
commit 2920ef7418

@ -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');

@ -1,10 +1,23 @@
<?php
namespace Controleur;
use Model\CommentaryModel;
Class UserControler{
private CommentaryModel $cMod;
public function __construct(){
global $co;
$this->cMod = new CommentaryModel(new CommentaryGateway($co));
}
public function quiz(){
global $vues;
require_once $vues['quiz'];
}
public function addComment(){
echo $_POST['content'];
}
}

@ -1,16 +1,20 @@
<?php
namespace Controleur;
use Model\QuoteModel;
use Model\CommentaryModel;
use Gateway\Connection;
use Gateway\QuoteGateway;
use Gateway\CommentaryGateway;
Class VisitorControler{
private QuoteModel $qMod;
private CommentaryModel $cMod;
public function __construct(){
global $co;
$this->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'];
}
}

@ -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;
}
}

@ -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";

@ -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 {

@ -15,6 +15,7 @@
'sourceName' => $q->getTitleSrc(),
'dateSortie' => $q->getDateSrc(),
'nbLike' => $q->getLike(),
'com' => $c,));
$_POST['idQuote'] = $q->getId();
));
?>

@ -17,7 +17,19 @@
<div class="like-icon">❤️</div>
<div class="share-icon">🔗</div>
</div>
<div class="commentaire">
<div>
<form action="{{racine}}/addComment" method="post">
<input type="text" class="comAdd" id="content" name="content" required>
<input type="submit" class="btn" value=">" />
</form>
</div>
{% if com|length > 0 %} <ul>
{% for c in com %}
<li>{{c.comment}} - {{ c.date }}</li>
{% endfor %} </ul>
{% endif %}
</div>
</body>
</html>
Loading…
Cancel
Save