diff --git a/.idea/ScienceQuest.iml b/.idea/ScienceQuest.iml index 310f67d..460deeb 100755 --- a/.idea/ScienceQuest.iml +++ b/.idea/ScienceQuest.iml @@ -2,11 +2,15 @@ - - - - - + + + + + + + + + diff --git a/.idea/php.xml b/.idea/php.xml index a1827cd..b5741f6 100755 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -10,6 +10,12 @@ + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..35eb1dd 100755 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index b68c8e1..d91386a 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Neutral +# SCIENCEQUEST Mise en situation d'une entreprise fictive établissant un lien avec un Product Owner (PO) ayant pour but de réaliser son projet durant 100 heures dédiées tout au long de l'année. \ No newline at end of file diff --git a/project/src/config/Validation.php b/project/src/config/Validation.php index c9f2d58..7648117 100755 --- a/project/src/config/Validation.php +++ b/project/src/config/Validation.php @@ -2,6 +2,9 @@ namespace config; +use model\ConfigurationJeu; +use model\Joueur; +use model\MdlPendu; use model\ValidationException; class Validation @@ -22,13 +25,13 @@ class Validation } if ($difficulty == '' || !filter_var($difficulty, FILTER_VALIDATE_INT)) { - $dVueErreur[] = "Aucune difficultée séléctionnée"; + $dVueErreur[] = "Aucune difficulté séléctionnée"; $difficulty = 0; throw new ValidationException("Erreur difficulté"); } } - public static function valUserLogin(string &$user, &$dVueErreur) + public static function valUserLogin(string $user, &$dVueErreur) { if ($user == '' || !filter_var($user, FILTER_SANITIZE_STRING)) { $dVueErreur[] = 'Identifiant invalide'; @@ -37,7 +40,8 @@ class Validation } } - public static function valCodeInvitation(string &$codeInvitation, &$dVueErreur){ + public static function valCodeInvitation(string $codeInvitation, &$dVueErreur): string + { if($codeInvitation == ''){ $dVueErreur[] = 'Code d\'invitation invalide'; throw new ValidationException("Code d'invitation invalide"); @@ -56,8 +60,9 @@ class Validation return $pseudo; } - public static function valRole(&$role, &$dVueErreur){ - if(! $role instanceof \model\Joueur){ + public static function valRole(&$role, &$dVueErreur): Joueur + { + if(! $role instanceof Joueur){ $role = NULL; $dVueErreur[] = 'Role invalide'; throw new ValidationException('Role invalide'); @@ -65,8 +70,9 @@ class Validation return $role; } - public static function valConfigurationJeu(&$configurationJeu, &$dVueErreur){ - if(! $configurationJeu instanceof \model\ConfigurationJeu){ + public static function valConfigurationJeu($configurationJeu, &$dVueErreur): ConfigurationJeu + { + if(! $configurationJeu instanceof ConfigurationJeu){ $role = NULL; $dVueErreur[] = 'Configuration du jeu invalide'; throw new ValidationException('Configuration du jeu'); @@ -74,8 +80,9 @@ class Validation return $configurationJeu; } - public static function valMdlPendu(&$pendu, &$dVueErreur){ - if(! $pendu instanceof \model\MdlPendu){ + public static function valMdlPendu($pendu, &$dVueErreur): MdlPendu + { + if(! $pendu instanceof MdlPendu){ $role = NULL; $dVueErreur[] = 'Erreur mauvais jeu en utilisation'; throw new ValidationException('Erreur mauvais jeu en utilisation'); diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index aadb0db..d9e6c07 100755 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -1,52 +1,52 @@ render('admin/accueil.html'); - break; - case 'stats': - echo "stats admin";exit; - // echo $twig->render('admin/stats.html'); - break; - case 'ajouterScientifiques': - echo "page ajout scientifiques admin";exit; - // echo $twig->render('admin/ajouter.html'); - break; - //mauvaise action - default: - $dVueErreur[] = "Erreur d'appel php"; - echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); - break; - } - } catch (\PDOException $e) { - $dVueErreur[] = 'Erreur avec la base de données !'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } catch (\Exception $e2) { - $dVueErreur[] = 'Erreur inattendue !'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } - } + if($_SESSION["isAdmin"]) { + try { + switch ($action) { + case '': + echo "accueil admin"; + exit; + // echo $twig->render('admin/accueil.html'); + case 'stats': + echo "stats admin"; + exit; + // echo $twig->render('admin/stats.html'); + case 'ajouterScientifiques': + echo "page ajout scientifiques admin"; + exit; + // echo $twig->render('admin/ajouter.html'); + //mauvaise action + default: + $dVueErreur[] = "Erreur d'appel php"; + echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); + break; + } + } catch (PDOException $e) { + $dVueErreur[] = 'Erreur avec la base de données !'; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + } catch (Exception $e2) { + $dVueErreur[] = 'Erreur inattendue !'; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + } + } } //verifier si l'utilisateur est connecté mais pas admin if(isset($_SESSION["isLogged"])){ - if($_SESSION["isLogged"]==true) { - //dire acces interdit au non admins - array_push($dVueEreur, "Erreur 403 : Acces interdit"); + if($_SESSION["isLogged"]) { + //dire acces interdit aux non admins + $dVueErreur[] = "Erreur 403 : Acces interdit"; echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); exit(0); } @@ -56,4 +56,3 @@ class AdminController { exit(0); } } -?> \ No newline at end of file diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index ce5e709..959e608 100755 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -1,16 +1,27 @@ setBasePath($basePath); $router->map('GET|POST','/[a:action]?','UserController'); @@ -42,7 +53,7 @@ class FrontController $match = $router->match(); if (!$match) { - throw new \Exception('Wrong call'); + throw new Exception('Wrong call'); } switch($match['target']) { @@ -57,6 +68,7 @@ class FrontController $action = 'login'; } $this->callController('AdminController',$action); + break; case 'PseudoController': $this->callController('PseudoController',$match); @@ -72,14 +84,14 @@ class FrontController echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); break; } - } catch (\PDOException $e) { + } catch (PDOException $e) { $dVueErreur[] = 'Erreur avec la base de données !'; $dVueErreur[] = $e->getMessage(); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); } catch (LoginException $e) { echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('login.html'); - } catch (\Exception $e2) { + } catch (Exception $e2) { $dVueErreur[] = 'Erreur inattendue !'.$e2->getMessage(); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); } @@ -108,22 +120,24 @@ class FrontController $id_jeu = $_POST['jeu'] ?? ''; $id_difficulte = $_POST['difficulte'] ?? ''; try{ - \config\Validation::val_form($id_jeu, $id_difficulte, $dVueErreur); - }catch (\model\ValidationException $ex){ - $this->CreateParty($dVueErreur); - }catch (\Exception $ex){ + Validation::val_form($id_jeu, $id_difficulte, $dVueErreur); + }catch (ValidationException|Exception $ex){ $this->CreateParty($dVueErreur); } if(count($dVueErreur) == 0){ - $jeu = (new \model\MdlJeu())->getFromId($id_jeu); - $difficulte = (new \model\MdlDifficulte())->getFromId($id_difficulte); - $_SESSION['configuration'] = new \model\ConfigurationJeu($jeu, $difficulte); + $jeu = (new MdlJeu())->getFromId($id_jeu); + $difficulte = (new MdlDifficulte())->getFromId($id_difficulte); + $_SESSION['configuration'] = new ConfigurationJeu($jeu, $difficulte); header("Location: /pseudo"); #echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); }else{ $this->CreateParty($dVueErreur); } - } + } + + private function CreateParty(array $dVueErreur) + { + } } diff --git a/project/src/controller/JouerController.php b/project/src/controller/JouerController.php index 6d544e8..bb55cb2 100644 --- a/project/src/controller/JouerController.php +++ b/project/src/controller/JouerController.php @@ -7,6 +7,9 @@ use model\ValidationException; class JouerController{ + /** + * @throws Exception + */ public function __construct(){ global $twig, $config; $dVue = []; @@ -30,7 +33,6 @@ class JouerController{ break; default: throw new Exception("Jeu non défini !"); - break; } } }else{ diff --git a/project/src/controller/UserController.php b/project/src/controller/UserController.php index 0ea78e9..a5ec0e4 100755 --- a/project/src/controller/UserController.php +++ b/project/src/controller/UserController.php @@ -3,8 +3,11 @@ namespace controller; use config\Validation; +use Exception; use model\Connection; use model\GameGateway; +use model\MdlDifficulte; +use model\MdlJeu; use model\ValidationException; class UserController { @@ -25,6 +28,9 @@ class UserController { } } + /** + * @throws Exception + */ public function jouer(array $params) { global $twig, $config; $dVue = []; @@ -48,7 +54,6 @@ class UserController { break; default: throw new Exception("Jeu non défini !"); - break; } } }else{ @@ -61,8 +66,8 @@ class UserController { global $twig; global $dVueErreur; - $listJeu = (new \model\MdlJeu())->getAll(); - $listDifficulte = (new \model\MdlDifficulte())->getAll(); + $listJeu = (new MdlJeu())->getAll(); + $listDifficulte = (new MdlDifficulte())->getAll(); $dVueCreateJeu = []; foreach($listJeu as $jeu){ diff --git a/project/src/db.sql b/project/src/db.sql index d8fef29..9e9a5d2 100755 --- a/project/src/db.sql +++ b/project/src/db.sql @@ -1,4 +1,3 @@ - -- Testé sous pgsql 15 DROP TABLE IF EXISTS Reponse; diff --git a/project/src/index.php b/project/src/index.php index 74f761c..06d9e3c 100755 --- a/project/src/index.php +++ b/project/src/index.php @@ -2,12 +2,13 @@ require_once(__DIR__.'/vendor/autoload.php'); require_once(__DIR__.'/config/config.php'); - use controller\FrontController; + use Twig\Environment; + use Twig\Loader\FilesystemLoader; - //twig - $loader = new \Twig\Loader\FilesystemLoader('templates'); - $twig = new \Twig\Environment($loader, [ +//twig + $loader = new FilesystemLoader('templates'); + $twig = new Environment($loader, [ 'cache' => false, ]); diff --git a/project/src/model/exception/IdSessionDoubleException.php b/project/src/model/exception/IdSessionDoubleException.php index 47b830f..1566971 100755 --- a/project/src/model/exception/IdSessionDoubleException.php +++ b/project/src/model/exception/IdSessionDoubleException.php @@ -2,7 +2,9 @@ namespace model; -class IdSessionDoubleException extends \RuntimeException +use RuntimeException; + +class IdSessionDoubleException extends RuntimeException { private int $idJoueur; private string $idSession; diff --git a/project/src/model/exception/LoginException.php b/project/src/model/exception/LoginException.php index 816f535..ab91a35 100755 --- a/project/src/model/exception/LoginException.php +++ b/project/src/model/exception/LoginException.php @@ -2,6 +2,8 @@ namespace model; -class LoginException extends \Exception +use Exception; + +class LoginException extends Exception { } \ No newline at end of file diff --git a/project/src/model/exception/PseudoDejaPrisException.php b/project/src/model/exception/PseudoDejaPrisException.php index 43413b2..d94b841 100755 --- a/project/src/model/exception/PseudoDejaPrisException.php +++ b/project/src/model/exception/PseudoDejaPrisException.php @@ -2,7 +2,9 @@ namespace model; -class PseudoDejaPrisException extends \RuntimeException +use RuntimeException; + +class PseudoDejaPrisException extends RuntimeException { } \ No newline at end of file diff --git a/project/src/model/exception/ValidationException.php b/project/src/model/exception/ValidationException.php index 0bd2319..19eee9e 100755 --- a/project/src/model/exception/ValidationException.php +++ b/project/src/model/exception/ValidationException.php @@ -1,5 +1,7 @@ con=$con; @@ -15,7 +18,7 @@ class AdminGateway { $sql = "SELECT * FROM Admin WHERE email=:email"; $this->con->executeQuery($sql, array( - ':email' => array($email, \PDO::PARAM_STR) + ':email' => array($email, PDO::PARAM_STR) )); $result = $this->con->getOneResult(); diff --git a/project/src/model/gateways/Connection.php b/project/src/model/gateways/Connection.php index f1eee73..2e8572d 100755 --- a/project/src/model/gateways/Connection.php +++ b/project/src/model/gateways/Connection.php @@ -3,10 +3,11 @@ namespace model; use PDO; +use PDOStatement; class Connection extends PDO { - private $stmt; + private PDOStatement $stmt; public function __construct(string $dsn, string $username, string $password) { diff --git a/project/src/model/gateways/DifficulteGateway.php b/project/src/model/gateways/DifficulteGateway.php index f0cff3f..ec552d4 100755 --- a/project/src/model/gateways/DifficulteGateway.php +++ b/project/src/model/gateways/DifficulteGateway.php @@ -4,7 +4,7 @@ namespace model; class DifficulteGateway { - private $con; + private Connection $con; function __construct(Connection $con) { $this->con = $con; diff --git a/project/src/model/gateways/GameGateway.php b/project/src/model/gateways/GameGateway.php index 04334c3..1b37f85 100755 --- a/project/src/model/gateways/GameGateway.php +++ b/project/src/model/gateways/GameGateway.php @@ -1,13 +1,14 @@ con = $co; + function __construct(Connection $con) { + $this->con = $con; } public static function getGames() : array { @@ -21,7 +22,7 @@ class GameGateway public function getGameByCode(int $code) : array { $query = 'SELECT * FROM Partie WHERE codeInvitation=:id'; $this->con->executeQuery($query,array( - ':id' => array($code,\PDO::PARAM_INT) + ':id' => [$code, PDO::PARAM_INT] )); return $this->con->getResults(); } diff --git a/project/src/model/gateways/InviteGateway.php b/project/src/model/gateways/InviteGateway.php index 9404c60..d0ddc0c 100755 --- a/project/src/model/gateways/InviteGateway.php +++ b/project/src/model/gateways/InviteGateway.php @@ -9,23 +9,49 @@ class InviteGateway extends JoueurGateway parent::__construct($con); } - public function getFromIdSession($idSession): array|bool - { - $this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;", - [":idSession" => [$idSession, $this->con::PARAM_STR]]); +// public function getFromIdSession($idSession): array|bool // <- Seulement autorisé en PHP 8 /!\ (on est en 7.4) +// { +// $this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;", +// [":idSession" => [$idSession, $this->con::PARAM_STR]]); +// return $this->con->getOneResult(); +// } + + /** + * @param string $idSession + * @return array|bool + */ + public function getFromIdSession(string $idSession) { // <- PHP 7.4 + $this->con->executeQuery( + "SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;", + [":idSession" => [$idSession, $this->con::PARAM_STR]] + ); return $this->con->getOneResult(); } - public function getFromId($id): array|bool - { - $this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE id = :id;", - [":id" => [$id, $this->con::PARAM_INT]]); + + +// public function getFromId($id): array|bool // <- Seulement autorisé en PHP 8 /!\ (on est en 7.4) +// { +// $this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE id = :id;", +// [":id" => [$id, $this->con::PARAM_INT]]); +// return $this->con->getOneResult(); +// } + + /** + * @param int $id + * @return array|bool + */ + public function getFromId(int $id) { // <- PHP 7.4 + $this->con->executeQuery( + "SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE id = :id;", + [":id" => [$id, $this->con::PARAM_INT]] + ); return $this->con->getOneResult(); } public function insertInvite(string $pseudo, string $idSession): int{ $row = $this->getFromIdSession($idSession); - if($row != false){ + if($row){ throw new IdSessionDoubleException($row['idjoueur'], $row['idsession']); }else{ $id = $this->insertJoueur($pseudo); diff --git a/project/src/model/gateways/JeuGateway.php b/project/src/model/gateways/JeuGateway.php index 0f3f74a..664f29e 100755 --- a/project/src/model/gateways/JeuGateway.php +++ b/project/src/model/gateways/JeuGateway.php @@ -2,11 +2,9 @@ namespace model; -use PDO; - class JeuGateway { - private $con; + private Connection $con; function __construct(Connection $con) { $this->con = $con; diff --git a/project/src/model/gateways/JoueurGateway.php b/project/src/model/gateways/JoueurGateway.php index 18e6055..b01d83b 100755 --- a/project/src/model/gateways/JoueurGateway.php +++ b/project/src/model/gateways/JoueurGateway.php @@ -4,21 +4,33 @@ namespace model; abstract class JoueurGateway { - protected $con; + protected Connection $con; function __construct(Connection $con) { $this->con = $con; } - protected function getFromPseudo($pseudo): array|bool - { - $this->con->executeQuery("SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;", - [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); +// protected function getFromPseudo($pseudo): array|bool <- autorisé seulement en PHP 8 +// { +// $this->con->executeQuery("SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;", +// [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); +// return $this->con->getOneResult(); +// } + + /** + * @param string $pseudo + * @return array|bool + */ + protected function getFromPseudo(string $pseudo) { // <- PHP 7.4 + $this->con->executeQuery( + "SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;", + [":pseudo" => [$pseudo, $this->con::PARAM_STR]] + ); return $this->con->getOneResult(); } protected function insertJoueur(string $pseudo): int{ - if($this->getFromPseudo($pseudo) != false){ + if($this->getFromPseudo($pseudo)){ throw new PseudoDejaPrisException(); }else{ $this->con->executeQuery("INSERT INTO Joueur(pseudo) VALUES(:pseudo);", @@ -28,7 +40,7 @@ abstract class JoueurGateway } public function setPseudo(int $id, string $pseudo){ - if($this->getFromPseudo($pseudo) != false){ + if($this->getFromPseudo($pseudo)){ throw new PseudoDejaPrisException(); }else{ $this->con->executeQuery("UPDATE Joueur SET pseudo=:pseudo WHERE id=:id", diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php index a863ea2..9de8cc1 100755 --- a/project/src/model/gateways/ScientifiqueGateway.php +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -4,15 +4,25 @@ namespace model; class ScientifiqueGateway { - private $con; + private Connection $con; function __construct(Connection $con) { $this->con = $con; } - public function getRandom(): array|bool{ +// public function getRandom(): array|bool{ <- autorisé seulement en PHP 8 +// $this->con->executeQuery( +// "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, index FROM Scientifique ORDER BY RANDOM() LIMIT 1;"); +// return $this->con->getOneResult(); +// } + + /** + * @return array|bool + */ + public function getRandom() { // PHP 7.4 $this->con->executeQuery( - "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;"); + "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;" + ); return $this->con->getOneResult(); } } \ No newline at end of file diff --git a/project/src/model/gateways/SexeGateway.php b/project/src/model/gateways/SexeGateway.php index 3a4e608..49ceedd 100755 --- a/project/src/model/gateways/SexeGateway.php +++ b/project/src/model/gateways/SexeGateway.php @@ -4,7 +4,7 @@ namespace model; class SexeGateway { - private $con; + private Connection $con; function __construct(Connection $con) { $this->con = $con; diff --git a/project/src/model/gateways/ThematiqueGateway.php b/project/src/model/gateways/ThematiqueGateway.php index deb64cf..5f60426 100755 --- a/project/src/model/gateways/ThematiqueGateway.php +++ b/project/src/model/gateways/ThematiqueGateway.php @@ -4,7 +4,7 @@ namespace model; class ThematiqueGateway { - private $con; + private Connection $con; function __construct(Connection $con) { $this->con = $con; diff --git a/project/src/model/gateways/UserGateway.php b/project/src/model/gateways/UserGateway.php index 188418a..7563880 100755 --- a/project/src/model/gateways/UserGateway.php +++ b/project/src/model/gateways/UserGateway.php @@ -2,10 +2,13 @@ namespace model; +use PDO; +use PDOStatement; + class UserGateway { private Connection $con; - private \PDOStatement $stmt; + private PDOStatement $stmt; public function __construct(Connection $con) { $this->con=$con; @@ -15,7 +18,7 @@ class UserGateway { $sql = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($sql, array( - ':email' => array($email, \PDO::PARAM_STR) + ':email' => array($email, PDO::PARAM_STR) )); $result = $this->con->getOneResult(); @@ -27,7 +30,7 @@ class UserGateway } public function addUser(string $email, string $password): void { - $sql = "INSERT INTO utilisateur (email, password) VALUES (:email, :password)"; + $sql = "INSERT INTO Utilisateur (email, password) VALUES (:email, :password)"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':email', $email); $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); @@ -35,14 +38,14 @@ class UserGateway } public function deleteUser(int $id): void { - $sql = "DELETE FROM utilisateur WHERE id=:id"; + $sql = "DELETE FROM Utilisateur WHERE idJoueur=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); } public function updateUser(int $id, string $email, string $password): void { - $sql = "UPDATE utilisateur SET email=:email, password=:password WHERE id=:id"; + $sql = "UPDATE Utilisateur SET email=:email, password=:password WHERE idJoueur=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->bindValue(':email', $email); @@ -51,7 +54,7 @@ class UserGateway } public function getUser(int $id): User { - $sql = "SELECT * FROM utilisateur WHERE id=:id"; + $sql = "SELECT * FROM Utilisateur WHERE idJoueur=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); @@ -72,7 +75,7 @@ class UserGateway } public function getHashedPasswordById(int $id): string { - $sql = "SELECT password FROM utilisateur WHERE id=:id"; + $sql = "SELECT password FROM Utilisateur WHERE idJoueur=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); @@ -81,7 +84,7 @@ class UserGateway } public function getHashedPassword(int $email): string { - $sql = "SELECT password FROM utilisateur WHERE email=:email"; + $sql = "SELECT password FROM Utilisateur WHERE email=:email"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':email', $email); $stmt->execute(); @@ -90,7 +93,7 @@ class UserGateway } public function getUserId(string $email): int { - $sql = "SELECT id FROM utilisateur WHERE email=:email"; + $sql = "SELECT idJoueur FROM Utilisateur WHERE email=:email"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':email', $email); $stmt->execute(); diff --git a/project/src/model/mdl/MdlAdmin.php b/project/src/model/mdl/MdlAdmin.php index 55af3fb..e189c50 100755 --- a/project/src/model/mdl/MdlAdmin.php +++ b/project/src/model/mdl/MdlAdmin.php @@ -13,7 +13,8 @@ class MdlAdmin extends MdlBase{ return $this->gw->login($username, $password); } - public static function isAdmin() { + public static function isAdmin(): bool + { if(!isset($_SESSION['admin']) || !$_SESSION['admin'] || !isset($_SESSION['email']) diff --git a/project/src/model/mdl/MdlPendu.php b/project/src/model/mdl/MdlPendu.php index 63b15f2..4981189 100755 --- a/project/src/model/mdl/MdlPendu.php +++ b/project/src/model/mdl/MdlPendu.php @@ -10,11 +10,12 @@ class MdlPendu{ private array $lettreExceptees; private array $lettreUtilisees; - private static $nbFailsMax = 8; + private static int $nbFailsMax = 8; public function __construct(Scientifique $scientifiqueATrouver){ $this->scientifiqueATrouver = $scientifiqueATrouver; - $this->aTrouver = strtr($scientifiqueATrouver->getPrenom()." ".$scientifiqueATrouver->getNom(), 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy'); #suppression des accents + $this->aTrouver = iconv('UTF-8', 'ASCII//TRANSLIT', $scientifiqueATrouver->getPrenom()." ".$scientifiqueATrouver->getNom()); #suppression des accents + $this->aTrouver = preg_replace('/[^A-Za-z0-9 ]/', '', $this->aTrouver); // Retire les caractères non-alphanumeric $this->nbFail = 0; $this->nbTours = 0; $this->lettreExceptees = [' ', '-']; @@ -24,13 +25,18 @@ class MdlPendu{ public function jouerLettre(string $lettre): string{ $lettre = strtolower($lettre); if(strlen($lettre) != 1){ throw new ValidationException("Veuillez fournir une seule lettre");} - if(!ctype_alpha($lettre)){ throw new ValidationException("Veuillez fournir une caractère alphabétique");} + if(!ctype_alpha($lettre)){ throw new ValidationException("Veuillez fournir un caractère alphabétique");} if(in_array($lettre, $this->lettreUtilisees)){ throw new ValidationException("Vous avez déjà joué cette lettre");} $this->nbTours += 1; - if(!str_contains($this->aTrouver, $lettre)){ +// if(!str_contains($this->aTrouver, $lettre)){ // UNIQUEMENT EN PHP 8.0 +// $this->nbFail += 1; +// } + + if (strpos($this->aTrouver, $lettre) === false) { // PHP 7.4 $this->nbFail += 1; } + $this->lettreUtilisees[] = $lettre; return $this->getDecouvert(); } diff --git a/project/src/model/mdl/MdlScientifique.php b/project/src/model/mdl/MdlScientifique.php index 6ea01da..fa12ff6 100755 --- a/project/src/model/mdl/MdlScientifique.php +++ b/project/src/model/mdl/MdlScientifique.php @@ -3,6 +3,7 @@ namespace model; use DateTime; +use Exception; use RuntimeException; class MdlScientifique extends MdlBase{ @@ -19,9 +20,12 @@ class MdlScientifique extends MdlBase{ $this->mdlThematique = new MdlThematique(); } + /** + * @throws Exception + */ public function getRandom(): Scientifique{ $row = $this->gw->getRandom(); - if($row == false) throw new RuntimeException("Erreur aucun scientifique trouvé"); + if(!$row) throw new RuntimeException("Erreur aucun scientifique trouvé"); $sexe = $this->mdlSexe->getFromId($row['idsexe']); $difficulte = $this->mdlDifficulte->getFromId($row['iddifficulte']); $thematique = $this->mdlThematique->getFromId($row['idthematique']); diff --git a/project/src/model/metier/Difficulty.php b/project/src/model/metier/Difficulty.php index 79801e9..b36a13a 100755 --- a/project/src/model/metier/Difficulty.php +++ b/project/src/model/metier/Difficulty.php @@ -2,9 +2,12 @@ namespace model; -enum Difficulty +class Difficulty { - case Easy; - case Medium; - case Hard; -} \ No newline at end of file + const EASY = 'Easy'; + const MEDIUM = 'Medium'; + const HARD = 'Hard'; +} + +// Usage +// $difficulty = Difficulty::EASY; \ No newline at end of file diff --git a/project/src/model/metier/Jeu.php b/project/src/model/metier/Jeu.php index 89c9161..156e4e0 100755 --- a/project/src/model/metier/Jeu.php +++ b/project/src/model/metier/Jeu.php @@ -11,7 +11,7 @@ class Jeu /** * @param int $id * @param string $nom - * @param string $nbParties + * @param int $nbrParties */ public function __construct(int $id, string $nom, int $nbrParties) { diff --git a/project/src/model/metier/Scientifique.php b/project/src/model/metier/Scientifique.php index 29eff43..2f1715f 100755 --- a/project/src/model/metier/Scientifique.php +++ b/project/src/model/metier/Scientifique.php @@ -22,7 +22,9 @@ class Scientifique * @param string $nom * @param string $prenom * @param string $photo + * @param DateTime $dateNaiss * @param string $descriptif + * @param float $ratioTrouvee * @param Thematique $thematique * @param Difficulte $difficulte * @param Sexe $sexe diff --git a/project/src/templates/accueil.html b/project/src/templates/accueil.html index eab2fe2..9d7ca30 100755 --- a/project/src/templates/accueil.html +++ b/project/src/templates/accueil.html @@ -3,7 +3,7 @@ - +