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

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

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

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

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

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

@ -9,58 +9,68 @@ class Question
private int $nbFails;
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->idChapter = $idChapter;
if ($idAnswerGood != -1) {
$this->idAnswerGood = $idAnswerGood;
}
$this->idAnswerGood = ($idAnswerGood !== -1) ? $idAnswerGood : -1;
$this->difficulty = $difficulty;
$this->nbFails = $nbFails;
}
public function getContent()
public function getId(): int
{
return $this->id;
}
public function getContent(): string
{
return $this->content;
}
public function getIdChapter()
public function getIdChapter(): int
{
return $this->idChapter;
}
public function getIdAnswerGood()
public function getIdAnswerGood(): int
{
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;
}
public function getNbFails()
public function getNbFails(): int
{
return $this->nbFails;
}
public function setNbFails(int $nbFails)
public function setNbFails(int $nbFails): void
{
$this->nbFails = $nbFails;
}

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

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

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

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

@ -57,17 +57,16 @@ class GatewayChapter
$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(
$query,
array(
':id' => array($idChapter, PDO::PARAM_STR),
':id' => array($id, PDO::PARAM_STR),
)
);
$results = $this->con->getResults();
return $results[0];
}
}

@ -24,7 +24,7 @@ class GatewayLobby
);
}
public function getLobbys()
public function getLobbies()
{
$query = "SELECT * FROM Lobbies;";
$this->con->executeQuery($query);
@ -32,11 +32,7 @@ class GatewayLobby
if ($results == NULL) {
return false;
}
$lobbys = array();
foreach ($results as $row) {
$lobbys[] = new Lobby($row['id'], $row['name'], $row['password'], $row['nbPlayer']);
}
return $lobbys;
return $results;
}
public function getLobbyByName($name)
@ -47,7 +43,7 @@ class GatewayLobby
if ($results == NULL) {
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) {
return false;
}
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
return $results[0];
}
public function getPlayerByID(int $id)
@ -42,7 +42,7 @@ class GatewayPlayer
if ($results == NULL) {
return false;
}
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
return $results[0];
}
public function getPlayers()
@ -54,7 +54,7 @@ class GatewayPlayer
return $results;
}
public function updatePlayer($player)
public function updatePlayer($id, $player)
{
$query = "UPDATE players SET nickname = :nickname, hashedPassword = :hashedPassword WHERE id = :id;";
$this->con->executeQuery(

@ -40,19 +40,18 @@ class GatewayQuestion
$query = "SELECT * FROM questions";
$this->con->executeQuery($query);
$results = $this->con->getResults();
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;";
$this->con->executeQuery(
$query,
array(
':content' => array($question['content'], PDO::PARAM_STR),
':idchapter' => array($question['idchapter'], PDO::PARAM_INT),
':idanswergood' => array($question['idanswergood'], PDO::PARAM_INT),
':content' => array($questionDataArray['content'], PDO::PARAM_STR),
':idchapter' => array($questionDataArray['idchapter'], PDO::PARAM_INT),
':idanswergood' => array($questionDataArray['idanswergood'], PDO::PARAM_INT),
':id' => array($id, PDO::PARAM_INT),
)
);

@ -16,19 +16,25 @@ class ModelAdministrator
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;
}
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;
}
public function updateAdministrator($id,$administrator)
public function updateAdministrator($id, $administrator)
{
$this->gwAdministrator->updateAdministrator($id,$administrator);
$this->gwAdministrator->updateAdministrator($id, $administrator);
}
public function deleteAdministratorByID($id)

@ -17,13 +17,19 @@ class ModelAnswer
function getAnswerByID($id)
{
$answer = $this->gwAnswer->getAnswerByID($id);
$answerDataArray = $this->gwAnswer->getAnswerByID($id);
$answer = new Answer($id, $answerDataArray['content'], $answerDataArray['idquestion']);
return $answer;
}
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;
}

@ -11,7 +11,12 @@ class ModelChapter
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;
}
@ -27,13 +32,14 @@ class ModelChapter
function getChapterByID($id)
{
$chapter = $this->gwChapter->getChapterByID($id);
$chapterDataArray = $this->gwChapter->getChapterByID($id);
$chapter = new Chapter($chapterDataArray['id'],$chapterDataArray['name']);
return $chapter;
}
function updateChapter($id,$chapter)
function updateChapter($id, $chapter)
{
$this->gwChapter->updateChapter($id,$chapter);
$this->gwChapter->updateChapter($id, $chapter);
}
public function verifyChapter($chapter)
{

@ -14,9 +14,19 @@ class ModelLobby
$this->gwLobby->addLobby($lobby);
}
public function getlobbies()
public function getLobbies()
{
$lobbies = $this->gwLobby->getlobbies();
$lobbiesDataArray = $this->gwLobby->getLobbies();
$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)
{
$player = $this->gwPlayer->getPlayerByID($id);
return $player;
$playerDataArray = $this->gwPlayer->getPlayerByID($id);
$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)

@ -10,37 +10,72 @@ class ModelQuestion
$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;
}
function deleteQuestionByID($id)
{
$this->gwQuestion->deleteQuestionByID($id);
}
function addQuestion($Question)
function addQuestion($questionsDataArray)
{
$questionId = $this->gwQuestion->addQuestion($Question);
$questionId = $this->gwQuestion->addQuestion($questionsDataArray);
return $questionId;
}
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;
}
function updateQuestion($id, $Question)
function updateQuestion($id, $questionDataArray)
{
$this->gwQuestion->updateQuestion($id, $Question);
$this->gwQuestion->updateQuestion($id, $questionDataArray);
}
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;
}
}

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

@ -23,7 +23,7 @@
<div class="container text-center text-white">
<div class="container border border-white rounded mt-5">
<p class="fs-2">
{{ questions[numQuestion]['content'] }}
{{ questions[numQuestion].content }}
<br>
Question n° : {{ numQuestion+1 }}/10
</p>
@ -36,13 +36,13 @@
<div class="col pt-5">
<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;">
{{ questions[numQuestion]['answers'][0]['content'] }}
{{ answerss[numQuestion][0].content }}
</label>
</div>
<div class="col pt-5">
<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;">
{{ questions[numQuestion]['answers'][1]['content'] }}
{{ answerss[numQuestion][1].content }}
</label>
</div>
</div>
@ -50,13 +50,13 @@
<div class="col pt-5">
<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;">
{{ questions[numQuestion]['answers'][2]['content'] }}
{{ answerss[numQuestion][2].content }}
</label>
</div>
<div class="col pt-5">
<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;">
{{ questions[numQuestion]['answers'][3]['content'] }}
{{ answerss[numQuestion][3].content }}
</label>
</div>
</div>

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

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

Loading…
Cancel
Save