diff --git a/project/src/model/gateways/InviteGateway.php b/project/src/model/gateways/InviteGateway.php index 6d0a823..9404c60 100644 --- a/project/src/model/gateways/InviteGateway.php +++ b/project/src/model/gateways/InviteGateway.php @@ -4,25 +4,32 @@ namespace model; class InviteGateway extends JoueurGateway { - private $con; function __construct(Connection $con) { - $this->con = $con; + parent::__construct($con); } public function getFromIdSession($idSession): array|bool { - $this->con->executeQuery("SELECT id, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;", + $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]]); + return $this->con->getOneResult(); + } + public function insertInvite(string $pseudo, string $idSession): int{ - if($this->getFromIdSession($idSession) != false){ - throw new IdSessionDoubleException(); + $row = $this->getFromIdSession($idSession); + if($row != false){ + throw new IdSessionDoubleException($row['idjoueur'], $row['idsession']); }else{ $id = $this->insertJoueur($pseudo); - $this->con->executeQuery("INSERT INTO Invite(id, idSession) VALUES(:id, :idSession);", + $this->con->executeQuery("INSERT INTO Invite(idJoueur, idSession) VALUES(:id, :idSession);", [":id" => [$id, $this->con::PARAM_INT], ":idSession" => [$idSession, $this->con::PARAM_STR]]); return $id;