Merge pull request 'Long-fix Pull Request' (#35) from Long-fix into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #35
pull/37/head
Jade VAN BRABANDT 1 year ago
commit bc67e2fe0d

@ -5,16 +5,22 @@ class Administrator
private int $id; private int $id;
private string $username; private string $username;
private string $hashedPassword; private string $hashedPassword;
public function __construct(string $username, string $password) public function __construct(int $id,string $username, string $password)
{ {
$this->id = $id;
$this->username = $username; $this->username = $username;
try { try {
$this->hashedPassword = $hashedPassword = md5($password); $this->hashedPassword = md5($password);
} catch (Exception $e) { } catch (Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
} }
} }
public function getId(): int
{
return $this->id;
}
public function getUsername() public function getUsername()
{ {

@ -6,12 +6,17 @@ class Answer
private string $content; private string $content;
private int $idQuestion; private int $idQuestion;
public function __construct(string $content, int $idQuestion) public function __construct(int $id, string $content, int $idQuestion)
{ {
$this->id = $id;
$this->content = $content; $this->content = $content;
$this->idQuestion = $idQuestion; $this->idQuestion = $idQuestion;
} }
public function getId(): int
{
return $this->id;
}
public function getContent() public function getContent()
{ {
return $this->content; return $this->content;

@ -5,11 +5,17 @@ class Chapter
private int $id; private int $id;
private string $name; private string $name;
public function __construct(string $name) public function __construct(int $id,string $name)
{ {
$this->id = $id;
$this->name = $name; $this->name = $name;
} }
public function getId()
{
return $this->id;
}
public function getName() public function getName()
{ {
return $this->name; return $this->name;

@ -15,6 +15,11 @@ class Lobby
$this->nbPlayer = $nbPlayer; $this->nbPlayer = $nbPlayer;
} }
public function getId(): int
{
return $this->id;
}
public function getName() public function getName()
{ {
return $this->name; return $this->name;

@ -17,6 +17,11 @@ class Player
} }
} }
public function getId(): int
{
return $this->id;
}
public function getNickname() public function getNickname()
{ {
return $this->nickname; return $this->nickname;

@ -9,59 +9,69 @@ class Question
private int $nbFails; private int $nbFails;
private int $idAnswerGood; private int $idAnswerGood;
public function __construct(string $content, int $idChapter, int $idAnswerGood = -1, int $difficulty = 1, int $nbFails = 0) public function __construct(
{ int $id,
string $content,
int $idChapter,
int $idAnswerGood = -1,
int $difficulty = 1,
int $nbFails = 0
) {
$this->id = $id;
$this->content = $content; $this->content = $content;
$this->idChapter = $idChapter; $this->idChapter = $idChapter;
if ($idAnswerGood != -1) { $this->idAnswerGood = ($idAnswerGood !== -1) ? $idAnswerGood : -1;
$this->idAnswerGood = $idAnswerGood;
}
$this->difficulty = $difficulty; $this->difficulty = $difficulty;
$this->nbFails = $nbFails; $this->nbFails = $nbFails;
} }
public function getContent() public function getId(): int
{
return $this->id;
}
public function getContent(): string
{ {
return $this->content; return $this->content;
} }
public function getIdChapter() public function getIdChapter(): int
{ {
return $this->idChapter; return $this->idChapter;
} }
public function getIdAnswerGood() public function getIdAnswerGood(): int
{ {
return $this->idAnswerGood; return $this->idAnswerGood;
} }
public function setContent(string $content) public function getDifficulty(): int
{ {
$this->content = $content; return $this->difficulty;
} }
public function setIdAnswerGood(int $idAnswerGood) public function setContent(string $content): void
{ {
$this->idAnswerGood = $idAnswerGood; $this->content = $content;
} }
public function getDifficulty() public function setIdAnswerGood(int $idAnswerGood): void
{ {
return $this->difficulty; $this->idAnswerGood = $idAnswerGood;
} }
public function setDifficulty(int $difficulty) public function setDifficulty(int $difficulty): void
{ {
$this->difficulty = $difficulty; $this->difficulty = $difficulty;
} }
public function getNbFails() public function getNbFails(): int
{ {
return $this->nbFails; return $this->nbFails;
} }
public function setNbFails(int $nbFails) public function setNbFails(int $nbFails): void
{ {
$this->nbFails = $nbFails; $this->nbFails = $nbFails;
} }
} }

@ -14,14 +14,14 @@ class ControllerAdminQuestions
global $dns, $user, $pass, $vues, $twig; global $dns, $user, $pass, $vues, $twig;
session_start(); session_start();
try { try {
if($_SESSION["idAdminConnected"] != null){ if ($_SESSION["idAdminConnected"] != null) {
$this->twig =$twig; $this->twig = $twig;
$this->vues = $vues; $this->vues = $vues;
$this->mdQuestion = new ModelQuestion(); $this->mdQuestion = new ModelQuestion();
$this->mdAnswer = new ModelAnswer(); $this->mdAnswer = new ModelAnswer();
$this->mdChapter = new ModelChapter(); $this->mdChapter = new ModelChapter();
$questions = array();
$questions = $this->mdQuestion->getQuestions(); $questions = $this->mdQuestion->getQuestions();
$chapters = $this->mdChapter->getChapters(); $chapters = $this->mdChapter->getChapters();
@ -29,8 +29,7 @@ class ControllerAdminQuestions
'questions' => $questions, 'questions' => $questions,
'chapters' => $chapters, 'chapters' => $chapters,
]); ]);
} } else {
else {
header("Location:/login"); header("Location:/login");
} }
} catch (PDOException $e) { } catch (PDOException $e) {
@ -40,12 +39,14 @@ class ControllerAdminQuestions
} }
} }
function delete($param) { function delete($param)
{
$this->mdQuestion->deleteQuestionByID($param["id"]); $this->mdQuestion->deleteQuestionByID($param["id"]);
header("Location:/admin/questions"); header("Location:/admin/questions");
} }
function add($param) { function add($param)
{
$content = $_POST['content']; $content = $_POST['content'];
$idChapter = intval($_POST['idChapter']); $idChapter = intval($_POST['idChapter']);
$AnswersPost = array(); $AnswersPost = array();
@ -58,6 +59,7 @@ class ControllerAdminQuestions
$Question = [ $Question = [
'content' => $content, 'content' => $content,
'idchapter' => $idChapter, 'idchapter' => $idChapter,
'idanswergood' => $correctAnswer,
'difficulty' => 1, 'difficulty' => 1,
'nbfails' => 0, 'nbfails' => 0,
]; ];
@ -85,16 +87,15 @@ class ControllerAdminQuestions
'idanswergood' => $answersId[$correctAnswer], 'idanswergood' => $answersId[$correctAnswer],
]; ];
$this->mdQuestion->updateQuestion($idquestion,$Question); $this->mdQuestion->updateQuestion($idquestion, $Question);
header("Location:/admin/questions"); header("Location:/admin/questions");
} }
function updatemodal($param) { function updatemodal($param)
{
$question = $this->mdQuestion->getQuestionByID($param["id"]); $question = $this->mdQuestion->getQuestionByID($param["id"]);
$answers = array();
$answers = $this->mdAnswer->getAnswersByIDQuestions($param["id"]); $answers = $this->mdAnswer->getAnswersByIDQuestions($param["id"]);
$chapters = $this->mdChapter->getChapters(); $chapters = $this->mdChapter->getChapters();
@ -106,12 +107,12 @@ class ControllerAdminQuestions
]); ]);
} }
function update($param) { function update($param)
{
$id = $_POST['id']; $id = intval($_POST['id']);
$content = $_POST['content']; $content = $_POST['content'];
$idChapter = intval($_POST['idChapter']); $idChapter = intval($_POST['idChapter']);
$correctAnswer = intval($_POST['correctAnswer']); $correctAnswer = intval($_POST['correctAnswer']);
$answersId = array(); $answersId = array();
@ -125,24 +126,25 @@ class ControllerAdminQuestions
$answers[1] = $_POST['answer2']; $answers[1] = $_POST['answer2'];
$answers[2] = $_POST['answer3']; $answers[2] = $_POST['answer3'];
$answers[3] = $_POST['answer4']; $answers[3] = $_POST['answer4'];
$Question = [ $questionDataArray = [
'content' => $content, 'content' => $content,
'idchapter' => $idChapter, 'idchapter' => $idChapter,
'idanswergood' => $answersId[$correctAnswer], 'idanswergood' => $answersId[$correctAnswer],
]; ];
$this->mdQuestion->updateQuestion($id, $Question); $this->mdQuestion->updateQuestion($id, $questionDataArray);
for ($i = 0; $i <= 3; $i++) { for ($i = 0; $i <= 3; $i++) {
$Answers[] = [ $answersDataArray[] = [
'content' => $answers[$i], 'content' => $answers[$i],
'id' => $id, 'id' => $id,
]; ];
} }
for ($i = 0; $i <= 3; $i++) { for ($i = 0; $i <= 3; $i++) {
$this->mdAnswer->updateAnswer($answersId[$i],$Answers[$i]); $this->mdAnswer->updateAnswer($answersId[$i], $answersDataArray[$i]);
} }
header("Location:/admin/questions"); header("Location:/admin/questions");

@ -17,7 +17,6 @@ class ControllerUser
global $vues, $twig; global $vues, $twig;
session_start(); session_start();
try { try {
$this->twig = $twig; $this->twig = $twig;
$this->vues = $vues; $this->vues = $vues;
@ -89,12 +88,11 @@ class ControllerUser
function verifySingleplayer() function verifySingleplayer()
{ {
$_SESSION["Score"] = 0; $_SESSION["Score"] = 0;
$_SESSION["PrevTime"] = new DateTime('now');
$difficulty = $_POST['difficulty']; $difficulty = $_POST['difficulty'];
$chapter = $_POST['chapter']; $chapter = $_POST['chapter'];
$difficultyIsOk = TRUE; $difficultyIsOk = TRUE;
$chapterIsOk = TRUE; $chapterIsOk = TRUE;
if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) { if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) {
$_SESSION["error"] = "Valeur de difficulté invalide"; $_SESSION["error"] = "Valeur de difficulté invalide";
$difficultyIsOk = FALSE; $difficultyIsOk = FALSE;
@ -104,16 +102,19 @@ class ControllerUser
$_SESSION["error"] = "Valeur de chapitre invalide"; $_SESSION["error"] = "Valeur de chapitre invalide";
$chapterIsOk = FALSE; $chapterIsOk = FALSE;
} }
if ($difficultyIsOk and $chapterIsOk) { if ($difficultyIsOk and $chapterIsOk) {
$_SESSION["PrevTime"] = new DateTime('now');
$_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
foreach ($_SESSION["Questions"] as &$question) { $_SESSION["Answers"] = array();
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']); foreach ($_SESSION["Questions"] as $question) {
$question['answers'] = $answers; $answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId());
var_dump("i"); $_SESSION["Answers"][] = $answers;
} }
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $_SESSION["Questions"], 'questions' => $_SESSION["Questions"],
'numQuestion' => 0, 'numQuestion' => 0,
'answerss' => $_SESSION["Answers"],
]); ]);
} else { } else {
$_SESSION["error"] = "Valeur de choix de thème invalide"; $_SESSION["error"] = "Valeur de choix de thème invalide";
@ -132,12 +133,13 @@ class ControllerUser
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $_SESSION["Questions"], 'questions' => $_SESSION["Questions"],
'numQuestion' => $numQuestion, 'numQuestion' => $numQuestion,
'answerss' => $_SESSION["Answers"],
]); ]);
} else { } else {
$answerContent = $_SESSION["Questions"][$numQuestion]['answers'][$answerNumber]['content']; $answerContent = $_SESSION["Answers"][$numQuestion][$answerNumber]->getContent();
$_SESSION["Questions"][$numQuestion]['playerAnswersContent'] = $answerContent; $_SESSION["playerAnswersContent"][$numQuestion] = $answerContent;
if ($_SESSION["Questions"][$numQuestion]['idanswergood'] == $_SESSION["Questions"][$numQuestion]['answers'][$answerNumber]['id']) { if ($_SESSION["Questions"][$numQuestion]->getIdAnswerGood() == $_SESSION["Answers"][$numQuestion][$answerNumber]->getId()) {
$time = $_SESSION["PrevTime"]->diff($_SESSION["CurrTime"]); $time = $_SESSION["PrevTime"]->diff($_SESSION["CurrTime"]);
$_SESSION["Score"] = $_SESSION["Score"] + 80 + 40 * ((30 - $time->s) / 100 * 10 / 3); $_SESSION["Score"] = $_SESSION["Score"] + 80 + 40 * ((30 - $time->s) / 100 * 10 / 3);
} }
@ -147,15 +149,33 @@ class ControllerUser
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $_SESSION["Questions"], 'questions' => $_SESSION["Questions"],
'numQuestion' => $numQuestion + 1, 'numQuestion' => $numQuestion + 1,
'answerss' => $_SESSION["Answers"],
]); ]);
} else { } else {
$Final = array();
$Final[]["Question"] = array();
$Final[]["goodAnswer"] = array();
$Final[]["PlayerAnswer"] = array();
$c=0;
foreach ($_SESSION["Questions"] as &$question) { foreach ($_SESSION["Questions"] as &$question) {
$answer = $this->mdAnswer->getAnswerByID($question['idanswergood']); $answer = $this->mdAnswer->getAnswerByID($question->getIdAnswerGood());
$question['goodAnswersContent'] = $answer['content']; $Final[$c]["goodAnswer"] = $answer->getContent();
$c=$c+1;
}
$c=0;
foreach ($_SESSION["Questions"] as $question) {
$Final[$c]["Question"] = $question->getContent();
$c=$c+1;
}
$c=0;
foreach ($_SESSION["playerAnswersContent"] as $answer)
{
$Final[$c]["PlayerAnswer"] = $answer;
$c=$c+1;
} }
echo $this->twig->render($this->vues["viewScore"], [ echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"], 'score' => $_SESSION["Score"],
'questions' => $_SESSION["Questions"], 'Final' => $Final,
]); ]);
} }
} }
@ -168,15 +188,18 @@ class ControllerUser
echo $this->twig->render($this->vues["singleplayer"], [ echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $_SESSION["Questions"], 'questions' => $_SESSION["Questions"],
'numQuestion' => $numQuestion + 1, 'numQuestion' => $numQuestion + 1,
'answerss' => $_SESSION["Answers"],
]); ]);
} else { } else {
$goodAnswer = array();
foreach ($_SESSION["Questions"] as &$question) { foreach ($_SESSION["Questions"] as &$question) {
$answer = $this->mdAnswer->getAnswerByID($question['idAnswerGood']); $answer = $this->mdAnswer->getAnswerByID($question['idanswergood']);
$question['GoodAnswersContent'] = $answer['content']; $goodAnswer[] = $answer->getContent();
} }
echo $this->twig->render($this->vues["viewScore"], [ echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"], 'score' => $_SESSION["Score"],
'questions' => $_SESSION["Questions"], 'questions' => $_SESSION["Questions"],
'answerss' => $_SESSION["Answers"],
]); ]);
} }
} }

@ -30,7 +30,7 @@ class GatewayAdministrator
if ($results == NULL) { if ($results == NULL) {
return false; return false;
} }
return new Administrator($results[0]['id'], $results[0]['username'], $results[0]['hashedPassword']); return $results[0];
} }
public function getAdministratorByID(int $id) public function getAdministratorByID(int $id)
@ -47,11 +47,11 @@ class GatewayAdministrator
$query = "SELECT * FROM administrators"; $query = "SELECT * FROM administrators";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results; return $results;
} }
public function updateAdministrator($id,$administrator) public function updateAdministrator($id, $administrator)
{ {
$query = "UPDATE administrators SET username = :username, password = :password WHERE id = :id;"; $query = "UPDATE administrators SET username = :username, password = :password WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
@ -81,7 +81,7 @@ class GatewayAdministrator
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results[0]; return $results[0];
} }
} }

@ -47,7 +47,6 @@ class GatewayAnswer
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results; return $results;
} }

@ -57,17 +57,16 @@ class GatewayChapter
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
} }
public function verifyChapter($idChapter) public function verifyChapter($id)
{ {
$query = "SELECT chapters.id FROM chapters WHERE id = :id"; $query = "SELECT chapters.id FROM chapters WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':id' => array($idChapter, PDO::PARAM_STR), ':id' => array($id, PDO::PARAM_STR),
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results[0]; return $results[0];
} }
} }

@ -24,7 +24,7 @@ class GatewayLobby
); );
} }
public function getLobbys() public function getLobbies()
{ {
$query = "SELECT * FROM Lobbies;"; $query = "SELECT * FROM Lobbies;";
$this->con->executeQuery($query); $this->con->executeQuery($query);
@ -32,11 +32,7 @@ class GatewayLobby
if ($results == NULL) { if ($results == NULL) {
return false; return false;
} }
$lobbys = array(); return $results;
foreach ($results as $row) {
$lobbys[] = new Lobby($row['id'], $row['name'], $row['password'], $row['nbPlayer']);
}
return $lobbys;
} }
public function getLobbyByName($name) public function getLobbyByName($name)
@ -47,7 +43,7 @@ class GatewayLobby
if ($results == NULL) { if ($results == NULL) {
return false; return false;
} }
return new Lobby($results[0]['id'], $results[0]['name'], $results[0]['password'], $results[0]['nbPlayer']); return $results[0];
} }

@ -31,7 +31,7 @@ class GatewayPlayer
if ($results == NULL) { if ($results == NULL) {
return false; return false;
} }
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']); return $results[0];
} }
public function getPlayerByID(int $id) public function getPlayerByID(int $id)
@ -42,7 +42,7 @@ class GatewayPlayer
if ($results == NULL) { if ($results == NULL) {
return false; return false;
} }
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']); return $results[0];
} }
public function getPlayers() public function getPlayers()
@ -50,11 +50,11 @@ class GatewayPlayer
$query = "SELECT * FROM players"; $query = "SELECT * FROM players";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results; return $results;
} }
public function updatePlayer($player) public function updatePlayer($id, $player)
{ {
$query = "UPDATE players SET nickname = :nickname, hashedPassword = :hashedPassword WHERE id = :id;"; $query = "UPDATE players SET nickname = :nickname, hashedPassword = :hashedPassword WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
@ -89,7 +89,7 @@ class GatewayPlayer
) )
); );
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results[0]; return $results[0];
} }
} }

@ -40,19 +40,18 @@ class GatewayQuestion
$query = "SELECT * FROM questions"; $query = "SELECT * FROM questions";
$this->con->executeQuery($query); $this->con->executeQuery($query);
$results = $this->con->getResults(); $results = $this->con->getResults();
return $results; return $results;
} }
public function updateQuestion($id, $question) public function updateQuestion($id, $questionDataArray)
{ {
$query = "UPDATE questions SET content = :content, idchapter = :idchapter, idanswergood = :idanswergood WHERE id = :id;"; $query = "UPDATE questions SET content = :content, idchapter = :idchapter, idanswergood = :idanswergood WHERE id = :id;";
$this->con->executeQuery( $this->con->executeQuery(
$query, $query,
array( array(
':content' => array($question['content'], PDO::PARAM_STR), ':content' => array($questionDataArray['content'], PDO::PARAM_STR),
':idchapter' => array($question['idchapter'], PDO::PARAM_INT), ':idchapter' => array($questionDataArray['idchapter'], PDO::PARAM_INT),
':idanswergood' => array($question['idanswergood'], PDO::PARAM_INT), ':idanswergood' => array($questionDataArray['idanswergood'], PDO::PARAM_INT),
':id' => array($id, PDO::PARAM_INT), ':id' => array($id, PDO::PARAM_INT),
) )
); );

@ -16,19 +16,25 @@ class ModelAdministrator
public function getAdministratorByID($id) public function getAdministratorByID($id)
{ {
$administrator = $this->gwAdministrator->getAdministratorByID($id); $administratorDataArray = $this->gwAdministrator->getAdministratorByID($id);
$administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]);
return $administrator; return $administrator;
} }
public function getAdministrators() public function getAdministrators()
{ {
$administrators = $this->gwAdministrator->getAdministrators(); $administratorsDataArray = $this->gwAdministrator->getAdministrators();
$administrators = array();
foreach ($administratorsDataArray as $administratorDataArray) {
$administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]);
$administrators[] = $administrator;
}
return $administrators; return $administrators;
} }
public function updateAdministrator($id,$administrator) public function updateAdministrator($id, $administrator)
{ {
$this->gwAdministrator->updateAdministrator($id,$administrator); $this->gwAdministrator->updateAdministrator($id, $administrator);
} }
public function deleteAdministratorByID($id) public function deleteAdministratorByID($id)

@ -17,13 +17,19 @@ class ModelAnswer
function getAnswerByID($id) function getAnswerByID($id)
{ {
$answer = $this->gwAnswer->getAnswerByID($id); $answerDataArray = $this->gwAnswer->getAnswerByID($id);
$answer = new Answer($id, $answerDataArray['content'], $answerDataArray['idquestion']);
return $answer; return $answer;
} }
function getAnswersByIDQuestions($idQuestion) function getAnswersByIDQuestions($idQuestion)
{ {
$answers = $this->gwAnswer->getAnswersByIDQuestions($idQuestion); $answersDataArray = $this->gwAnswer->getAnswersByIDQuestions($idQuestion);
$answers = array();
foreach ($answersDataArray as $answerDataArray) {
$answer = new Answer($answerDataArray['id'], $answerDataArray['content'], $idQuestion);
$answers[] = $answer;
}
return $answers; return $answers;
} }

@ -11,29 +11,35 @@ class ModelChapter
function getChapters() function getChapters()
{ {
$chapters = $this->gwChapter->getChapters(); $chaptersDataArray = $this->gwChapter->getChapters();
$chapters = array();
foreach ($chaptersDataArray as $chapterDataArray) {
$chapter = new Chapter($chapterDataArray['id'],$chapterDataArray["name"]);
$chapters[] = $chapter;
}
return $chapters; return $chapters;
} }
function deleteChapter($id) function deleteChapter($id)
{ {
$this->gwChapter->deleteChapter($id); $this->gwChapter->deleteChapter($id);
} }
function addChapter($chapter) function addChapter($chapter)
{ {
$this->gwChapter->addChapter($chapter); $this->gwChapter->addChapter($chapter);
} }
function getChapterByID($id) function getChapterByID($id)
{ {
$chapter = $this->gwChapter->getChapterByID($id); $chapterDataArray = $this->gwChapter->getChapterByID($id);
$chapter = new Chapter($chapterDataArray['id'],$chapterDataArray['name']);
return $chapter; return $chapter;
} }
function updateChapter($id,$chapter) function updateChapter($id, $chapter)
{ {
$this->gwChapter->updateChapter($id,$chapter); $this->gwChapter->updateChapter($id, $chapter);
} }
public function verifyChapter($chapter) public function verifyChapter($chapter)
{ {

@ -14,9 +14,19 @@ class ModelLobby
$this->gwLobby->addLobby($lobby); $this->gwLobby->addLobby($lobby);
} }
public function getlobbies() public function getLobbies()
{ {
$lobbies = $this->gwLobby->getlobbies(); $lobbiesDataArray = $this->gwLobby->getLobbies();
return $lobbies; $lobbies = array();
foreach ($lobbiesDataArray as $lobbyDataArray) {
$lobby = new Lobby(
intval($lobbyDataArray['id']),
$lobbyDataArray['name'],
$lobbyDataArray['password'],
intval($lobbyDataArray['nbPlayer'])
);
$lobbies[] = $lobby;
return $lobbies;
}
} }
} }

@ -16,13 +16,13 @@ class ModelPlayer
public function getPlayerByID($id) public function getPlayerByID($id)
{ {
$player = $this->gwPlayer->getPlayerByID($id); $playerDataArray = $this->gwPlayer->getPlayerByID($id);
return $player; $player = new Player($playerDataArray["id"], $playerDataArray["nickname"], $playerDataArray["password"]);
} }
public function updatePlayer($id,$player) public function updatePlayer($id, $player)
{ {
$this->gwPlayer->updatePlayer($id,$player); $this->gwPlayer->updatePlayer($id, $player);
} }
public function deletePlayerByID($id) public function deletePlayerByID($id)

@ -10,37 +10,72 @@ class ModelQuestion
$this->gwQuestion = new GatewayQuestion(); $this->gwQuestion = new GatewayQuestion();
} }
function getQuestions() function getQuestions() : array
{ {
$questions = $this->gwQuestion->getQuestions(); $questionsDataArray = $this->gwQuestion->getQuestions();
$questions = array();
foreach ($questionsDataArray as $questionDataArray) {
$question = new Question(
intval($questionDataArray['id']),
$questionDataArray['content'],
intval($questionDataArray['idchapter']),
intval($questionDataArray['idanswergood']),
intval($questionDataArray['difficulty']),
intval($questionDataArray['nbfails'])
);
$questions[] = $question;
}
return $questions; return $questions;
} }
function deleteQuestionByID($id) function deleteQuestionByID($id)
{ {
$this->gwQuestion->deleteQuestionByID($id); $this->gwQuestion->deleteQuestionByID($id);
} }
function addQuestion($Question) function addQuestion($questionsDataArray)
{ {
$questionId = $this->gwQuestion->addQuestion($Question); $questionId = $this->gwQuestion->addQuestion($questionsDataArray);
return $questionId; return $questionId;
} }
function getQuestionByID($id) function getQuestionByID($id)
{ {
$question = $this->gwQuestion->getQuestionByID($id); $questionDataArray = $this->gwQuestion->getQuestionByID($id);
$question = new Question(
intval($questionDataArray['id']),
$questionDataArray['content'],
intval($questionDataArray['idchapter']),
intval($questionDataArray['idanswergood']),
intval($questionDataArray['difficulty']),
intval($questionDataArray['nbfails'])
);
return $question; return $question;
} }
function updateQuestion($id, $Question) function updateQuestion($id, $questionDataArray)
{ {
$this->gwQuestion->updateQuestion($id, $Question); $this->gwQuestion->updateQuestion($id, $questionDataArray);
} }
function getQuestionsByChapterAndDifficulty($chapter, $difficulty) function getQuestionsByChapterAndDifficulty($chapter, $difficulty)
{ {
$this->questions = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty); $questionsDataArray = $this->gwQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
$this->questions = array();
foreach ($questionsDataArray as $questionDataArray) {
$question = new Question(
intval($questionDataArray['id']),
$questionDataArray['content'],
intval($questionDataArray['idchapter']),
intval($questionDataArray['idanswergood']),
intval($questionDataArray['difficulty']),
intval($questionDataArray['nbfails'])
);
$this->questions[] = $question;
}
return $this->questions; return $this->questions;
} }
} }

@ -54,7 +54,7 @@
id.value = "{{ administrator.id }}"; id.value = "{{ administrator.id }}";
username.value = "{{ administrator.username }}"; username.value = "{{ administrator.username }}";
password.value = "{{ administrator.password }}"; password.value = "{{ administrator.hashedPassword }}";
modal.show(); modal.show();
} }

@ -100,7 +100,7 @@
answer1.value = "{{ answers[0].content }}"; answer1.value = "{{ answers[0].content }}";
answer2.value = "{{ answers[1].content }}"; answer2.value = "{{ answers[1].content }}";
answer3.value = "{{ answers[2].content }}"; answer3.value = "{{ answers[2].content }}";
answer4.value = "{{ answers[3].content }}"; answer4.value = "{{ answers[3].content }}";
modal.show(); modal.show();
} }

@ -23,7 +23,7 @@
<div class="container text-center text-white"> <div class="container text-center text-white">
<div class="container border border-white rounded mt-5"> <div class="container border border-white rounded mt-5">
<p class="fs-2"> <p class="fs-2">
{{ questions[numQuestion]['content'] }} {{ questions[numQuestion].content }}
<br> <br>
Question n° : {{ numQuestion+1 }}/10 Question n° : {{ numQuestion+1 }}/10
</p> </p>
@ -36,13 +36,13 @@
<div class="col pt-5"> <div class="col pt-5">
<input type="radio" class="btn-check" name="answer" value="0" id="answer1" autocomplete="off" required> <input type="radio" class="btn-check" name="answer" value="0" id="answer1" autocomplete="off" required>
<label class="btn fs-2 container text-white" for="answer1" style="background-color:blue;"> <label class="btn fs-2 container text-white" for="answer1" style="background-color:blue;">
{{ questions[numQuestion]['answers'][0]['content'] }} {{ answerss[numQuestion][0].content }}
</label> </label>
</div> </div>
<div class="col pt-5"> <div class="col pt-5">
<input type="radio" class="btn-check" name="answer" value="1" id="answer2" autocomplete="off"> <input type="radio" class="btn-check" name="answer" value="1" id="answer2" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer2" style="background-color:green;"> <label class="btn fs-2 container text-white" for="answer2" style="background-color:green;">
{{ questions[numQuestion]['answers'][1]['content'] }} {{ answerss[numQuestion][1].content }}
</label> </label>
</div> </div>
</div> </div>
@ -50,13 +50,13 @@
<div class="col pt-5"> <div class="col pt-5">
<input type="radio" class="btn-check" name="answer" value="2" id="answer3" autocomplete="off"> <input type="radio" class="btn-check" name="answer" value="2" id="answer3" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer3" style="background-color:red;"> <label class="btn fs-2 container text-white" for="answer3" style="background-color:red;">
{{ questions[numQuestion]['answers'][2]['content'] }} {{ answerss[numQuestion][2].content }}
</label> </label>
</div> </div>
<div class="col pt-5"> <div class="col pt-5">
<input type="radio" class="btn-check" name="answer" value="3" id="answer4" autocomplete="off"> <input type="radio" class="btn-check" name="answer" value="3" id="answer4" autocomplete="off">
<label class="btn fs-2 container text-white" for="answer4" style="background-color:orange;"> <label class="btn fs-2 container text-white" for="answer4" style="background-color:orange;">
{{ questions[numQuestion]['answers'][3]['content'] }} {{ answerss[numQuestion][3].content }}
</label> </label>
</div> </div>
</div> </div>

@ -17,15 +17,15 @@
</div> </div>
<div class="d-flex flex-column align-items-center text-light fs-3"> <div class="d-flex flex-column align-items-center text-light fs-3">
{% for question in questions %} {% for f in Final %}
<p> <p>
Question : {{ question['content'] }} Question : {{ f['Question'] }}
</p> </p>
<p> <p>
Bonne réponse : {{ question['goodAnswersContent'] }} Bonne réponse : {{ f['goodAnswer'] }}
</p> </p>
<p> <p>
Votre réponse : {{ question['playerAnswersContent'] }} Votre réponse : {{ f['PlayerAnswer'] }}
</p> </p>
{% endfor %} {% endfor %}

@ -34,7 +34,7 @@ class Autoload
{ {
global $rep; global $rep;
$filename = $class . '.php'; $filename = $class . '.php';
$dir = array('models/', './', 'usages/', 'controllers/', 'gateways/', 'update/', 'vues/'); $dir = array('models/', './', 'usages/', 'controllers/', 'gateways/', 'update/', 'vues/', 'class/');
foreach ($dir as $d) { foreach ($dir as $d) {
$file = $rep . $d . $filename; $file = $rep . $d . $filename;
//echo $file; //echo $file;

Loading…
Cancel
Save