parent
2424a4c574
commit
83ecf5b0db
@ -1,105 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "../public/script/Connection.php";
|
||||
require_once "characterEntity.php";
|
||||
|
||||
class CharacterGateway
|
||||
{
|
||||
|
||||
private Connection $co;
|
||||
|
||||
public function __construct(Connection $co)
|
||||
{
|
||||
$this -> co = $co;
|
||||
}
|
||||
|
||||
public function create(characterEntity $c) : bool
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO Character
|
||||
VALUES(:id_character, :name, :img_path)
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
"id_character" => array($c -> getIdCharacter(), PDO::PARAM_INT),
|
||||
"name" => array($c -> getName(), PDO::PARAM_STR),
|
||||
"img_path" => array($c -> getImgPath(), PDO::PARAM_STR)
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function findById(int $id) : ?characterEntity
|
||||
{
|
||||
$query = "SELECT * FROM Character WHERE id_character = :id_c";
|
||||
|
||||
$this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
|
||||
$res = $this ->co -> getResults();
|
||||
|
||||
if($res)
|
||||
return new characterEntity(
|
||||
$res["id_character"],
|
||||
$res["name"],
|
||||
$res["img_path"]
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function findByName(string $name) : ?characterEntity
|
||||
{
|
||||
$query = "SELECT * FROM Character WHERE name = :n";
|
||||
|
||||
$this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]);
|
||||
$res = $this ->co -> getResults();
|
||||
|
||||
if($res)
|
||||
return new characterEntity(
|
||||
$res["id_character"],
|
||||
$res["name"],
|
||||
$res["img_path"]
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function findAll() : array
|
||||
{
|
||||
$query = "SELECT * FROM Character";
|
||||
|
||||
$this -> co -> executeQuery($query);
|
||||
$res = $this ->co -> getResults();
|
||||
|
||||
$characters = [];
|
||||
|
||||
foreach ($res as $character)
|
||||
{
|
||||
$characters[] = new characterEntity(
|
||||
$character["id_character"],
|
||||
$character["name"],
|
||||
$character["img_path"]
|
||||
);
|
||||
}
|
||||
return $characters;
|
||||
}
|
||||
|
||||
public function delete(int $id) : bool
|
||||
{
|
||||
$query = "DELETE FROM Character WHERE id_character = :id_c";
|
||||
|
||||
return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
|
||||
}
|
||||
|
||||
public function update(characterEntity $c) : bool
|
||||
{
|
||||
$query = "
|
||||
UPDATE Character
|
||||
SET name = :n, img_path = :i
|
||||
WHERE id_character = :id_c
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
"id_c" => array($c -> getIdCharacter(), PDO::PARAM_INT),
|
||||
"name" => array($c -> getName(), PDO::PARAM_STR),
|
||||
"i" => array($c -> getImgPath(), PDO::PARAM_STR)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue