|
|
@ -20,32 +20,15 @@ class ImageGateway
|
|
|
|
|
|
|
|
|
|
|
|
public function insertImage(Image $img)
|
|
|
|
public function insertImage(Image $img)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$query = "INSERT INTO Image (`nom`, `taille`, `type`, `desc`, `blob`) VALUES ( :n, :t, :ty, :d, :b)";
|
|
|
|
$query = "INSERT INTO Image (`nom`, `taille`, `type`, `blob`) VALUES ( :n, :t, :ty, :b)";
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':n' => array($img->getName(), PDO::PARAM_STR),
|
|
|
|
':n' => array($img->getName(), PDO::PARAM_STR),
|
|
|
|
':t' => array($img->getTaille(), PDO::PARAM_STR),
|
|
|
|
':t' => array($img->getTaille(), PDO::PARAM_STR),
|
|
|
|
':ty' => array($img->getType(), PDO::PARAM_STR),
|
|
|
|
':ty' => array($img->getType(), PDO::PARAM_STR),
|
|
|
|
':d' => array("desc", PDO::PARAM_STR),
|
|
|
|
|
|
|
|
':b' => array($img->getBlob(), PDO::PARAM_STR)
|
|
|
|
':b' => array($img->getBlob(), PDO::PARAM_STR)
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function insert(int $id,string $name, string $desc, string $taille, string $type, string $blob)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$query = 'INSERT INTO Image VALUES (:i, :n, :t, :ty, :d, :b)';
|
|
|
|
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
|
|
|
|
':i' => array($id,PDO::PARAM_INT),
|
|
|
|
|
|
|
|
':n' => array($name, PDO::PARAM_STR),
|
|
|
|
|
|
|
|
':t' => array($taille, PDO::PARAM_STR),
|
|
|
|
|
|
|
|
':ty' => array($type, PDO::PARAM_STR),
|
|
|
|
|
|
|
|
':d' => array($desc, PDO::PARAM_STR),
|
|
|
|
|
|
|
|
':b' => array($blob, PDO::PARAM_STR)
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function delete(int $id)
|
|
|
|
public function delete(int $id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$query = 'DELETE FROM Image WHERE id=:i';
|
|
|
|
$query = 'DELETE FROM Image WHERE id=:i';
|
|
|
@ -54,14 +37,13 @@ class ImageGateway
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function findById(int $id)
|
|
|
|
public function obtenirParId(int $id) : array
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$query = 'SELECT * FROM Image WHERE id=:i';
|
|
|
|
$query = 'SELECT * FROM Image WHERE id=:i';
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':i' => array($id, PDO::PARAM_INT)
|
|
|
|
':i' => array($id, PDO::PARAM_INT)
|
|
|
|
));
|
|
|
|
));
|
|
|
|
$res = $this->con->getResults();
|
|
|
|
return $this->con->getResults();
|
|
|
|
return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function trouverParNom(string $nom)
|
|
|
|
public function trouverParNom(string $nom)
|
|
|
@ -70,8 +52,7 @@ class ImageGateway
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
$this->con->executeQuery($query, array(
|
|
|
|
':n' => array($nom, PDO::PARAM_STR)
|
|
|
|
':n' => array($nom, PDO::PARAM_STR)
|
|
|
|
));
|
|
|
|
));
|
|
|
|
$res = $this->con->getResults();
|
|
|
|
return $this->con->getResults();
|
|
|
|
return new Image($res[0]["id"],$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -84,17 +65,17 @@ class ImageGateway
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return intval($res[0]['MAX(id)'])+1;
|
|
|
|
return intval($res[0]['MAX(id)'])+1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getAll()
|
|
|
|
public function obtenirToutesImages()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$query = 'SELECT * FROM Image';
|
|
|
|
$query = 'SELECT * FROM Image';
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$this->con->executeQuery($query);
|
|
|
|
$res = $this->con->getResults();
|
|
|
|
$res = $this->con->getResults();
|
|
|
|
$array = [];
|
|
|
|
$array = [];
|
|
|
|
foreach ($res as $r) {
|
|
|
|
foreach ($res as $r) {
|
|
|
|
$array[] = new Image($r['nom'], $r['taille'], $r['type'], $r['blob']);
|
|
|
|
$array[] = new Image($this->getNewId(),$r['nom'], $r['taille'], $r['type'], $r['blob']);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $array;
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|