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.
ProjetPHP/dal/TaskGateway.php

112 lines
4.1 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 insertT(Task $t){
$query='INSERT INTO Tache VALUES (:id,:titre,:descript,NULL,NULL,:priorite,:idList,false)';
$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($table,$id,$element, $valeur){
if($table == 'task'){
$query='UPDATE Tache SET '.$element.'=:'.$element.' WHERE id=:id';
} else {
$query='UPDATE uList SET '.$element.'=:'.$element.' WHERE id=:id';
}
$this->con->executeQuery($query, array(
':id'=>array($id,PDO::PARAM_STR),
':'.$element =>array($valeur,PDO::PARAM_STR)));
}
public function delete($table,$id){
if($table == 'task'){
$query='DELETE FROM Tache WHERE id = :id';
} else {
$query='DELETE FROM uList 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*/
# pour toutes les listes d'un user specifique, appeller 2 fois la fonction:
# une fois pour prendre toutes les listes qui ont l'id de l'user
# pour toutes ces listes (foreach), find toutes chaque tache associé
public function find($table, $element="", $valeur=""){
if($table =='task'){
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'],$row['isDone']);
}
return $tabTaches;
} else if($table == 'list'){
if(strcmp($element,"")==0)
{
$query='SELECT * FROM uList';
$this->con->executeQuery($query);
}
else
{
$query='SELECT * FROM uList WHERE '.$element.'=:'.$element;
$this->con->executeQuery($query, array(
':'.$element =>array($valeur,PDO::PARAM_STR)));
}
$results=$this->con->getResults();
foreach($results as $row)
{
$tabList[]=new ListTask($row['id'],$row['nom'],$row['user'],$row['dc']);
}
return $tabList;
}
}
/* # LIST FUNCTIONS */
/*create, update, delete, read(select info)*/
public function insertL(ListTask $l){
$query='INSERT INTO uList VALUES (:id,:nom,:user,0)';
$this->con->executeQuery($query, array(
':id'=> array($l->get_id(),PDO::PARAM_STR),
':nom'=> array($l->get_nom(),PDO::PARAM_STR),
':user'=> array($l->get_owner(),PDO::PARAM_STR)));
}
}
?>