generated from Templates_CodeFirst/templateHtmlCss
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.
61 lines
2.2 KiB
61 lines
2.2 KiB
<?php
|
|
|
|
class TacheGateway
|
|
{
|
|
|
|
|
|
private $con;
|
|
|
|
public function __construct(Connection $con){
|
|
$this->con = $con;
|
|
}
|
|
|
|
public function insert(Tache $t, int $idList): void{
|
|
$query = "INSERT INTO Tache VALUES (null, :name, :content, :completed, :idList)";
|
|
$this->con->executeQuery($query, array(':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL), ':idList' => array($idList, PDO::PARAM_INT)));
|
|
}
|
|
|
|
public function delete(int $id): void{
|
|
$query = "DELETE FROM Tache where id=:id";
|
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT)));
|
|
}
|
|
|
|
public function update(Tache $t): void{
|
|
$query = "UPDATE Tache SET name=:name, content=:content, completed=:completed WHERE id=:id";
|
|
$this->con->executeQuery($query, array(':id' => array($t->getId(), PDO::PARAM_INT), ':name' => array($t->getName(), PDO::PARAM_STR), ':content' => array($t->getContent(), PDO::PARAM_STR), ':completed' => array($t->getCompleted(), PDO::PARAM_BOOL)));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public function getLastId(): int{
|
|
$query = "SELECT max(id) as oldId FROM Tache";
|
|
$this->con->executeQuery($query, array());
|
|
$results=$this->con->getResults();
|
|
return $results[0]['oldId'];
|
|
}
|
|
|
|
|
|
public function findById(int $id): ?Tache{
|
|
$tache=null;
|
|
$query = "SELECT * FROM Tache WHERE id=:id";
|
|
$this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_STR)));
|
|
|
|
$results=$this->con->getResults();
|
|
foreach ($results as $row ) {
|
|
$tache=new Tache($row['id'], $row['name'], $row['content'], $row['completed']);
|
|
}
|
|
return $tache;
|
|
|
|
}
|
|
}
|
|
|
|
?>
|