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.

68 lines
2.3 KiB

<?php
require_once('liste.php');
class ListeGateway
{
private $con;
public function __construct(Connection $con){
$this->con = $con;
}
public function insert(Liste $l): void{
$tacheGateway=new TacheGateway($this->con);
if ($l->getCreator()==null){
$query = "INSERT INTO Liste VALUES (null, :name, :private, null)";
$this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL)));
}
else{
$query = "INSERT INTO Liste VALUES (null, :name, :private, :creator)";
$this->con->executeQuery($query, array(':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL), ':creator' => array($l->getCreator()->getId(), PDO::PARAM_STR)));
}
foreach($l->getTaches() as $taches){
$tacheGateway->insert($taches, $this->getLastId());
}
}
public function delete(Liste $l): void{
$tacheGateway=new TacheGateway($this->con);
foreach($l->getTaches() as $taches){
$tacheGateway->delete($taches);
}
$query = "DELETE FROM Liste where id=:id";
$this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT)));
}
public function update(Liste $l): void{
$query = "UPDATE Liste SET name=:name, private=:private WHERE id=:id";
$this->con->executeQuery($query, array(':id' => array($l->getId(), PDO::PARAM_INT), ':name' => array($l->getName(), PDO::PARAM_STR), ':private' => array($l->getPrivate(), PDO::PARAM_BOOL)));
}
public function getLastId(): int{
$query = "SELECT max(id) as oldId FROM Liste";
$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;
}
}
*/
}
?>