You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.4 KiB
83 lines
2.4 KiB
<?php
|
|
|
|
require_once "../Model/Joueur.php";
|
|
require_once "../Config/Connection.php";
|
|
|
|
class JoueurGateway
|
|
{
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
public function __construct(Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
/**
|
|
* @param Connection $con
|
|
*/
|
|
public function setCon(Connection $con): void
|
|
{
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(Joueur $joueur) : void{
|
|
$query = "INSERT INTO Joueur VALUE (:email,:pseudo,:mdp)";
|
|
$this->con->executeQuery($query, array(
|
|
':email' => array($joueur->getEmail(),PDO::PARAM_STR),
|
|
':pseudo' => array($joueur->getPseudo(),PDO::PARAM_STR),
|
|
':mdp' => array($joueur->getMdp(),PDO::PARAM_STR)));
|
|
}
|
|
|
|
public function delete(string $email) : void{
|
|
$query = "DELETE FROM Joueur WHERE email=:email";
|
|
$this->con->executeQuery($query, array(
|
|
':email' => array($email,PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
public function getJoueurByEmail(string $email) : Joueur{
|
|
$query = "SELECT * FROM Joueur WHERE email=:email";
|
|
$this->con->executeQuery($query, array(
|
|
':email' => array($email,PDO::PARAM_STR)
|
|
));
|
|
$results=$this->con->getResults();
|
|
foreach ($results as $row) {
|
|
$email=$row['email'];
|
|
$pseudo=$row['pseudo'];
|
|
$mdp=$row['mdp'];
|
|
}
|
|
if ($results == null){
|
|
throw new JoueurNotFoundException("Joueur Introuvable");
|
|
}
|
|
return new Joueur($email, $pseudo, $mdp);
|
|
}
|
|
|
|
public function getMdpByEmail(string $email) : string{
|
|
$query = "SELECT mdp FROM Joueur WHERE email=:email";
|
|
$this->con->executeQuery($query, array(
|
|
':email' => array($email,PDO::PARAM_STR)
|
|
));
|
|
$results=$this->con->getResults();
|
|
foreach ($results as $row) {
|
|
$mdp=$row['mdp'];
|
|
}
|
|
if ($results == null){
|
|
throw new InvalidMdpException("Mots de passe Incorrect");
|
|
}
|
|
return $mdp;
|
|
}
|
|
|
|
public function showAll() : void{
|
|
$query = "SELECT * FROM Joueur";
|
|
$this->con->executeQuery($query);
|
|
$results=$this->con->getResults();
|
|
foreach ($results as $row) {
|
|
echo $row['email'] . '</br>';
|
|
echo $row['pseudo'] . '</br>';
|
|
echo $row['mdp'] . '</br>';
|
|
}
|
|
|
|
}
|
|
} |