diff --git a/project/src/model/gateways/JoueurGateway.php b/project/src/model/gateways/JoueurGateway.php new file mode 100644 index 0000000..5a24050 --- /dev/null +++ b/project/src/model/gateways/JoueurGateway.php @@ -0,0 +1,29 @@ +con = $con; + } + + public function getFromPseudo($pseudo): array|bool + { + $this->con->executeQuery("SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;", + [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); + return $this->con->getOneResult(); + } + + public function insertJoueur(string $pseudo): int{ + if($this->getFromPseudo($pseudo) != false){ + throw new PseudoDejaPrisException(); + }else{ + $this->con->executeQuery("INSERT INTO Joueur(pseudo) VALUES(:pseudo);", + [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); + return $this->getFromPseudo($pseudo)["id"]; + } + } +} \ No newline at end of file