Merge SubmitQuoteUser into master

pull/22/head^2
tomivt 5 months ago
commit 6281acbf84

BIN
.DS_Store vendored

Binary file not shown.

@ -10,7 +10,8 @@
"Model\\": "src/Model/",
"Gateway\\": "src/Gateway/",
"Entity\\": "src/Entity/",
"Verification\\": "src/Verification/"
"Verification\\": "src/Verification/",
"Enum\\": "src/Enum"
}
}
}

@ -12,7 +12,7 @@ $base = '';
$login = '';
$mdp = '';
$racine='/~lebeaulato/WF-Website';
$racine='';
//Vues

@ -13,10 +13,9 @@ if(!isset($_SESSION['theme'])){
//chargement config
require_once __DIR__ . '/config/config.php';
require __DIR__ . '/vendor/autoload.php';
$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbkekentin;', 'kekentin', 'passwd');
$co = new \Gateway\Connection('pgsql:host=localhost;dbname=dbwikifantasy;', 'kiem', '');
//twig
$loader = new \Twig\Loader\FilesystemLoader('vue/templates');

@ -0,0 +1,76 @@
@import url(./style.css);
@import url('https://fonts.googleapis.com/css2?family=Lemon&display=swap');
body, html {
height: 100%;
overflow: hidden;
}
/* ====== DARK MODE ====== */
body.dark-mode h1, body.dark-mode h2, body.dark-mode p {
color: white;
font-family: "Lemon", serif;
text-align: center;
}
/* ====== LIGHT MODE ====== */
body.light-mode h1, body.light-mode h2, body.light-mode p {
color: black;
font-family: "Lemon", serif;
text-align: center;
}
/* ====== OTHER ====== */
.header {
display: flex;
width: 100%;
height: 17%;
justify-content: space-between;
align-items: center;
}
.nav img {
margin-right: 10px;
}
.logo img {
display: block;
margin: 0 auto;
}
.user img {
margin-left: 10px;
}
#form {
width: 80%;
height: 83%;
display: flex;
justify-content: center;
align-items: center;
}
body.dark-mode #box {
background-color: #1b0048;
padding: 20px;
width: 50%;
margin: auto;
border-radius: 15px;
border: 1px solid #6100ff;
}
/* ====== DIVERS ====== */
#contentField, #characterField, #sourceField, #imageField {
}
#contentField p, #characterField p, #sourceField p, #imageField p {
}
#confirm {
}

@ -5,15 +5,18 @@ use Gateway\Connection;
Class FrontControler{
private $listAction;
private array $listAction;
private Connection $co;
/**
* @throws \Exception
*/
public function __construct($co){
global $twig,$racine;
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata'),
'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit'),
'admin' => array('null')];
$dVueEreur = [];
@ -44,10 +47,12 @@ Class FrontControler{
$router->map('GET|POST', '/unlog', 'UserControler','unlog');
$router->map('GET|POST', '/signin', 'VisitorControler','signin');
$router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin');
$router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
$router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
$router->map('GET|POST', '/addFav/[i:id]', 'UserControler','addFav');
$router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav');
$router->map('GET|POST', '/changedata', 'UserControler','changedata');
$router->map('GET|POST', '/submit', 'UserControler', 'submit');
$router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit');
$match = $router->match();

@ -1,27 +1,26 @@
<?php
namespace Controleur;
use Gateway\CharacterGateway;
use Gateway\SourceGateway;
use Model\CharacterModel;
use Model\CommentaryModel;
use Gateway\CommentaryGateway;
use Model\SourceModel;
use Model\UserModel;
use Gateway\UserGateway;
use Model\QuoteModel;
use Gateway\QuoteGateway;
use Entity\QuestionEntity;
use Gateway\Connection;
use Gateway\QuestionGateway;
use Gateway\QuizGateway;
use Gateway\QuizQuestionGateway;
use Model\QuestionModel;
use Model\QuizModel;
use Model\QuizQuestionModel;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Loader\FilesystemLoader;
use Verification\Verification;
use Enum\TypeSourceEnum;
class UserControler {
@ -112,7 +111,7 @@ class UserControler {
$score = $_SESSION['score'];
$_SESSION['no_question'] = Verification::verifChar( isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1);
if ($_SESSION['no_question'] >= $total_questions) {
session_destroy();
$_SESSION['no_question'] = 0;
$this->endQuiz($id_quiz, $score);
}
else header("Location: ".$racine."/quiz/$id_quiz"); ///~kekentin/WF/WF-Website
@ -181,6 +180,7 @@ class UserControler {
public function showQuestion(int $id, int $num) : void
{
global $vues;
global $twig;
$q = $this->GetQuestion($id);
$question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion();
@ -218,7 +218,6 @@ class UserControler {
global $vues;
if ($_POST)
{
$newImage = $_POST['image'] ?? null;
$newPseudo = $_POST['pseudo'] ?? null;
$newEmail = $_POST['email'] ?? null;
$newMdpFirst = $_POST['passwdFirst'] ?? null;
@ -227,14 +226,15 @@ class UserControler {
//Modif le pseudo
if($newPseudo){
$user = $this-> uMod->setUsername($_SESSION['user'], $newPseudo);
if($user == $newPseudo){ //Si le pseudo existe déjà
$_SESSION['user'] = $newPseudo;
}
}
else if($newEmail){
$user = $this-> uMod->setEmail($_SESSION['user'], $newEmail);
}
else if($newMdpFirst && $newMdpSecond){
if($newMdpFirst == $newMdpSecond){
@ -244,10 +244,106 @@ class UserControler {
$user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd);
}
}
else if($newImage){
$user = $this->uMod->setImage($_SESSION['user']);
}
header("Location: /");
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function submit() : void
{
global $twig;
echo $twig -> render("submitQuote.html.twig");
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function toSubmit() : ?array
{
global $co;
if ($_POST)
{
$content = $_POST['content'] ?? null;
$character = $_POST['character'] ?? null;
$source = $_POST['source'] ?? null;
//$img = $_POST['img'] ?? null;
$errors = [null, null];
$gw = new CharacterGateway($co);
$mdl = new CharacterModel($gw);
$character = $mdl -> getCharacterByName($character);
$gw = new SourceGateway($co);
$mdl = new SourceModel($gw);
$source = $mdl -> getSourceByTitle($source);
if (!$character)
$errors[0] = "Personnage inexistant";
if (!$source)
$errors[1] = "Source inexistante";
if ($errors[0] || $errors[1])
{
global $twig;
echo $twig->render("submitQuote.html.twig", ['errors' => $errors]);
exit();
}
$gw = new QuoteGateway($co);
$mdl = new QuoteModel($gw);
$mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter());
return [$content, $_POST['character'], $_POST['source']];
}
return null;
}
/**
* @throws SyntaxError
* @throws RuntimeError
* @throws LoaderError
*/
public function validsubmit() : void
{
$recap = $this -> toSubmit();
if ($recap)
{
$this -> recapSubmitQuote($recap);
}
}
/**
* @throws RuntimeError
* @throws SyntaxError
* @throws LoaderError
*/
public function recapSubmitQuote(?array $recap) : void
{
global $twig;
echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]);
}
public function getIdOfUser() : ?int
{
if (isset($_SESSION['user']))
{
global $co;
$gw = new UserGateway($co);
$mdl = new UserModel($gw);
return $mdl -> getUsername($_SESSION['user']) -> getId();
}
header("Location: /~lebeaulato/WF-Website/profil");
return null;
}
}

@ -87,14 +87,14 @@ Class VisitorControler {
*/
public function login()
{
global $vues;
require_once $vues['login'];
//global $vues;
//require_once $vues['login'];
// global $twig;
global $twig;
// echo $twig->render("login.html.twig");
echo $twig->render("login.html.twig");
//$this -> toLogIn();
$this -> toLogIn();
}
/**
@ -104,12 +104,15 @@ Class VisitorControler {
*/
public function signin(): void
{
global $vues;
require_once $vues['signin'];
}
//global $vues;
//require_once $vues['signin'];
global $twig;
echo $twig->render("login.html.twig");
$this -> signin();
}
public function validlogin() : void

@ -1,6 +1,8 @@
<?php
namespace Entity;
use Enum\TypeSourceEnum;
class SourceEntity
{
private int $id_source;
@ -9,16 +11,19 @@ class SourceEntity
private string $date;
private TypeSourceEnum $type;
/**
* @param int $id_source
* @param string $title
* @param string $date
*/
public function __construct(int $id_source, string $title, string $date)
public function __construct(int $id_source, string $title, string $date, TypeSourceEnum $type)
{
$this->id_source = $id_source;
$this->title = $title;
$this->date = $date;
$this->type = $type;
}
/**
@ -69,9 +74,15 @@ class SourceEntity
$this->date = $date;
}
public function getType(): TypeSourceEnum
{
return $this->type;
}
public function setType(TypeSourceEnum $type): void
{
$this->type = $type;
}
}

@ -0,0 +1,9 @@
<?php
namespace Enum;
enum TypeSourceEnum : string {
case Movie = 'movie';
case VideoGame = 'video-game';
case Anime = 'anime';
case TV = 'tv';
}

@ -11,56 +11,56 @@ class CharacterGateway extends Gateway
public function create(int $id_character, string $name , string $img_char) : bool
{
$query = "
INSERT INTO Characters
VALUES(:id_char, :name, :img_char)
INSERT INTO caracter
VALUES(:id_caracter, :caracter, :id_img)
";
return $this -> co -> executeQuery($query, [
'id_char' => array($id_character, PDO::PARAM_INT),
'name' => array($name, PDO::PARAM_STR),
'img_char' => array($img_char, PDO::PARAM_STR)
'id_caracter' => array($id_character, PDO::PARAM_INT),
'caracter' => array($name, PDO::PARAM_STR),
'id_img' => array($img_char, PDO::PARAM_STR)
]);
}
public function findById(int $id) : array
{
$query = "SELECT * FROM Characters WHERE id_char = :id_c";
$query = "SELECT * FROM caracter WHERE id_caracter = :id_c";
$this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
return $this -> co -> getResults();
}
public function findByName(string $name) : array
{
$query = "SELECT * FROM Characters WHERE name = :n";
$query = "SELECT * FROM caracter WHERE caracter = :n";
$this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]);
return $this -> co -> getResults();
}
public function findAll() : array
{
$query = "SELECT * FROM Characters";
$query = "SELECT * FROM caracter";
$this -> co -> executeQuery($query);
return $this -> co -> getResults();
}
public function delete(int $id) : bool
{
$query = "DELETE FROM Characters WHERE id_char = :id_c";
$query = "DELETE FROM caracter WHERE id_caracter = :id_c";
return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
}
public function update(int $id_char, string $name, string $img_char) : bool
{
$query = "
UPDATE Characters
SET name = :n, img_char = :i
WHERE id_char = :id_c
UPDATE caracter
SET caracter = :n, id_img = :i
WHERE id_caracter = :id_c
";
return $this -> co -> executeQuery($query, [
"id_c" => array($id_char, PDO::PARAM_INT),
"name" => array($name, PDO::PARAM_STR),
"caracter" => array($name, PDO::PARAM_STR),
"i" => array($img_char, PDO::PARAM_STR)
]);
}

@ -1,22 +1,21 @@
<?php
namespace Gateway;
use PDO;
use PDOException;
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->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;
$query="SELECT q.id_quote, q.content, c.id_char, c.img_char, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE content LIKE '%:quote%' AND is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;";
$this->co->executeQuery($query,array(':quote' => array($quote,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
return $this->co->getResults();
}
public function searchSource(string $source,int $numpage,string $language):array{
//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->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
$query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE s.title LIKE '%:source%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;";
$this->co->executeQuery($query,array(':source' => array($source,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
}
@ -24,8 +23,8 @@ Class QuoteGateway extends Gateway{
public function searchPers(string $Carac,int $numpage,string $language):array{
//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->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':language' => array($language,PDO::PARAM_STR)));
$query="SELECT q.id_quote, q.content, c.character, c.img_path, s.title, s.date, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character JOIN Source s ON s.id_source = q.id_source WHERE c.character LIKE '%:pers%' AND q.is_valid = true AND langue = :langue LIMIT 20 OFFSET :page*20;";
$this->co->executeQuery($query,array(':pers' => array($Pers,PDO::PARAM_STR),':page' => array($numpage,PDO::PARAM_INT),':langue' => array($language,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
}
@ -33,7 +32,7 @@ Class QuoteGateway extends Gateway{
public function searchId(string $id):array{
//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.character, i.imgPath, s.title, s.dates, q.likes, q.langue FROM Quote q JOIN Characters c ON c.id_char = q.character 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->co->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
$result=$this->co->getResults();
return $result;
@ -42,11 +41,11 @@ Class QuoteGateway extends Gateway{
public function search(?string $type,?string $search,array $filtre):array{
$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 Characters 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 lower(";
if($type=='personnage'){
$query = $query . "c.caracter) LIKE lower('%" . $search . "%')";
}
@ -62,7 +61,7 @@ Class QuoteGateway extends Gateway{
}*/
$this->co->executeQuery($query,array());
$result=$this->co->getResults();
return $result;
}
@ -71,7 +70,7 @@ Class QuoteGateway extends Gateway{
$query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue
FROM DailyQuote dq
JOIN Quote q ON dq.citation_id = q.id_quote
JOIN Caracter c ON c.id_caracter = q.id_caracter
JOIN Characters 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.isValide = true AND q.langue = :language
@ -85,14 +84,14 @@ Class QuoteGateway extends Gateway{
echo "Erreur dans getQuoteOfTheDay: " . $e->getMessage();
return [];
}
}
}
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
FROM Quote q
JOIN Caracter c ON c.id_caracter = q.id_caracter
JOIN Characters 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.isValide = true AND q.langue = :language
@ -110,7 +109,7 @@ Class QuoteGateway extends Gateway{
$query = "SELECT q.id_quote, q.content, c.caracter, i.imgPath, s.title, s.dateS, q.likes, q.langue
FROM Favorite f
JOIN Quote q ON f.quote = q.id_quote
JOIN Caracter c ON c.id_caracter = q.id_caracter
JOIN Characters 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 f.users = :userId";
@ -126,6 +125,32 @@ Class QuoteGateway extends Gateway{
}
}
public function autoincrement() : int
{
$query = "SELECT Max(id_quote) + 1 as id FROM Quote;";
$this->co->executeQuery($query);
return ($this -> co ->getResults())[0]['id'];
}
public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
{
$query = "
INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path)
VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path)
";
return $this->co->executeQuery($query, [
':id' => array($this->autoincrement(), PDO::PARAM_INT),
':content' => array($content, PDO::PARAM_STR),
':img_path' => array($img_path, PDO::PARAM_STR),
':langage' => array($langage, PDO::PARAM_STR),
':user' => array($user, PDO::PARAM_INT),
':reason' => array('À vérifier', PDO::PARAM_STR),
':source' => array($source, PDO::PARAM_STR),
':character' => array($character, PDO::PARAM_STR)
]);
}
//======================== PARTI ADMIN ========================
//Probablement à déplacer dans un autre fichier
@ -133,8 +158,7 @@ Class QuoteGateway extends Gateway{
//obtenir les quotes en attentes de validation par l'admin
$query = 'SELECT * FROM Quote WHERE isValid=:bool';
$this->co->executeQuery($query,array(':bool' => array(false, PDO::PARAM_BOOL)));
$result=$this->co->getResults();
return $result;
return $this->co->getResults();
}
public function validQuote(int $id){
@ -152,61 +176,56 @@ Class QuoteGateway extends Gateway{
public function updateContent(int $id, string $newContent):array{
//Update le contexte de quote passé en paramètre
$queryUpdate = 'UPDATE Quote SET content=:newContent WHERE id_quote=:idQuote';
$con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR)));
$this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newContent'=> array($newContent, PDO::PARAM_STR)));
//Renvoie le nouveau contexte de quote
$queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote';
$con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
$result = $con->getResults();
return $result;
$queryReponse = 'SELECT content FROM Quote WHERE id_quote=:idQuote';
$this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
return $this->co->getResults();
}
public function updateTimeCode(int $id, string $newTimeCode):array{
//Update le time code de quote passé en paramètre
$queryUpdate = 'UPDATE Quote SET timecode=:newTimeCode WHERE id_quote=:idQuote';
$con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR)));
$this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTimeCode'=> array($newTimeCode, PDO::PARAM_STR)));
//Renvoie le nouveau contexte de quote
$queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote';
$con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
$result = $con->getResults();
return $result;
$queryReponse = 'SELECT timecode FROM Quote WHERE id_quote=:idQuote';
$this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
return $this->co->getResults();
}
public function updateDate(int $id, int $newDate):array{
//Update la date de quote passé en paramètre
$queryUpdate = 'UPDATE Source SET dateSource =:newdate WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)';
$con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT)));
$this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newDate'=> array($newDate, PDO::PARAM_INT)));
//Renvoie la nouvelle date de quote
$queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
$con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
$result = $con->getResults();
return $result;
$queryReponse = 'SELECT s.dateSource FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
$this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
return $this->co->getResults();
}
public function updateTitle(int $id, string $newTitle):array{
//Update le titre de l'oeuvre de quote passé en paramètre
$queryUpdate = 'UPDATE Source SET title =:newTitle WHERE idSource = (SELECT idSource FROM Quote WHERE idQuote =:idQuote)';
$con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR)));
$this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newTitle'=> array($newTitle, PDO::PARAM_STR)));
//Renvoie le nouveau titre de quote
$queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
$con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
$result = $con->getResults();
return $result;
$queryReponse = 'SELECT s.title FROM Source s, Quote q WHERE id_quote=:idQuote AND s.idSource = q.idSource';
$this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
return $this->co->getResults();
}
public function updateNameCharacter(int $id, string $newNameCharacter):array{
//Update le personnage de l'oeuvre de quote passé en paramètre
$queryUpdate = 'UPDATE Character SET name =:newNameCharacter WHERE idCharacter = (SELECT idCharacter FROM Quote WHERE idQuote =:idQuote)';
$con->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR)));
$this->co->executeQuery($queryUpdate, array(':idQuote'=>array($id, PDO::PARAM_STR), ':newNameCharacter'=> array($newNameCharacter, PDO::PARAM_STR)));
//Renvoie le nouveau personnage de quote
$queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter';
$con->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
$result = $con->getResults();
return $result;
$queryReponse = 'SELECT c.title FROM Character c, Quote q WHERE id_quote=:idQuote AND c.idCharacter = q.idCharacter';
$this->co->executeQuery($queryReponse, array(':idQuote'=>array($id, PDO::PARAM_STR)));
return $this->co->getResults();
}
}

@ -1,20 +1,22 @@
<?php
namespace Gateway;
use Connection;
use Enum\TypeSourceEnum;
use Entity\SourceEntity;
use PDO;
class SourceGateway extends Gateway{
class SourceGateway extends Gateway{
public function create(sourceEntity $s) : bool
public function create(string $title, string $date, TypeSourceEnum $type) : bool
{
$query = "
INSERT INTO Source
VALUES(:id_source, :title, :date)
VALUES (:title, :type, :date)
";
return $this -> co -> executeQuery($query, [
"id_source" => array($s->getIdSource(), PDO::PARAM_INT),
"title" => array($s->getTitle(), PDO::PARAM_STR),
"date" => array($s->getDate(), PDO::PARAM_STR)
"title" => array($title, PDO::PARAM_STR),
"date" => array($date, PDO::PARAM_STR),
"type" => array($type, PDO::PARAM_STR)
]);
}
@ -30,7 +32,7 @@ class SourceGateway extends Gateway{
{
$query = "SELECT * FROM Source WHERE title = :t";
$this -> co -> executeQuery($query, ["title" => array($t, PDO::PARAM_STR)]);
$this -> co -> executeQuery($query, ["t" => array($t, PDO::PARAM_STR)]);
return $res = $this -> co -> getResults();
// if ($res)
@ -44,18 +46,18 @@ class SourceGateway extends Gateway{
public function findByDate(string $d) : array
{
$query = "SELECT * FROM Source WHERE date = :d";
$query = "SELECT * FROM Source WHERE dates = :d";
$this -> co -> executeQuery($query, ["date" => array($d, PDO::PARAM_STR)]);
$res = $this -> co -> getResults();
return $this -> co -> getResults();
}
if ($res)
return new sourceEntity(
$res["id_source"],
$res["title"],
$res["date"]
);
return null;
public function findByType(TypeSourceEnum $type) : array
{
$query = "SELECT * FROM Source WHERE type = :t";
$this -> co -> executeQuery($query, ["t" => array($type, PDO::PARAM_STR)]);
return $this -> co -> getResults();
}
public function findAll() : array
@ -71,7 +73,8 @@ class SourceGateway extends Gateway{
$sources[] = new sourceEntity(
$source["id_source"],
$source["title"],
$source["date"]
$source["date"],
$res["source"]
);
}
return $sources;

@ -78,7 +78,7 @@ Class UserGateway extends Gateway{
// 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';
$query = 'SELECT * FROM Users u Join Image i on i.id_img=u.img WHERE username= :username';
$this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR)));
return $this->co->getResults();
}

@ -19,9 +19,9 @@ class CharacterModel extends Model
$c = $this -> gateway -> findById($id_character);
if ($c)
return new CharacterEntity(
$c['id_character'],
$c['name'],
$c['img_path']
$c['id_caracter'],
$c['caracter'],
$c['id_img']
);
return null;
}
@ -31,9 +31,9 @@ class CharacterModel extends Model
$c = $this -> gateway -> findByName($name);
if ($c)
return new CharacterEntity(
$c[0]['id_character'],
$c[0]['name'],
$c[0]['img_path']
$c[0]['id_caracter'],
$c[0]['caracter'],
$c[0]['id_img']
);
return null;
}
@ -47,9 +47,9 @@ class CharacterModel extends Model
foreach ($c as $character)
{
$characters[] = new CharacterEntity(
$character['id_character'],
$character['name'],
$character['img_path']
$character['id_caracter'],
$character['caracter'],
$character['id_img']
);
}
return $characters;

@ -42,6 +42,12 @@
}
return $tabQ;
}
public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
{
return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character);
}
}
?>

@ -38,8 +38,8 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['password'],
$res[0]['email'],
$res[0]['password'],
$res[0]['img'],
$res[0]['creation']
);
@ -53,9 +53,9 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['password'],
$res[0]['email'],
$res[0]['imgpath'],
$res[0]['password'],
$res[0]['img'],
$res[0]['creation']
);
return null;
@ -68,8 +68,8 @@
return new UserEntity(
$res[0]['id_user'],
$res[0]['username'],
$res[0]['password'],
$res[0]['email'],
$res[0]['password'],
$res[0]['img'],
$res[0]['creation']
);

@ -1,17 +1,14 @@
<?php
namespace Model;
use Entity\SourceEntity;
use Gateway\SourceGateway;
use Gateway\Gateway;
use Enum\TypeSourceEnum;
class SourceModel extends Model
{
public function createSource(int $id_source, string $title, string $date) : bool
public function createSource(string $title, string $date, TypeSourceEnum $type) : bool
{
$q = new SourceEntity($id_source , $title, $date);
return $this -> gateway -> create($q);
return $this -> gateway -> create($title, $date, $type);
}
public function getSourceById(int $id_source) : ?SourceEntity
@ -22,40 +19,68 @@ class SourceModel extends Model
return new sourceEntity(
$res[0]["id_source"],
$res[0]["title"],
$res[0]["date"]
$res[0]["dates"],
TypeSourceEnum::from($res[0]["type"])
);
return null;
}
public function getSourceByTitle(string $title) : array
public function getSourceByTitle(string $title) : ?SourceEntity
{
$res = $this->gateway->findByTitle($title);
if ($res)
return new sourceEntity(
$res[0]["id_source"],
$res[0]["title"],
$res[0]["dates"],
TypeSourceEnum::from($res[0]["type"])
);
return null;
}
public function getSourceByDate(string $date) : array
{
$res = $this->gateway->findByDate($date);
$src = [];
foreach ($res as $sources) {
$src[] = new sourceEntity(
$sources["id_source"],
$sources["title"],
$sources["date"]
);
$sources["id_source"],
$sources["title"],
$sources["dates"],
TypeSourceEnum::from($sources["type"])
);
}
return $src;
}
public function getSourceByDate(string $date) : array
public function getSourceByType(TypeSourceEnum $type) : array
{
$res = $this->gateway->findByDate($date);
$res = $this->gateway->findByType($type);
$src = [];
foreach ($res as $sources) {
$src[] = new sourceEntity(
$sources["id_source"],
$sources["title"],
$sources["date"]
);
$sources["id_source"],
$sources["title"],
$sources["dates"],
TypeSourceEnum::from($sources["type"])
);
}
return $src;
}
public function getSources() : array
public function getAllSources() : array
{
return $this -> gateway -> findAll();
$res = $this -> gateway -> findAll();
$src = [];
foreach ($res as $sources) {
$src[] = new sourceEntity(
$sources["id_source"],
$sources["title"],
$sources["dates"],
TypeSourceEnum::from($sources["type"])
);
}
return $src;
}
public function deleteSource(int $id_source) : bool

@ -13,6 +13,7 @@ return array(
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
'Model\\' => array($baseDir . '/src/Model'),
'Gateway\\' => array($baseDir . '/src/Gateway'),
'Enum\\' => array($baseDir . '/src/Enum'),
'Entity\\' => array($baseDir . '/src/Entity'),
'Controleur\\' => array($baseDir . '/src/Controleur'),
);

@ -42,6 +42,7 @@ class ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c
),
'E' =>
array (
'Enum\\' => 5,
'Entity\\' => 7,
),
'C' =>
@ -79,6 +80,10 @@ class ComposerStaticInit68804b2111cb6b8bf6edf66cb2b4669c
array (
0 => __DIR__ . '/../..' . '/src/Gateway',
),
'Enum\\' =>
array (
0 => __DIR__ . '/../..' . '/src/Enum',
),
'Entity\\' =>
array (
0 => __DIR__ . '/../..' . '/src/Entity',

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wiki Fantasy : Submit Quote</title>
<link id="favicon" rel="icon" href="../../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link rel="stylesheet" href="../../public/styles/styleSubmitQuote.css">
<script defer src="../../public/script/theme-toggle.js"></script>
</head>
<body>
{% include "bandeau.html.twig" %}
<h1>▶ Your quote has been submitted successfully ◀</h1>
<div>
<div id="box">
<div id="contentField">
<p>Contenu *</p>
<h2>{{ content }}</h2>
</div>
<div id="characterField">
<p>Personnage *</p>
<h2>{{ character }}</h2>
</div>
<div id="sourceField">
<p>Source *</p>
<h2>{{ source }}</h2>
</div>
<div>
<button onclick="window.location.href='/';"> Revenir à l'acceuil</button>
</div>
</div>
</div>
</body>
</html>

@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wiki Fantasy : Submit Quote</title>
<link id="favicon" rel="icon" href="../../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link rel="stylesheet" href="../../public/styles/styleSubmitQuote.css">
<script defer src="../../public/script/theme-toggle.js"></script>
</head>
<body>
{% include "bandeau.html.twig" %}
<h1>▶ Submit a Quote ◀</h1>
<form id="form" method="post" action="/validsubmit">
<div id="box">
<div id="contentField">
<p>Contenu *</p>
<input type="text" id="content" name="content" placeholder="Entrez le contenu de la citation" required/>
</div>
<div id="characterField">
<p>Personnage *</p>
<input type="text" id="character" name="character" placeholder="Entrez le/la personnage de la citation" required/>
{% if errors[0] is defined and errors[0] is not empty %}
<p style="color: red">{{ errors[0] }}</p>
{% endif %}
</div>
<div id="sourceField">
<p>Source *</p>
<input type="text" id="source" name="source" placeholder="Entrez la source de la citation" required/>
{% if errors[1] is defined and errors[1] is not empty %}
<p style="color: red">{{ errors[1] }}</p>
{% endif %}
</div>
<div id="imageField">
<p>Image *</p>
</div>
<div id="confirm">
<input type="submit" class="btn" name="action" value="Soumettre"/>
</div>
</div>
</form>
</body>
</html>
Loading…
Cancel
Save