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.
74 lines
2.4 KiB
74 lines
2.4 KiB
<?php
|
|
require_once("Connection.php");
|
|
include_once("../business/Task.php");
|
|
|
|
class TaskGateway
|
|
{
|
|
// connection attribute
|
|
public Connection $con;
|
|
|
|
// constructor
|
|
public function __construct(Connection $con){
|
|
$this->con=$con;
|
|
}
|
|
|
|
// functions
|
|
// code de retour pour les fonctions i,u,d?
|
|
public function insert(Task $t){
|
|
$query='INSERT INTO Tache VALUES (:id,:titre,:descript,NULL,NULL,:priorite,:idList)';
|
|
|
|
$this->con->executeQuery($query, array(
|
|
':id'=> array($t->get_id(),PDO::PARAM_STR),
|
|
':titre'=> array($t->get_titre(),PDO::PARAM_STR),
|
|
':descript'=> array($t->get_description(),PDO::PARAM_STR),
|
|
':priorite'=> array($t->get_priorite(),PDO::PARAM_STR),
|
|
':idList'=> array($t->get_idList(),PDO::PARAM_STR) ));
|
|
|
|
/*Comment gerer les erreurs?
|
|
* si valeur existe deja
|
|
*/
|
|
}
|
|
|
|
public function update($id,$element, $valeur){
|
|
$query='UPDATE Tache SET '.$element.'=:'.$element.' WHERE id=:id';
|
|
|
|
$this->con->executeQuery($query, array(
|
|
':id'=>array($id,PDO::PARAM_STR),
|
|
':'.$element =>array($valeur,PDO::PARAM_STR)));
|
|
/*
|
|
element é o attributo da classe, valaeur é oque queremos botar
|
|
*/
|
|
}
|
|
|
|
public function delete($id){
|
|
$query='DELETE FROM Tache WHERE id = :id';
|
|
|
|
$this->con->executeQuery($query, array(
|
|
':id'=>array($id,PDO::PARAM_STR)));
|
|
}
|
|
|
|
/*si on veut trouver une liste, juste chercher toutes les taches avec idList= id_de_la_liste*/
|
|
public function find($element="", $valeur=""){
|
|
if(strcmp($element,"")==0)
|
|
{
|
|
$query='SELECT * FROM Tache';
|
|
$this->con->executeQuery($query);
|
|
}
|
|
else
|
|
{
|
|
$query='SELECT * FROM Tache WHERE '.$element.'=:'.$element;
|
|
$this->con->executeQuery($query, array(
|
|
':'.$element =>array($valeur,PDO::PARAM_STR)));
|
|
}
|
|
|
|
$results=$this->con->getResults();
|
|
foreach($results as $row)
|
|
{
|
|
$tabTaches[]=new Task($row['id'],$row['titre'],$row['description'],$row['priorite'],
|
|
$row['idList'],$row['dateDebut'],$row['dateFin']);
|
|
}
|
|
return $tabTaches;
|
|
}
|
|
}
|
|
?>
|