ajout commentaire fonctionel

pull/21/head
kevin.modejar 5 months ago
parent 90cb24707a
commit f0c0fc7ac7

@ -8,9 +8,9 @@ $rep = __DIR__ . '/../';
//$dConfig['includes']= array('controleur/Validation.php');
//BD
$base = 'dbmarocher8';
$login = 'marocher8';
$mdp = 'sucepute';
$base = 'dbkemondejar';
$login = 'kemondejar';
$mdp = 'Ctvl-21122005';
//Vues

@ -1,8 +1,8 @@
<?php
session_start();
$_SESSION['role']='admin';
$_SESSION['login']=NULL;
$_SESSION['role']='user';
$_SESSION['user']='bob_brown';
$_SESSION['theme']='dark';
@ -19,7 +19,7 @@ $twig = new \Twig\Environment($loader, [
'cache' => false,
]);
$twig->addGlobal('racine','/~marocher8/WF-Website');
$twig->addGlobal('racine','/~kemondejar/WF-Website');
$cont = new Controleur\FrontControler($co);

@ -14,23 +14,15 @@ Class FrontControler{
public function __construct($co){
global $twig;
<<<<<<< HEAD
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin'),
'user' => array('quiz','commentary','favorite','logout','addComment'),
'admin' => array('null')];
=======
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin', 'favorite'),
'user' => array('quiz','commentary','logout'),
'user' => array('quiz','commentary','logout','addComment','favorite'),
'admin' => array('null')];
>>>>>>> refs/remotes/origin/master
$dVueEreur = [];
$router = new \AltoRouter();
$router->setBasePath('/~marocher8/WF-Website');
$router->setBasePath('/~kemondejar/WF-Website');
$router->map('GET', '/', 'VisitorControler','accueil');

@ -1,15 +1,20 @@
<?php
namespace Controleur;
use Model\CommentaryModel;
use Gateway\CommentaryGateway;
use Model\UserModel;
use Gateway\UserGateway;
Class UserControler{
private CommentaryModel $cMod;
private UserModel $uMod;
public function __construct(){
global $co;
$this->cMod = new CommentaryModel(new CommentaryGateway($co));
$this->uMod = new UserModel(new UserGateway($co));
}
public function quiz(){
@ -17,21 +22,18 @@ Class UserControler{
require_once $vues['quiz'];
}
<<<<<<< HEAD
public function addComment(){
echo $_POST['content'];
=======
$id = $_POST['idQuote'];
$this->cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user']));
header("Location: /~kemondejar/WF-Website/quote/$id");
}
public function favorits() {
global $vues;
$user = $_SESSION['username'];
$idUser = $this->userGateway->getIdUser($user);
$suggestions = $this->favoritsGateway->getFavorits(0, 'fr');
require_once $vues['favorits'];
>>>>>>> refs/remotes/origin/master
}
}

@ -35,7 +35,7 @@ class VisitorControler {
public function quote(array $arg) {
global $vues;
$id=$arg['idQuote'];
$id= $arg['idQuote'] ?? 1;
$q = $this->qMod->searchId($id);
$c = $this->cMod->getComment($id);
require_once $vues['quote'];

@ -1,6 +1,4 @@
<?php
namespace Gateway;
namespace Gateway;
use PDO;
@ -10,16 +8,14 @@ class CommentaryGateway {
$this->co = $co;
}
public function create(commentaryEntity $c) :bool {
public function create(string $comment ,string $idUser, int $idQuote) :bool {
$query="INSERT INTO Commentary VALUES(:id_comment, :comment , :date, :idQuote, :idUser)";
$query="INSERT INTO Commentary(quote,users,datec,comment) VALUES(:idQuote, :idUser , CURRENT_DATE,:comment )";
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)));
"comment" => array($comment, PDO::PARAM_STR),
"idUser" => array($idUser, PDO::PARAM_STR),
"idQuote" => array($idQuote, PDO::PARAM_INT)));
}
public function findById(int $id) : array {

@ -1,8 +1,9 @@
<?php
namespace Gateway;
use Connection;
use PDO;
Class UserGateway{
private Connection $con;
public function __construct(Connection $con){
@ -162,16 +163,10 @@ Class UserGateway{
public function getIdUser(string $username):array{
$query = 'SELECT id_user FROM Users WHERE username=:username';
$con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
$result = $con->getResults();
$this->con->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
$result = $this->con->getResults();
return $result;
}
}
$uG = new UserGateway(new Connection("pgsql:host=londres;dbname=dblebeaulato","lebeaulato",""));
?>

@ -11,10 +11,8 @@ class CommentaryModel {
$this->gw = $gw;
}
public function createComment(string $comment, string $date, string $idQuote, string $idUser): bool {
$c = new CommentaryEntity($id_comment, $comment, $date, $idUser);
return $this->gw->create($c);
public function createComment(string $comment, string $idQuote, string $idUser): bool {
return $this->gw->create($comment, $idUser, $idQuote);
}
public function getComment(int $id): array {

@ -72,6 +72,11 @@
return $src;
}
public function getIdByUsername(string $username){
$res = $this->gateway->getIdUser($username);
return $res[0]['id_user'];
}
}
?>

@ -5,6 +5,7 @@ global $twig;
echo $twig->render('head.html.twig', [
'title' => "Accueil",
'style' => "public/styles/styleAccueil.css",
'scripts' => array("public/script/theme-toggle.js")
]);

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

@ -22,6 +22,7 @@
<div>
<form action="{{racine}}/addComment" method="post">
<input type="text" class="comAdd" id="content" name="content" required>
<input type="hidden" class="hide" id="idQuote" name="idQuote" value="{{idQuote}}">
<input type="submit" class="btn" value=">" />
</form>
</div>

Loading…
Cancel
Save