diff --git a/Website/controllers/ControllerAdmin.php b/Website/controllers/ControllerAdministrator.php similarity index 100% rename from Website/controllers/ControllerAdmin.php rename to Website/controllers/ControllerAdministrator.php diff --git a/Website/controllers/FrontController.php b/Website/controllers/FrontController.php index 8822548..c19af14 100755 --- a/Website/controllers/FrontController.php +++ b/Website/controllers/FrontController.php @@ -2,13 +2,12 @@ class FrontController { + function __construct() { global $dsn, $user, $pass, $vues; $listeAction_Administrator = array('goToAdministratorConnexion', 'verifValidation', 'ajoutSource', 'supprimerSource', 'setNbArticlesParPage', 'goToAdministratoristration', 'refreshData', 'quitterAdministrator'); try { - $mdlAdministrator = new MdlAdministrator(); - $Administrator = $mdlAdministrator->isAdministrator(); $action = ""; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; @@ -20,20 +19,7 @@ class FrontController header("Location:" . $vues["AdministratorConnexion"]); } } else { - $gatewayNews = new GatewayNews(new Connection($dsn, $user, $pass)); - $page = 1; - if (isset($_GET['page'])) { - $page = $_GET['page']; - } - $gate = new GatewayConfigAdministrator(new Connection($dsn, $user, $pass)); - $nbArticlePages = $gate->getConfigAdministrator(1); - $listeNews = $gatewayNews->getNews($page, $nbArticlePages); - $pageAvant = $page - 1; - $pageApres = $page + 1; - - - $pageMAX = $gatewayNews->getNbNews() / $nbArticlePages + 1; - require($vues['listeNews']); + $gate = new GatewayAdministrator(new ConnectionBaseDeDonnee($dsn, $user, $pass)); } } catch (Exception $e) { header("Location:" . $vues["erreur"]); diff --git a/Website/gateways/GatewayAdmin.php b/Website/gateways/GatewayAdmin.php deleted file mode 100755 index 0e8895f..0000000 --- a/Website/gateways/GatewayAdmin.php +++ /dev/null @@ -1,36 +0,0 @@ -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']; - } -} diff --git a/Website/gateways/GatewayAdministrator.php b/Website/gateways/GatewayAdministrator.php new file mode 100755 index 0000000..e1dd22c --- /dev/null +++ b/Website/gateways/GatewayAdministrator.php @@ -0,0 +1,77 @@ +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))); + } +} diff --git a/Website/gateways/GatewayAnswer.php b/Website/gateways/GatewayAnswer.php new file mode 100755 index 0000000..1cca45f --- /dev/null +++ b/Website/gateways/GatewayAnswer.php @@ -0,0 +1,52 @@ +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))); + } +} diff --git a/Website/gateways/GatewayChapter.php b/Website/gateways/GatewayChapter.php new file mode 100755 index 0000000..6b2c7a0 --- /dev/null +++ b/Website/gateways/GatewayChapter.php @@ -0,0 +1,56 @@ +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))); + } +} diff --git a/Website/gateways/GatewayLobby.php b/Website/gateways/GatewayLobby.php new file mode 100755 index 0000000..82a3f12 --- /dev/null +++ b/Website/gateways/GatewayLobby.php @@ -0,0 +1,60 @@ +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))); + } + + +} diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php new file mode 100755 index 0000000..041208f --- /dev/null +++ b/Website/gateways/GatewayPlayer.php @@ -0,0 +1,78 @@ +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) + ) + ); + } +} diff --git a/Website/gateways/GatewayQuestion.php b/Website/gateways/GatewayQuestion.php new file mode 100755 index 0000000..a58f071 --- /dev/null +++ b/Website/gateways/GatewayQuestion.php @@ -0,0 +1,46 @@ +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; + } + } +} diff --git a/Website/index.php b/Website/index.php index 6c72127..abe567e 100755 --- a/Website/index.php +++ b/Website/index.php @@ -1,5 +1,5 @@