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.6 KiB
83 lines
2.6 KiB
<?php
|
|
|
|
class AlumniGateway
|
|
{
|
|
private Connection $con;
|
|
|
|
/**
|
|
* @param $con
|
|
*/
|
|
public function __construct(Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(string $email, int $id, string $motDePasse, Role $role){
|
|
$query='INSERT INTO Alumni VALUES (:i, :e, :m, :r)';
|
|
$this->con->executeQuery($query, array(
|
|
':i' => array($id, PDO::PARAM_INT),
|
|
':e' => array($email, PDO::PARAM_STR),
|
|
':m' => array($motDePasse, PDO::PARAM_STR),
|
|
':r' => 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 email=:e';
|
|
$this->con->executeQuery($query, array(
|
|
':e' => array($email, PDO::PARAM_STR),
|
|
));
|
|
$res=$this->con->getResults();
|
|
return new Alumni($res[0]['mail'],$res[0]['id'],$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;
|
|
}
|
|
} |