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.
91 lines
2.8 KiB
91 lines
2.8 KiB
<?php
|
|
namespace App\gateway;
|
|
use PDO;
|
|
|
|
class AlumniGateway
|
|
{
|
|
private \App\gateway\Connection $con;
|
|
|
|
/**
|
|
* @param $con
|
|
*/
|
|
public function __construct(\App\gateway\Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(string $email, string $motDePasse, string $role){
|
|
$query = 'INSERT INTO Alumni (mail, mdp, role) VALUES (:mail, :mdp, :role)';
|
|
return $this->con->executeQuery($query, array(
|
|
':mail' => array($email, PDO::PARAM_STR),
|
|
':mdp' => array($motDePasse, PDO::PARAM_STR),
|
|
':role' => array($role, PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
|
|
public function updateEmail(int $id, string $newEmail){
|
|
$query='UPDATE Alumni SET email=:new WHERE id=:i';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT),
|
|
':new' => array($newEmail, PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
public function updateMotDePasse(int $id, string $password){
|
|
$query='UPDATE Alumni SET motDePasse=:new WHERE id=:i';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT),
|
|
':new' => array($password, PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
public function updateRole(int $id, Role $newRole){
|
|
$query='UPDATE Alumni SET role=:new WHERE id=:i';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT),
|
|
':new' => array($newRole, PDO::PARAM_STR)
|
|
));
|
|
}
|
|
|
|
public function delete(int $id){
|
|
$query='DELETE FROM Alumni WHERE id=:i';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT)
|
|
));
|
|
}
|
|
|
|
public function findById(int $id){
|
|
$query = 'SELECT * FROM Alumni WHERE id=:i';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT)
|
|
));
|
|
$res=$this->con->getResults();
|
|
return new Alumni($res[0]['mail'],$res[0]['id'],$res[0]['mdp'],$res[0]['role']);
|
|
}
|
|
|
|
public function findByEmail(string $email){
|
|
$query='SELECT * FROM Alumni WHERE mail=:e';
|
|
$this->con->executeQuery($query, array(
|
|
':e' => array($email, PDO::PARAM_STR),
|
|
));
|
|
$res=$this->con->getResults();
|
|
var_dump($res);
|
|
if(count($res)==0){
|
|
echo "Aucun utilisateur trouvé";
|
|
return null;
|
|
}
|
|
echo "Utilisateur trouvé";
|
|
return new \App\metier\Alumni($res[0]['mail'],$res[0]['mdp'],$res[0]['role']);
|
|
}
|
|
|
|
public function getAll(){
|
|
$query='SELECT * FROM Alumni';
|
|
$this->con->executeQuery($query);
|
|
$res=$this->con->getResults();
|
|
$array=[];
|
|
foreach($res as $r){
|
|
$array[]=new Alumni($r['mail'],$r['id'],$r['mdp'],$r['role']);
|
|
}
|
|
return $array;
|
|
}
|
|
} |