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.

64 lines
2.3 KiB

<?php
require_once('user.php');
class UserGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(User $u): void{
$query = "INSERT INTO Utilisateur VALUES (null, :username, :password)";
$this->con->executeQuery($query, array(':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
}
public function delete(User $u): void{
$query = "DELETE FROM Utilisateur where id=:id";
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT)));
}
public function update(User $u): void{
$query = "UPDATE Utilisateur SET username=:username, password=:password WHERE id=:id";
$this->con->executeQuery($query, array(':id' => array($u->getId(), PDO::PARAM_INT), ':username' => array($u->getUsername(), PDO::PARAM_STR), ':password' => array($u->getPassword(), PDO::PARAM_STR)));
}
public function findByNamePassword(string $username, string $password): ?User{
if (!empty($username) && !empty($password)){
$query = "SELECT * FROM Utilisateur WHERE username=:username AND password=:password";
$this->con->executeQuery($query, array(':username' => array($username, PDO::PARAM_STR), ':password' => array($password, PDO::PARAM_STR)));
$results=$this->con->getResults();
if (!empty($results)){
$user=new User($results[0]['id'], $results[0]['username'], $results[0]['password']);
return $user;
}
}
return null;
}
public function getLastId(): int{
$query = "SELECT max(id) as oldId FROM User";
$this->con->executeQuery($query, array());
$results=$this->con->getResults();
return $results[0]['oldId'];
}
/*
public function getTacheFromIdList(int $id): array{
$tabTaches=[];
$query = "SELECT * FROM Tache t where idListe=:id";
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
$results=$this->con->getResults();
foreach ($results as $row) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content'], $row['completed']);
}
return $tabTaches;
}
*/
}
?>