Add Image Gateway & Model

pull/17/head
tomivt 6 months ago
parent cb8db98aac
commit df1de5ff32

@ -0,0 +1,53 @@
<?php
namespace Entity;
class ImageEntity
{
private int $idImg;
private string $imgPath;
private string $isImgProfile;
/**
* @param int $idImg
* @param string $imgPath
* @param string $isImgProfile
*/
public function __construct(int $idImg, string $imgPath, string $isImgProfile)
{
$this->idImg = $idImg;
$this->imgPath = $imgPath;
$this->isImgProfile = $isImgProfile;
}
public function getIdImg(): int
{
return $this->idImg;
}
public function setIdImg(int $idImg): void
{
$this->idImg = $idImg;
}
public function getImgPath(): string
{
return $this->imgPath;
}
public function setImgPath(string $imgPath): void
{
$this->imgPath = $imgPath;
}
public function getIsImgProfile(): string
{
return $this->isImgProfile;
}
public function setIsImgProfile(string $isImgProfile): void
{
$this->isImgProfile = $isImgProfile;
}
}

@ -1,53 +0,0 @@
<?php
namespace Entity;
class ImageEntity
{
private int $id_img;
private string $img_path;
private string $isImgProfil;
/**
* @param int $id_img
* @param string $img_path
* @param string $isImgProfil
*/
public function __construct(int $id_img, string $img_path, string $isImgProfil)
{
$this->id_img = $id_img;
$this->img_path = $img_path;
$this->isImgProfil = $isImgProfil;
}
public function getIdImg(): int
{
return $this->id_img;
}
public function setIdImg(int $id_img): void
{
$this->id_img = $id_img;
}
public function getImgPath(): string
{
return $this->img_path;
}
public function setImgPath(string $img_path): void
{
$this->img_path = $img_path;
}
public function getIsImgProfil(): string
{
return $this->isImgProfil;
}
public function setIsImgProfil(string $isImgProfil): void
{
$this->isImgProfil = $isImgProfil;
}
}

@ -0,0 +1,88 @@
<?php
namespace Gateway;
use Gateway\Connection;
use PDO;
class ImageGateway
{
private Connection $co;
public function __construct(Connection $co)
{
$this -> co = $co;
}
public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool
{
$query = "
INSERT INTO Images
VALUES (:id_img, :img_path, :is_img_profile)
";
return $this -> co -> executeQuery($query, [
'id_img' => array($idImg, PDO::PARAM_INT),
'img_path' => array($idImg, PDO::PARAM_STR),
'is_img_profile' => array($idImg, PDO::PARAM_BOOL),
]);
}
public function findImgById(int $idImg) : array
{
$query = "
SELECT * FROM Images
WHERE id_image = :id_img
";
$this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]);
return $this -> co -> getResults();
}
public function findAllImg() : array
{
$query = "
SELECT * FROM Images
";
$this -> co -> executeQuery($query);
return $this -> co -> getResults();
}
public function findAllImgProfile() : array
{
$query = "
SELECT * FROM Images
WHERE is_img_prfl
";
$this -> co -> executeQuery($query);
return $this -> co -> getResults();
}
public function deleteImgGateway(int $idImg) : bool
{
$query = "
DELETE FROM Images
WHERE id_image = :id_img
";
return $this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]);
}
public function updateImgGateway(int $idImg, string $imgPath) : bool
{
$query = "
UPDATE Images
SET img_path = :img_path
WHERE id_image = :id_img
";
return $this -> co -> executeQuery($query, [
'id_img' => array($idImg, PDO::PARAM_INT),
'img_path' => array($imgPath, PDO::PARAM_STR)
]);
}
}

@ -0,0 +1,80 @@
<?php
namespace Model;
use Entity\ImageEntity;
use Gateway\ImageGateway;
class ImageModel
{
private ImageGateway $gw;
public function __construct(ImageGateway $gw)
{
$this -> gw = $gw;
}
public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool
{
return $this -> gw -> createImgGateway($idImg, $imgPath, $isImgProfile);
}
public function getImgById(int $idImg) : ?ImageEntity
{
$res = $this -> gw -> findImgById($idImg);
if ($res)
{
return new ImageEntity(
$res[0]['id_image'],
$res[0]['img_path'],
$res[0]['is_img_prfl']
);
}
return null;
}
public function getAllImg() : array
{
$res = $this -> gw -> findAllImg();
$images = [];
foreach ($res as $img)
{
$images[] = new ImageEntity(
$img['id_image'],
$img['img_path'],
$img['is_img_prfl']
);
}
return $images;
}
public function getAllImgProfile() : array
{
$res = $this -> gw -> findAllImgProfile();
$images = [];
foreach ($res as $img)
{
$images[] = new ImageEntity(
$img['id_image'],
$img['img_path'],
$img['is_img_prfl']
);
}
return $images;
}
public function deleteImgModel(int $idImg) : bool
{
return $this -> gw -> deleteImgGateway($idImg);
}
public function updateImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool
{
return $this -> gw -> updateImgGateway($idImg, $imgPath, $isImgProfile);
}
}
Loading…
Cancel
Save