parent
635dcb2022
commit
a32105946b
@ -1,36 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class GatewayAdministrator
|
|
||||||
{
|
|
||||||
private $con;
|
|
||||||
|
|
||||||
public function __construct($con)
|
|
||||||
{
|
|
||||||
$this->con = $con;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAdministrator($Administrator)
|
|
||||||
{
|
|
||||||
$query = "insert into Administratoristrator(id,username,password) values (:id,:username,:password);";
|
|
||||||
$this->con->executeQuery(
|
|
||||||
$query,
|
|
||||||
array(
|
|
||||||
':id' => array($Administrator->getId(), PDO::PARAM_INT),
|
|
||||||
':username' => array($Administrator->getUsername(), PDO::PARAM_STR),
|
|
||||||
':password' => array(password_hash($Administrator->getPassword(), PASSWORD_DEFAULT), PDO::PARAM_STR)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function getCredential($login)
|
|
||||||
{
|
|
||||||
$query = "SELECT password FROM Administrator WHERE username = :login;";
|
|
||||||
$this->con->executeQuery($query, array(':login' => array($login, PDO::PARAM_STR)));
|
|
||||||
$results = $this->con->getResults();
|
|
||||||
if ($results == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return $results[0]['password'];
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayAdministrator
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
/* private int $id;
|
||||||
|
private string $username;
|
||||||
|
private string $hashedPassword;*/
|
||||||
|
public function addAdministrator($administrator)
|
||||||
|
{
|
||||||
|
$query = "insert into Administrator(id,username,hashedPassword) values (:id,:username,:hashedPassword);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($administrator->getId(), PDO::PARAM_INT),
|
||||||
|
':username' => array($administrator->getUsername(), PDO::PARAM_STR),
|
||||||
|
':hashedPassword' => array($administrator->getHashedPassword(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdministratorByUsername(string $username)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Administrator WHERE username = :username;";
|
||||||
|
$this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Administrator($results[0]['id'], $results[0]['username'], $results[0]['hashedPassword']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdministratorByID(int $id)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Administrator WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Administrator($results[0]['id'], $results[0]['username'], $results[0]['hashedPassword']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdministrators()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Administrator;";
|
||||||
|
$this->con->executeQuery($query);
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAdministrator($administrator)
|
||||||
|
{
|
||||||
|
$query = "UPDATE Administrator SET username = :username, hashedPassword = :hashedPassword WHERE id = :id;";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($administrator->getId(), PDO::PARAM_INT),
|
||||||
|
':username' => array($administrator->getUsername(), PDO::PARAM_STR),
|
||||||
|
':hashedPassword' => array($administrator->getHashedPassword(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteAdministratorByID($id)
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Administrator WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayAnswer
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addAnswer($answer)
|
||||||
|
{
|
||||||
|
$query = "insert into Answer(id,content) values (:id,:content);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($answer->getId(), PDO::PARAM_INT),
|
||||||
|
':content' => array($answer->getContent(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAnswerByIDQuestions($idQuestions)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM answers, questions WHERE questions.id = :idQuestions;";
|
||||||
|
$this->con->executeQuery($query, array(':idQuestions' => array($idQuestions, PDO::PARAM_INT)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Answer($results[0]['id'], $results[0]['content']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateAnswer($answer)
|
||||||
|
{
|
||||||
|
$query = "UPDATE Answer SET content = :content WHERE id = :id;";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($answer->getId(), PDO::PARAM_INT),
|
||||||
|
':content' => array($answer->getContent(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteAnswer($id)
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Answer WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayChapter
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addChapter($chapter)
|
||||||
|
{
|
||||||
|
$query = "insert into Chapter(id,name) values (:id,:name);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($chapter->getId(), PDO::PARAM_INT),
|
||||||
|
':name' => array($chapter->getName(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChapters()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Chapter;";
|
||||||
|
$this->con->executeQuery($query);
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$chapters = array();
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$chapters[] = new Chapter($row['id'], $row['name']);
|
||||||
|
}
|
||||||
|
return $chapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateChapter($chapter)
|
||||||
|
{
|
||||||
|
$query = "UPDATE Chapter SET name = :name WHERE id = :id;";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($chapter->getId(), PDO::PARAM_INT),
|
||||||
|
':name' => array($chapter->getName(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteChapter($id)
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Chapter WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayLobby
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addLobby($lobby)
|
||||||
|
{
|
||||||
|
$query = "insert into Lobby(id,name,password,nbPlayer) values (:id,:name,:password,:nbPlayer);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($lobby->getId(), PDO::PARAM_INT),
|
||||||
|
':name' => array($lobby->getName(), PDO::PARAM_STR),
|
||||||
|
':password' => array($lobby->getPassword(), PDO::PARAM_STR),
|
||||||
|
':nbPlayer' => array($lobby->getNbPlayer(), PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLobbys()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Lobby;";
|
||||||
|
$this->con->executeQuery($query);
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$lobbys = array();
|
||||||
|
foreach ($results as $row) {
|
||||||
|
$lobbys[] = new Lobby($row['id'], $row['name'], $row['password'], $row['nbPlayer']);
|
||||||
|
}
|
||||||
|
return $lobbys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLobbyByName($name)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Lobby WHERE name = :name;";
|
||||||
|
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Lobby($results[0]['id'], $results[0]['name'], $results[0]['password'], $results[0]['nbPlayer']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deleteLobby($id)
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Lobby WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayPlayer
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addPlayer($player)
|
||||||
|
{
|
||||||
|
$query = "insert into Player(id,nickname,hashedPassword) values (:id,:nickname,:hashedPassword);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($player->getId(), PDO::PARAM_INT),
|
||||||
|
':nickname' => array($player->getNickname(), PDO::PARAM_STR),
|
||||||
|
':hashedPassword' => array($player->getHashedPassword(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlayerByNickname(string $nickname)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Player WHERE nickname = :nickname;";
|
||||||
|
$this->con->executeQuery($query, array(':nickname' => array($nickname, PDO::PARAM_STR)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
|
||||||
|
}
|
||||||
|
public function getPlayerByID(int $id)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Player WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Player($results[0]['id'], $results[0]['nickname'], $results[0]['hashedPassword']);
|
||||||
|
}
|
||||||
|
public function getPlayers()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Player;";
|
||||||
|
$this->con->executeQuery($query);
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatePlayer($player)
|
||||||
|
{
|
||||||
|
$query = "UPDATE Player SET nickname = :nickname, hashedPassword = :hashedPassword WHERE id = :id;";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($player->getId(), PDO::PARAM_INT),
|
||||||
|
':nickname' => array($player->getNickname(), PDO::PARAM_STR),
|
||||||
|
':hashedPassword' => array($player->getHashedPassword(), PDO::PARAM_STR)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletePlayerByID(int $id)
|
||||||
|
{
|
||||||
|
$query = "DELETE FROM Player WHERE id = :id;";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($id, PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class GatewayQuestion
|
||||||
|
{
|
||||||
|
private $con;
|
||||||
|
|
||||||
|
public function __construct($con)
|
||||||
|
{
|
||||||
|
$this->con = $con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addQuestion($question)
|
||||||
|
{
|
||||||
|
$query = "insert into Question(id,content,difficulty,nbFails) values (:id,:content,:difficulty,:nbFails);";
|
||||||
|
$this->con->executeQuery(
|
||||||
|
$query,
|
||||||
|
array(
|
||||||
|
':id' => array($question->getId(), PDO::PARAM_INT),
|
||||||
|
':content' => array($question->getContent(), PDO::PARAM_STR),
|
||||||
|
':difficulty' => array($question->getDifficulty(), PDO::PARAM_INT),
|
||||||
|
':nbFails' => array($question->getNbFails(), PDO::PARAM_INT)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQuestionByID($id)
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Question WHERE id = :id;";
|
||||||
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return new Question($results[0]['id'], $results[0]['content'], $results[0]['difficulty'], $results[0]['nbFails']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQuestions()
|
||||||
|
{
|
||||||
|
$query = "SELECT * FROM Question;";
|
||||||
|
$this->con->executeQuery($query);
|
||||||
|
$results = $this->con->getResults();
|
||||||
|
if ($results == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue