fix : partial fix of class not being used right
continuous-integration/drone/push Build is passing Details

pull/35/head
BelsethUwU 1 year ago
parent e390a93eb5
commit 688c4801af

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

@ -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 setContent(string $content): void
{
$this->content = $content;
}
public function setIdAnswerGood(int $idAnswerGood)
public function setIdAnswerGood(int $idAnswerGood): void
{
$this->idAnswerGood = $idAnswerGood;
}
public function getDifficulty()
public function getDifficulty(): int
{
return $this->difficulty;
}
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,8 +14,8 @@ 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();
@ -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,33 +87,43 @@ 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"]);
$answersIDArray = $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,
'answers' => $answers,
'answerZero' => $answers[0],
'answerOne' => $answers[1],
'answerTwo' => $answers[2],
'answerThree' => $answers[3],
]);
}
function update($param) {
function update($param)
{
$id = $_POST['id'];
$content = $_POST['content'];
$idChapter = intval($_POST['idChapter']);
var_dump($idChapter);
$correctAnswer = intval($_POST['correctAnswer']);
$answersId = array();
@ -126,23 +138,25 @@ 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,
];
}
var_dump($answersId, $answersDataArray);
for ($i = 0; $i <= 3; $i++) {
$this->mdAnswer->updateAnswer($answersId[$i],$Answers[$i]);
$this->mdAnswer->updateAnswer($answersId[$i], $answersDataArray[$i]);
}
header("Location:/admin/questions");

@ -89,12 +89,10 @@ 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;
@ -105,16 +103,18 @@ class ControllerUser
$chapterIsOk = FALSE;
}
if ($difficultyIsOk and $chapterIsOk) {
$_SESSION["PrevTime"] = new DateTime('now');
$_SESSION["Questions"] = $this->mdQuestion->getQuestionsByChapterAndDifficulty($chapter, $difficulty);
foreach ($_SESSION["Questions"] as &$question) {
$answerss = array();
foreach ($_SESSION["Questions"] as $question) {
$answers = $this->mdAnswer->getAnswersByIDQuestions($question['id']);
$question['answers'] = $answers;
var_dump("i");
$answerss[] = $answers;
var_dump("t");
}
echo $this->twig->render($this->vues["singleplayer"], [
'questions' => $_SESSION["Questions"],
'numQuestion' => 0,
]);
// echo $this->twig->render($this->vues["singleplayer"], [
// 'questions' => $_SESSION["Questions"],
// 'numQuestion' => 0,
// ]);
} else {
$_SESSION["error"] = "Valeur de choix de thème invalide";
header("Location:/themeChoice");

@ -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($name)
{
$query = "SELECT chapters.id FROM chapters WHERE id = :id";
$query = "SELECT chapters.name FROM chapters WHERE name = :name";
$this->con->executeQuery(
$query,
array(
':id' => array($idChapter, PDO::PARAM_STR),
':name' => array($name, 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["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["username"], $administratorDataArray["password"]);
$administrators[$administratorDataArray['id']] = $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[$answerDataArray['id']] = $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["name"]);
$chapters[$chapterDataArray['id']] = $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['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();
return $lobbies;
$lobbiesDataArray = $this->gwLobby->getLobbies();
$lobbies = array();
foreach ($lobbiesDataArray as $lobbyDataArray) {
$lobby = new Lobby(
intval($lobbyDataArray['id']),
$lobbyDataArray['name'],
$lobbyDataArray['password'],
intval($lobbyDataArray['nbPlayer'])
);
$lobbies[$lobbyDataArray] = $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)

@ -12,35 +12,70 @@ class ModelQuestion
function getQuestions()
{
$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[$questionDataArray['id']] = $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'])
);
$questions[$questionDataArray['id']] = $question;
}
return $this->questions;
}
}

@ -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 == answers[0].id %}checked="checked"{% endif %} value="0"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerZero.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 == answers[1].id %}checked="checked"{% endif %} value="1"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerOne.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 == answers[2].id %}checked="checked"{% endif %} value="2"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answersTwo.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 == answers[3].id %}checked="checked"{% endif %} value="3"> Correct
<input type="radio" name="correctAnswer" {% if question.idanswergood == answerThree.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 = "{{ answers[0].id }}";
IdAnswer2.value = "{{ answers[1].id }}";
IdAnswer3.value = "{{ answers[2].id }}";
IdAnswer4.value = "{{ answers[3].id }}";
IdAnswer1.value = "{{ answersZero.id }}";
IdAnswer2.value = "{{ answersOne.id }}";
IdAnswer3.value = "{{ answersTwo.id }}";
IdAnswer4.value = "{{ answersThree.id }}";
answer1.value = "{{ answers[0].content }}";
answer2.value = "{{ answers[1].content }}";
answer3.value = "{{ answers[2].content }}";
answer4.value = "{{ answers[3].content }}";
answer1.value = "{{ answerZero.content }}";
answer2.value = "{{ answerOne.content }}";
answer3.value = "{{ answerTwo.content }}";
answer4.value = "{{ answerThree.content }}";
modal.show();
}

@ -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.id }}">
<input type="radio" class="btn-check" name="chapter" id="{{ chapter.name }}" value="{{ chapter.name }}">
<label class="btn btn-outline-warning fs-1" for="{{ chapter.name }}">{{ chapter.name }}</label>
{% endfor %}
</div>

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