From 8acb7ab48eb385b7d14909c3a18dff7d72ea1535 Mon Sep 17 00:00:00 2001 From: "victor.soulier" Date: Sat, 18 Nov 2023 16:23:17 +0100 Subject: [PATCH] ADD : gateway joueur --- project/src/model/gateways/JoueurGateway.php | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 project/src/model/gateways/JoueurGateway.php 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