@ -29,20 +29,29 @@ class UserControler {
private CommentaryModel $cMod;
private UserModel $uMod;
private QuoteModel $qMod;
private QuestionModel $mdl;
private CharacterModel $caMod;
private SourceModel $srcMod;
private QuestionModel $questMod;
private ImageModel $iMod;
private QuizModel $quizModel;
public function __construct() {
global $co;
$this->cMod = new CommentaryModel(new CommentaryGateway($co));
$this->uMod = new UserModel(new UserGateway($co));
$this->qMod = new QuoteModel(new QuoteGateway($co));
$this -> mdl = new QuestionModel(new QuestionGateway($co));
$this -> questMod = new QuestionModel(new QuestionGateway($co));
$this -> caMod = new CharacterModel(new CharacterGateway($co));
$this->srcMod = new SourceModel(new SourceGateway($co));
$this->iMod = new ImageModel(new ImageGateway($co));
$this->quizModel = new QuizModel(new QuizGateway($co));
}
public function accueilQuiz() {
global $vues;
$quizs = $this->quizModel->listQuiz();
require_once $vues['accueilQuiz'];
}
public function profil() {
@ -145,10 +154,12 @@ class UserControler {
$gw = new QuizGateway($co);
$mdl = new QuizModel($gw);
$nbQuestion = $this->getNumberOfQuestion($id_quiz);
if ($mdl->getQuiz($id_quiz + 1)){
$next = true;
require_once $vues['endQuiz'];
}
$next = false;
require_once $vues['endQuiz'];
}
@ -174,7 +185,7 @@ class UserControler {
$answer = explode('-', $answerd)[0];
$id = (int) explode('-', $answerd)[1];
}
$res = $this->mdl ->getQuestion($id);
$res = $this->questMod ->getQuestion($id);
return $answer == $res->getCanswer();
}
@ -195,11 +206,20 @@ class UserControler {
$q = $this->GetQuestion($id);
$question = $q[$num] ?? $q[0];
$idquestion = $question->getIdQuestion();
$nbQuestion = $this->getNumberOfQuestion($id);
require_once $vues['quiz'];
//echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]);
}
public function getQuiz(int $id) : QuizModel
{
global $co;
$gw = new QuizGateway($co);
$mdl = new QuizModel($gw);
return $mdl->getQuiz($id);
}
public function getNumberOfQuestion(int $id) : int{
global $co;
@ -333,46 +353,24 @@ class UserControler {
* @throws RuntimeError
* @throws LoaderError
*/
public function toSubmit() : ?array{
public function toSubmit(string $content,string $character, string $source)
{
global $co;
if ($_POST)
{
$content = $_POST['content'] ?? null;
$character = $_POST['character'] ?? null;
$source = $_POST['src'] ?? null;
//$img = $_POST['img'] ?? null;
$errors = [null, null];
$gw = new CharacterGateway($co);
$mdl = new CharacterModel($gw);
$character = $mdl -> getCharacterById($character);
$gw = new SourceGateway($co);
$mdl = new SourceModel($gw);
$source = $mdl -> getSourceById($source);
$nameSrc = $this->srcMod->getSourceById($source)->getTitle();
$nameChar = $this->caMod->getCharacterById($character)->getName();
if (!$character)
$errors[0] = "Personnage inexistant";
if (!$source)
$errors[1] = "Source inexistante";
if ($errors[0] || $errors[1])
{
global $twig;
$this->submit();
exit();
$this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user'])));
$this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar));
}
$gw = new QuoteGateway($co);
$mdl = new QuoteModel($gw);
//$mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter());
return [$content, $_POST['character'], $_POST['src']];
}
return null;
}
/**
@ -386,6 +384,8 @@ class UserControler {
global $vues;
$src = true;
$char = true;
$srcId = null;
$charId = null;
require_once $vues['create'];
exit();
}
@ -393,6 +393,8 @@ class UserControler {
global $vues;
$src = true;
$char = false;
$srcId = null;
$charId = $_POST['character'];
require_once $vues['create'];
exit();
}
@ -400,32 +402,25 @@ class UserControler {
global $vues;
$src = false;
$char = true;
$srcId = $_POST['src'];
$charId = null;
require_once $vues['create'];
exit();
}
if($_POST)
$recap = $this -> toSubmit();
if ($recap)
{
$this -> recapSubmitQuote($recap);
$recap = $this -> toSubmit($_POST['content'],$_POST['character'],$_POST['src']);
}
public function recapSubmitQuote(array $recap){
global $vues;
require_once($vues["recap"]);
}
// ===================== SUBMIT QUOTE FUNCTION =====================
/**
* @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{
public function getIdOfUser() : ?int
{
if (isset($_SESSION['user']))
{
global $co;
@ -439,17 +434,18 @@ class UserControler {
public function add(){
global $vues;
var_dump($_POST);
global $vues, $repImg;
$error = [];
$src = false;
$char = false;
var_dump($_FILES);
if($_POST['req'] == "both"){
$src = true;
$char = true;
}
elseif($_POST['req'] == "src"){
$src = true;
$char = false;
$type = array("Movie","Serie","VideoGame","Anime");
if($_POST['req'] == "src" or $src == true){
$type = array("movie","serie","video-game","anime");
if(Verification::verifNotNull($_POST["titre"])){
$_POST["titre"] = Verification::verifChar($_POST["titre"]);
if($this->srcMod->existSource($_POST["titre"],$_POST["type"])){
@ -460,8 +456,6 @@ class UserControler {
$error[] = "Le titre doit être définit";
}
if(Verification::verifNotNull($_POST["date"])){
$src = true;
$char = false;
$_POST["date"] = Verification::verifChar($_POST["date"]);
if(intval($_POST["date"],10) < 1850 or intval ( $ _POST [ " date " ] , 10 ) > date( "Y", time() )){
$error[] = "La date est invalide";
@ -480,30 +474,85 @@ class UserControler {
$error[] = "Le type doit être définit";
}
}
elseif($_POST['req'] == "char"){
$src = false;
$char = true;
if(Verification::verifNotNull($_POST[""])){
if($_POST['req'] == "char" or $char == true){
if(Verification::verifNotNull($_POST["name"])){
$_POST["name"] = Verification::verifChar($_POST["name"]);
}
else{
$error[] = "Le nom doit être définit";
}
// upload de la photo
if (isset($_FILES['avatar'])) {
$tabExtension = explode('.', $_FILES['avatar']['name']);
$extension = strtolower(end($tabExtension));
$extensions = ['jpg', 'png', 'jpeg'];
if(in_array($extension, $extensions)){
move_uploaded_file($_FILES['avatar']['tmp_name'], $repImg.$_FILES['avatar']['name']);
$filePath = $repImg.$_FILES['avatar']['name'];
}
else{
$error[] = "Mauvaise extension";
exit();
}
}
else{
$error[] = "Aucune photo";
}
}
if($error == []){
$recap['content'] = $_POST['content'];
if($_POST['req'] == "both"){
$this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
$idImg = $this->iMod->createImgModelWithoutId($filePath);
$this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
$idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
$idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
}
elseif($_POST['req'] == "src"){
$this->srcMod->createSource($_POST["titre"], $_POST["date"], $_POST["type"]);
$this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
$idC = Verification::VerifChar($_POST["character"]);
$idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
}
elseif($_POST['req'] == "char"){
$idImg = $this->iMod->createImgModelWithoutId($filePath);
$this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
$idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
$idS = Verification::VerifChar($_POST["src"]);
}
$this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS);
}
else{
require_once($vues["create"]);
var_dump($error);
}
}
// Quiz aléatoire
// argument = Langue / type question / type reponse
public function quizAleatoire(){
global $vues;
if(!isset($_POST["nbVie"])){
$vie = 3;
}
$question = $questMod->getRandomQuestion([$_POST["questionType"],$_POST["awnserType"]],$_POST["langue"]);
addTab($question);
if($question == null){
$erreur = [501,"Erreur serveur lors de l'obtention de la question"];
$require_once($vues["erreur"]);
}
else{
$require_once($vues['quiz']);
}
}
public function questionSuivantAleatoire(){
}
// ===================== DELETE ACCOUNT FUNCTION =====================