ADD : methode getFromId

correction_routeur^2
Victor SOULIER 1 year ago
parent c486697393
commit e6d6f8aada

@ -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;

Loading…
Cancel
Save