diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml
new file mode 100644
index 0000000..b631df8
--- /dev/null
+++ b/.idea/material_theme_project_new.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..449c40f
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $PROJECT_DIR$/composer.json
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "customColor": "",
+ "associatedIndex": 4
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1730794293135
+
+
+ 1730794293135
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php
new file mode 100644
index 0000000..d4d5fd6
--- /dev/null
+++ b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php
@@ -0,0 +1,95 @@
+
+ */
+ private array $macros = [];
+
+ public function __construct(Environment $env)
+ {
+ parent::__construct($env);
+
+ $this->source = $this->getSourceContext();
+
+ $this->parent = false;
+
+ $this->blocks = [
+ ];
+ }
+
+ protected function doDisplay(array $context, array $blocks = []): iterable
+ {
+ $macros = $this->macros;
+ // line 1
+ yield "
+
+
+
+
+ Wiki Fantasy : Quiz
+
+
+
+
+
+
+
+ ";
+ // line 14
+ yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["score"] ?? null), "html", null, true);
+ yield "
+
+
+
+
+";
+ yield from [];
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getTemplateName(): string
+ {
+ return "endQuiz.html.twig";
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function isTraitable(): bool
+ {
+ return false;
+ }
+
+ /**
+ * @codeCoverageIgnore
+ */
+ public function getDebugInfo(): array
+ {
+ return array ( 57 => 14, 42 => 1,);
+ }
+
+ public function getSourceContext(): Source
+ {
+ return new Source("", "endQuiz.html.twig", "/Users/kiem/Documents/WikiFantasy/WF-Website/vue/templates/endQuiz.html.twig");
+ }
+}
diff --git a/config/config.php b/config/config.php
index 746e2b5..4faee83 100644
--- a/config/config.php
+++ b/config/config.php
@@ -8,7 +8,6 @@ $rep = __DIR__ . '/../';
//$dConfig['includes']= array('controleur/Validation.php');
//BD
-
$base = 'dbmarocher8';
$login = 'marocher8';
$mdp = 'sucepute';
diff --git a/index.php b/index.php
index 1b7ac9f..1037b10 100644
--- a/index.php
+++ b/index.php
@@ -23,8 +23,5 @@ $twig->addGlobal('racine','/~marocher8/WF-Website');
$cont = new Controleur\FrontControler($co);
-session_unset();
-session_destroy();
-$_SESSION = array();
?>
diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php
index 0a8b24f..2938d4a 100644
--- a/src/Controleur/FrontControler.php
+++ b/src/Controleur/FrontControler.php
@@ -37,7 +37,7 @@ Class FrontControler{
'' => '[^/\.]++'
*/
- $router->map('GET|POST', '/quote/[i:idQuote]?', 'VisitorControler','quote');
+ $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', '/favorite', 'VisitorControler','favorite');
diff --git a/src/Controleur/QuizControler.php b/src/Controleur/QuizControler.php
index 0e72f6d..34f33d8 100644
--- a/src/Controleur/QuizControler.php
+++ b/src/Controleur/QuizControler.php
@@ -1,5 +1,4 @@
co = $co;
- $this -> gw = new QuestionGateway($this->co);
- $this -> mdl = new QuestionModel($this->gw);
-
- $loader = new FilesystemLoader('vue/templates');
+ $this -> gw = new QuestionGateway($this -> co);
+ $this -> mdl = new QuestionModel($this -> gw);
+ global $num;
+ global $loader;
$action = $_REQUEST['action'] ?? null;
$id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null;
+ $nb_questions = $this->getNumberOfQuestion($id);
switch ($action) {
case 'canswer':
-
if ($this->CorrectAnswer())
- echo "Bonne réponse";
- else echo "Mauvaise réponse";
- $this->no_question ++;
- echo $this->no_question;
- $this->showQuestion($id, $this->no_question);
+ $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1;
+ $this->continueQuiz($id, $nb_questions);
break;
default:
switch($id)
@@ -61,13 +56,48 @@ class QuizControler
// page erreur
break;
default:
- $this->showQuestion($id, $this->no_question);
+ $_SESSION['score'] = $_SESSION['score'] ?? 0;
+ $this->showQuestion($id, $_SESSION['no_question'] ?? 0);
break;
}
}
}
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function continueQuiz(int $id_quiz, int $total_questions) : void
+ {
+ $score = $_SESSION['score'];
+ $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1;
+ if ($_SESSION['no_question'] >= $total_questions) {
+ session_destroy();
+ $this->endQuiz($id_quiz, $score);
+ }
+ else header("Location: http://localhost:8000/quiz/$id_quiz");
+
+ }
+
+ /**
+ * @throws SyntaxError
+ * @throws RuntimeError
+ * @throws LoaderError
+ */
+ public function endQuiz(int $id_quiz, int $score) : void
+ {
+ global $twig;
+
+ $gw = new QuizGateway($this->co);
+ $mdl = new QuizModel($gw);
+
+ if ($mdl->getQuiz($id_quiz + 1))
+ echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]);
+ echo $twig->render('endQuiz.html.twig', ['score' => $score]);
+ }
+
public function CorrectAnswer() : bool
{
$answera = $_POST['answera'] ?? null;
@@ -108,37 +138,23 @@ class QuizControler
* @throws SyntaxError
* @throws LoaderError
*/
- public function showQuestion(int $id, int $no) : void
+ public function showQuestion(int $id, int $num) : void
{
global $twig;
+ echo $num;
+ echo " : ", $_SESSION['score'];
$q = $this->GetQuestion($id);
- $question = $q[$no];
-
+ $question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion();
echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]);
-
}
- public function getNumberOfQuestion() : int
+
+ public function getNumberOfQuestion(int $id) : int
{
$gw = new QuizGateway($this->co);
$mdl = new QuizModel($gw);
- return 0;
-
+ return $mdl->getQuiz($id)->getNbQuestions();
}
-}
-
-/*
-
-getUrl() ?>> = $new->getTitle() ?>
- }
-
-?>
-
-
-*/
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php
index e03a88e..a446714 100644
--- a/src/Controleur/VisitorControler.php
+++ b/src/Controleur/VisitorControler.php
@@ -30,7 +30,11 @@ class VisitorControler {
public function quote(array $arg) {
global $vues;
+<<<<<<< HEAD
$id = $arg['idQuote'] ?? 1;
+=======
+ $id=$arg['idQuote'];
+>>>>>>> refs/remotes/origin/master
$q = $this->qMod->searchId($id);
require_once $vues['quote'];
}
diff --git a/src/Gateway/userGateway.php b/src/Gateway/userGateway.php
index 25ae228..1472485 100644
--- a/src/Gateway/userGateway.php
+++ b/src/Gateway/userGateway.php
@@ -11,56 +11,129 @@ Class UserGateway{
public function insert(string $username,string $email,string $passwd):string{
- // récupération id
- $query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM Users);';
- $this->con->executeQuery($query);
- $result=$this->con->getResults();
- foreach($result as $row){
- $id=$row['id_user'] + 1;
- }
+ //crypte passeword
+ $passwordEncrypted = crypt($passwd);
// insertion user
- $query='INSERT INTO Users VALUES (:id,:username,:email,:passwd,CURRENT_DATE,false);';
- $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR),':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwd,PDO::PARAM_STR)));
+ $query='INSERT INTO Users VALUES (:username,:email,:passwd,CURRENT_DATE,false);';
+ $this->con->executeQuery($query,array(':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwordEncrypted,PDO::PARAM_STR)));
return $id;
}
public function delete(string $id) : bool{
- // supretion user
+ // suppression user
$query='DELETE FROM Users WHERE id_user = :id;';
- return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR)));
+ return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
}
+ public function getFavorite(string $id):array{
+
+ //obtention favoris d'un user
+ $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote IN Favorite f JOIN User u ON u.id_user = f.user WHERE id_user = :id);';
+ $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT)));
+ $result=$this->con->getResults();
+ return $result;
+ }
+
//obtenir les information d'un user
public function findDataUser(int $id):array{
$query = 'SELECT * FROM Users WHERE id_user=:idUser';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT)));
$result = $con->getResults();
return $result;
}
+ public function createQuote(int $id, string $content, string $langue, string $caracter, string $source):array{
+
+ //recupère id du personnage
+ $queryCaracter = "SELECT id_caracter FROM Caracter WHERE caracter =:caracter";
+ $con->executeQuery($queryCaracter, array(
+ ':caracter'=>array($caracter, PDO::PARAM_STR)
+ ));
+ $resultCaracter = $con->getResult();
+
+ if($resultCaracter == NULL){
+ //ajout creationCaracter
+ }
+
+ //recupère id de la source
+ $querySource = "SELECT id_source FROM Source WHERE title =:source";
+ $con->executeQuery($querySource, array(
+ ':source'=>array($source, PDO::PARAM_STR)
+ ));
+ $resultSource = $con->getResult();
+
+ if($resultSource == NULL){
+ //ajout creationSource
+ }
+ $queryInsert = "INSERT INTO Quote (content, langue, id_caracter, id_source, id_user_verif) VALUES (:content, :langue, :caracter, :source, :idverif)";
+ $con->executeQuery($queryInsert, array(
+ ':content'=>array($content, PDO::PARAM_STR),
+ ':langue'=>array($langue, PDO::PARAM_STR),
+ ':caracter'=>array($resultCaracter, PDO::PARAM_STR),
+ ':source'=>array($resultSource, PDO::PARAM_STR),
+ ':idverif'=>array($id, PDO::PARAM_INT)
+ ));
+ }
+
+
+
+ public function createCaracter(string $caracter, string $img):array{
+ //creation du personnage
+ $queryCaracter = "INSERT INTO Caracter(caracter, img_path) VALUES (:caracter, :img)";
+ $con->executeQuery($queryCaracter, array(
+ ':caracter'=>array($caracter, PDO::PARAM_STR),
+ 'img'=>array($img, PDO::PARAM_STR)
+ ));
+
+ //récuperation de id caracter
+ $queryCaracter = "SELECT id_caracter FROM Caracter WHERE caracter =:caracter";
+ $con->executeQuery($queryCaracter, array(
+ ':caracter'=>array($caracter, PDO::PARAM_STR)
+ ));
+ $resultCaracter = $con->getResult();
+ }
+
+
+
+ public function createSource(string $title, string $dateS):array{
+ //creation du personnage
+ $querySource = "INSERT INTO Source(title, dateS) VALUES (:title, :dateS)";
+ $con->executeQuery($querySource, array(
+ ':title'=>array($title, PDO::PARAM_STR),
+ 'dateS'=>array($dateS, PDO::PARAM_STR)
+ ));
+
+ //recupère id de la source
+ $querySource = "SELECT id_source FROM Source WHERE title =:source";
+ $con->executeQuery($querySource, array(
+ ':source'=>array($source, PDO::PARAM_STR)
+ ));
+ $querySource = $con->getResult();
+ }
+
// ===================== UPDATE FUNCTION =====================
public function updateUsername(int $id, string $newUsername):array{
//Update le nom du user passé en paramètre
$queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser';
- $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
+ $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_INT), ':newUsername'=> array($newUsername, PDO::PARAM_STR)));
//Renvoie le nouveau nom du user
$queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR)));
+ $con->executeQuery($queryReponse, array($id=>array($id, PDO::PARAM_INT)));
return $result;
}
public function updateEmail(int $id, string $newEmail):array{
//Update le email du user passé en paramètre
$queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser';
- $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
+ $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_INT), ':newEmail'=> array($newEmail, PDO::PARAM_STR)));
//Renvoie le nouveau email du user
$queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_INT)));
$result = $con->getResults();
return $result;
}
@@ -68,25 +141,23 @@ Class UserGateway{
public function updateImg(int $id, int $newImg):array{
//Update l'image du user passé en paramètre
$query = 'UPDATE Users SET img=:newImg WHERE id_user=:idUser';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR)));
+ $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT), ':newImg'=> array($newImg, PDO::PARAM_STR)));
//Renvoie la nouvelle image du user
$queryReponse = 'SELECT img FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
+ $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_INT)));
$result = $con->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';
- $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
- //Renvoie le nouveau passwd du user
- $queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser';
- $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR)));
- $result = $con->getResults();
- return $result;
+ //crypte le mot de passe
+ $passwordEncrypted = crypt($newPassWd);
+
+ //Update le passwd du user passé en paramètre
+ $query = 'UPDATE Users SET password=:newPassWd WHERE id_user=:idUser';
+ $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT), ':newPassWd'=> array($passwordEncrypted, PDO::PARAM_STR)));
}
public function getIdUser(string $username):array{
@@ -98,6 +169,9 @@ Class UserGateway{
}
+
+
+
$uG = new UserGateway(new Connection("pgsql:host=londres;dbname=dblebeaulato","lebeaulato",""));
?>
diff --git a/src/Model/QuizModel.php b/src/Model/QuizModel.php
index 728d516..155a512 100644
--- a/src/Model/QuizModel.php
+++ b/src/Model/QuizModel.php
@@ -24,8 +24,8 @@ class QuizModel {
$q = $this -> gateway -> findQuizById($id_quiz);
if ($q) {
return new quizEntity(
- $q['id_quiz'],
- $q['nb_questions'],
+ $q[0]['id_quiz'],
+ $q[0]['nb_quest']
);
}
return null;
diff --git a/vue/accueil.php b/vue/accueil.php
index f40330d..1764696 100644
--- a/vue/accueil.php
+++ b/vue/accueil.php
@@ -1,12 +1,13 @@
render('head.html.twig', [
'title' => "Accueil",
'style' => "public/styles/styleAccueil.css",
]);
+
// Rendu du bandeau
echo $twig->render('bandeau.html.twig');
diff --git a/vue/login.php b/vue/login.php
index e6fea79..39ec7a4 100644
--- a/vue/login.php
+++ b/vue/login.php
@@ -4,7 +4,8 @@
echo $twig->render('head.html.twig', array(
'title' => "Login",
- 'style' => "public/styles/styleLogin.css",
+ 'style' => "public/styles/styleLogin.css",
+ 'scripts' => array("public/script/theme-toggle.js")
));
echo $twig->render('bandeau.html.twig');
diff --git a/vue/quote.php b/vue/quote.php
index 8332bf2..9466ceb 100644
--- a/vue/quote.php
+++ b/vue/quote.php
@@ -4,7 +4,8 @@
echo $twig->render('head.html.twig', array(
'title' => "Quote",
- 'style' => "public/styles/styleQuote.css",
+ 'style' => "../public/styles/styleQuote.css",
+ 'scripts' => array("../public/script/theme-toggle.js")
));
echo $twig->render('bandeau.html.twig');
echo $twig->render('quote.html', array(
@@ -14,7 +15,6 @@
'sourceName' => $q->getTitleSrc(),
'dateSortie' => $q->getDateSrc(),
'nbLike' => $q->getLike(),
- 'timeCode' =>"1h45",
));
?>
\ No newline at end of file
diff --git a/vue/signin.php b/vue/signin.php
index 4cef884..efb8cd3 100644
--- a/vue/signin.php
+++ b/vue/signin.php
@@ -5,6 +5,7 @@
echo $twig->render('head.html.twig', array(
'title' => "Sign in",
'style' => "public/styles/styleSignin.css",
+ 'scripts' => array("public/script/theme-toggle.js")
));
echo $twig->render('bandeau.html.twig');
diff --git a/vue/templates/endQuiz.html.twig b/vue/templates/endQuiz.html.twig
new file mode 100644
index 0000000..b34f4ea
--- /dev/null
+++ b/vue/templates/endQuiz.html.twig
@@ -0,0 +1,19 @@
+
+
+
+
+
+ Wiki Fantasy : Quiz
+
+
+
+
+
+
+
+ {{ score }}
+ {{ nextquiz }}
+
+zeze
+
+
diff --git a/vue/templates/head.html.twig b/vue/templates/head.html.twig
index 31c1ef9..8d9e7ce 100644
--- a/vue/templates/head.html.twig
+++ b/vue/templates/head.html.twig
@@ -6,6 +6,10 @@
{{ title }}
-
+ {% if scripts|length > 0 %}
+ {% for script in scripts %}
+
+ {% endfor %}
+ {% endif %}
\ No newline at end of file
diff --git a/vue/templates/login.html b/vue/templates/login.html
index e4cd68d..3005264 100644
--- a/vue/templates/login.html
+++ b/vue/templates/login.html
@@ -6,7 +6,7 @@
-

+

@@ -24,7 +24,7 @@
diff --git a/vue/templates/quiz.html.twig b/vue/templates/quiz.html.twig
index f78dd54..b53270d 100644
--- a/vue/templates/quiz.html.twig
+++ b/vue/templates/quiz.html.twig
@@ -9,7 +9,7 @@
-
-
+ {{ include "bandeau.html.twig" }}
▶ Quiz ◀
diff --git a/vue/templates/quote.html b/vue/templates/quote.html
index ddf2581..7395b09 100644
--- a/vue/templates/quote.html
+++ b/vue/templates/quote.html
@@ -5,7 +5,7 @@
“{{quoteContent}}”
- - - {{sourceName}} ({{timeCode}})
+ - - {{sourceName}}
- - {{nameCarac}}
- - {{dateSortie}}