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('./metier/tache.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(Tache $t): void{
$query = "DELETE FROM Tache where id=:id";
$this->con->executeQuery($query, array(':id' => array($t->getId(), 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 findByName(string $name): array{
if (!empty($name)){
$query = "SELECT * FROM Tache WHERE name=:name";
$this->con->executeQuery($query, array(':name' => array($name, PDO::PARAM_STR)));
$results=$con->getResults();
foreach ($results as $row ) {
$tabTaches[]=new Tache($row['id'], $row['name'], $row['content']);
}
return $tabTaches;
}
}
*/
}
?>