fix : je finis après
continuous-integration/drone/push Build is passing Details

pull/35/head
Jade VAN BRABANDT 1 year ago
parent 688c4801af
commit ff94851391

@ -5,16 +5,22 @@ class Administrator
private int $id;
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()
{

@ -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;

@ -45,6 +45,11 @@ class Question
return $this->idAnswerGood;
}
public function getDifficulty(): int
{
return $this->difficulty;
}
public function setContent(string $content): void
{
$this->content = $content;
@ -55,11 +60,6 @@ class Question
$this->idAnswerGood = $idAnswerGood;
}
public function getDifficulty(): int
{
return $this->difficulty;
}
public function setDifficulty(int $difficulty): void
{
$this->difficulty = $difficulty;

@ -21,7 +21,7 @@ class ControllerAdminQuestions
$this->mdQuestion = new ModelQuestion();
$this->mdAnswer = new ModelAnswer();
$this->mdChapter = new ModelChapter();
$questions = array();
$questions = $this->mdQuestion->getQuestions();
$chapters = $this->mdChapter->getChapters();
@ -96,34 +96,23 @@ class ControllerAdminQuestions
{
$question = $this->mdQuestion->getQuestionByID($param["id"]);
$answersIDArray = $this->mdAnswer->getAnswersByIDQuestions($param["id"]);
$answers = $this->mdAnswer->getAnswersByIDQuestions($param["id"]);
$chapters = $this->mdChapter->getChapters();
$answers = array();
$i = 0;
foreach ($answersIDArray as $answerIDArray) {
$answers["{$i}"] = $answerIDArray;
$i++;
}
echo $this->twig->render($this->vues["adminQuestionsModal"], [
'question' => $question,
'chapters' => $chapters,
'answerZero' => $answers[0],
'answerOne' => $answers[1],
'answerTwo' => $answers[2],
'answerThree' => $answers[3],
'answers' => $answers,
]);
}
function update($param)
{
$id = $_POST['id'];
$id = intval($_POST['id']);
$content = $_POST['content'];
$idChapter = intval($_POST['idChapter']);
var_dump($idChapter);
$correctAnswer = intval($_POST['correctAnswer']);
$answersId = array();
@ -137,8 +126,7 @@ class ControllerAdminQuestions
$answers[1] = $_POST['answer2'];
$answers[2] = $_POST['answer3'];
$answers[3] = $_POST['answer4'];
$questionDataArray = [
'content' => $content,
@ -154,7 +142,7 @@ class ControllerAdminQuestions
'id' => $id,
];
}
var_dump($answersId, $answersDataArray);
for ($i = 0; $i <= 3; $i++) {
$this->mdAnswer->updateAnswer($answersId[$i], $answersDataArray[$i]);
}

@ -17,7 +17,6 @@ class ControllerUser
global $vues, $twig;
session_start();
try {
$this->twig = $twig;
$this->vues = $vues;
@ -91,6 +90,7 @@ class ControllerUser
$_SESSION["Score"] = 0;
$difficulty = $_POST['difficulty'];
$chapter = $_POST['chapter'];
$difficultyIsOk = TRUE;
$chapterIsOk = TRUE;
if (!($difficulty == 0 or $difficulty == 1 or $difficulty == 2)) {
@ -102,19 +102,21 @@ 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);
$answerss = array();
$_SESSION["Answers"] = array();
foreach ($_SESSION["Questions"] as $question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
$answerss[] = $answers;
var_dump("t");
$answers = $this->mdAnswer->getAnswersByIDQuestions($question->getId());
$_SESSION["Answers"][] = $answers;
}
// echo $this->twig->render($this->vues["singleplayer"], [
// 'questions' => $_SESSION["Questions"],
// 'numQuestion' => 0,
// ]);
var_dump($_SESSION["Questions"]);
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";
header("Location:/themeChoice");
@ -132,12 +134,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 +150,19 @@ 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->getIdAnswerGood());
$goodAnswer[] = $answer->getContent();
}
echo $this->twig->render($this->vues["viewScore"], [
'score' => $_SESSION["Score"],
'questions' => $_SESSION["Questions"],
'answerss' => $_SESSION["Answers"],
'goodAnswer' => $goodAnswer,
]);
}
}
@ -168,15 +175,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"],
]);
}
}

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

@ -17,7 +17,7 @@ class ModelAdministrator
public function getAdministratorByID($id)
{
$administratorDataArray = $this->gwAdministrator->getAdministratorByID($id);
$administrator = new Administrator($administratorDataArray["username"], $administratorDataArray["password"]);
$administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]);
return $administrator;
}
@ -26,8 +26,8 @@ class ModelAdministrator
$administratorsDataArray = $this->gwAdministrator->getAdministrators();
$administrators = array();
foreach ($administratorsDataArray as $administratorDataArray) {
$administrator = new Administrator($administratorDataArray["username"], $administratorDataArray["password"]);
$administrators[$administratorDataArray['id']] = $administrator;
$administrator = new Administrator($administratorDataArray["id"],$administratorDataArray["username"], $administratorDataArray["password"]);
$administrators[] = $administrator;
}
return $administrators;
}

@ -28,7 +28,7 @@ class ModelAnswer
$answers = array();
foreach ($answersDataArray as $answerDataArray) {
$answer = new Answer($answerDataArray['id'], $answerDataArray['content'], $idQuestion);
$answers[$answerDataArray['id']] = $answer;
$answers[] = $answer;
}
return $answers;
}

@ -14,8 +14,8 @@ class ModelChapter
$chaptersDataArray = $this->gwChapter->getChapters();
$chapters = array();
foreach ($chaptersDataArray as $chapterDataArray) {
$chapter = new Chapter($chapterDataArray["name"]);
$chapters[$chapterDataArray['id']] = $chapter;
$chapter = new Chapter($chapterDataArray['id'],$chapterDataArray["name"]);
$chapters[] = $chapter;
}
return $chapters;
}
@ -33,7 +33,7 @@ class ModelChapter
function getChapterByID($id)
{
$chapterDataArray = $this->gwChapter->getChapterByID($id);
$chapter = new Chapter($chapterDataArray['name']);
$chapter = new Chapter($chapterDataArray['id'],$chapterDataArray['name']);
return $chapter;
}

@ -25,7 +25,7 @@ class ModelLobby
$lobbyDataArray['password'],
intval($lobbyDataArray['nbPlayer'])
);
$lobbies[$lobbyDataArray] = $lobby;
$lobbies[] = $lobby;
return $lobbies;
}
}

@ -10,7 +10,7 @@ class ModelQuestion
$this->gwQuestion = new GatewayQuestion();
}
function getQuestions()
function getQuestions() : array
{
$questionsDataArray = $this->gwQuestion->getQuestions();
$questions = array();
@ -23,7 +23,7 @@ class ModelQuestion
intval($questionDataArray['difficulty']),
intval($questionDataArray['nbfails'])
);
$questions[$questionDataArray['id']] = $question;
$questions[] = $question;
}
return $questions;
}
@ -74,8 +74,9 @@ class ModelQuestion
intval($questionDataArray['difficulty']),
intval($questionDataArray['nbfails'])
);
$questions[$questionDataArray['id']] = $question;
$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();
}

@ -37,25 +37,25 @@
<label for="name">Réponse 1 de la question :</label>
<input type="hidden" class="form-control" id="updateIdAnswer1" name="IdAnswer1">
<input type="text" class="form-control" id="updateAnswer1" name="answer1">
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerZero.id %}checked="checked"{% endif %} value="0"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answers[0].id %}checked="checked"{% endif %} value="0"> Correct
</div>
<div class="form-group">
<label for="name">Réponse 2 de la question :</label>
<input type="hidden" class="form-control" id="updateIdAnswer2" name="IdAnswer2">
<input type="text" class="form-control" id="updateAnswer2" name="answer2">
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerOne.id %}checked="checked"{% endif %} value="1"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answers[1].id %}checked="checked"{% endif %} value="1"> Correct
</div>
<div class="form-group">
<label for="name">Réponse 3 de la question :</label>
<input type="hidden" class="form-control" id="updateIdAnswer3" name="IdAnswer3">
<input type="text" class="form-control" id="updateAnswer3" name="answer3">
<input type="radio" name="correctAnswer" {% if question.idanswergood == answersTwo.id %}checked="checked"{% endif %} value="2"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answers[2].id %}checked="checked"{% endif %} value="2"> Correct
</div>
<div class="form-group">
<label for="name">Réponse 4 de la question :</label>
<input type="hidden" class="form-control" id="updateIdAnswer4" name="IdAnswer4">
<input type="text" class="form-control" id="updateAnswer4" name="answer4">
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerThree.id %}checked="checked"{% endif %} value="3"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answers[3].id %}checked="checked"{% endif %} value="3"> Correct
</div>
</div>
<div class="modal-footer">
@ -92,15 +92,15 @@
id.value = "{{ question.id }}";
content.value = "{{ question.content }}";
IdAnswer1.value = "{{ answersZero.id }}";
IdAnswer2.value = "{{ answersOne.id }}";
IdAnswer3.value = "{{ answersTwo.id }}";
IdAnswer4.value = "{{ answersThree.id }}";
IdAnswer1.value = "{{ answers[0].id }}";
IdAnswer2.value = "{{ answers[1].id }}";
IdAnswer3.value = "{{ answers[2].id }}";
IdAnswer4.value = "{{ answers[3].id }}";
answer1.value = "{{ answerZero.content }}";
answer2.value = "{{ answerOne.content }}";
answer3.value = "{{ answerTwo.content }}";
answer4.value = "{{ answerThree.content }}";
answer1.value = "{{ answers[0].content }}";
answer2.value = "{{ answers[1].content }}";
answer3.value = "{{ answers[2].content }}";
answer4.value = "{{ answers[3].content }}";
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>

@ -28,7 +28,7 @@
<div class="dropdown d-flex flex-column align-items-center p-5">
{% for chapter in chapters %}
<input type="radio" class="btn-check" name="chapter" id="{{ chapter.name }}" value="{{ chapter.name }}">
<input type="radio" class="btn-check" name="chapter" id="{{ chapter.name }}" value="{{ chapter.id }}">
<label class="btn btn-outline-warning fs-1" for="{{ chapter.name }}">{{ chapter.name }}</label>
{% endfor %}
</div>

@ -22,7 +22,7 @@
Question : {{ question['content'] }}
</p>
<p>
Bonne réponse : {{ question['goodAnswersContent'] }}
Bonne réponse : {{ goodAnswer['goodAnswersContent'] }}
</p>
<p>
Votre réponse : {{ question['playerAnswersContent'] }}

Loading…
Cancel
Save