parent
07690552d7
commit
c62529c821
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Entity;
|
||||
class CharacterEntity
|
||||
{
|
||||
|
||||
private int $id_character;
|
||||
|
||||
private string $name;
|
||||
|
||||
private string $img_char;
|
||||
|
||||
public function __construct(int $id_character, string $name, string $img_char)
|
||||
{
|
||||
$this -> id_character = $id_character;
|
||||
$this -> name = $name;
|
||||
$this -> img_char = $img_char;
|
||||
}
|
||||
|
||||
public function getIdCharacter(): int
|
||||
{
|
||||
return $this -> id_character;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this -> name;
|
||||
}
|
||||
|
||||
public function getImgChar(): string
|
||||
{
|
||||
return $this -> img_char;
|
||||
}
|
||||
|
||||
public function setIdCharacter(int $id_character): void
|
||||
{
|
||||
$this -> id_character = $id_character;
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this -> name = $name;
|
||||
}
|
||||
|
||||
public function setImgChar(string $img_char): void
|
||||
{
|
||||
$this -> img_char = $img_char;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
class CharacterEntity
|
||||
{
|
||||
|
||||
private int $id_character;
|
||||
|
||||
private string $name;
|
||||
|
||||
private string $img_path;
|
||||
|
||||
public function __construct(int $id_character, string $name, string $img_path)
|
||||
{
|
||||
$this -> id_character = $id_character;
|
||||
$this -> name = $name;
|
||||
$this -> img_path = $img_path;
|
||||
}
|
||||
|
||||
public function getIdCharacter() : int
|
||||
{
|
||||
return $this -> id_character;
|
||||
}
|
||||
public function getName() : string
|
||||
{
|
||||
return $this -> name;
|
||||
}
|
||||
public function getImgPath() : string
|
||||
{
|
||||
return $this -> img_path;
|
||||
}
|
||||
|
||||
public function setIdCharacter(int $id_character) : void
|
||||
{
|
||||
$this -> id_character = $id_character;
|
||||
}
|
||||
public function setName(string $name) : void
|
||||
{
|
||||
$this -> name = $name;
|
||||
}
|
||||
public function setImgPath(string $img_path) : void
|
||||
{
|
||||
$this -> img_path = $img_path;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Gateway;
|
||||
use Connection;
|
||||
use PDO;
|
||||
use Entity\characterEntity;
|
||||
|
||||
|
||||
class CharacterGateway
|
||||
{
|
||||
|
||||
private Connection $co;
|
||||
|
||||
public function __construct(Connection $co)
|
||||
{
|
||||
$this -> co = $co;
|
||||
}
|
||||
|
||||
public function create(int $id_character, string $name , string $img_char) : bool
|
||||
{
|
||||
$query = "
|
||||
INSERT INTO Characters
|
||||
VALUES(:id_char, :name, :img_char)
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
'id_char' => array($id_character, PDO::PARAM_INT),
|
||||
'name' => array($name, PDO::PARAM_STR),
|
||||
'img_char' => array($img_char, PDO::PARAM_STR)
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function findById(int $id) : array
|
||||
{
|
||||
$query = "SELECT * FROM Characters WHERE id_char = :id_c";
|
||||
$this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function findByName(string $name) : array
|
||||
{
|
||||
$query = "SELECT * FROM Characters WHERE name = :n";
|
||||
$this -> co -> executeQuery($query, ["n" => array($name, PDO::PARAM_STR)]);
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function findAll() : array
|
||||
{
|
||||
$query = "SELECT * FROM Characters";
|
||||
$this -> co -> executeQuery($query);
|
||||
return $this -> co -> getResults();
|
||||
}
|
||||
|
||||
public function delete(int $id) : bool
|
||||
{
|
||||
$query = "DELETE FROM Characters WHERE id_char = :id_c";
|
||||
return $this -> co -> executeQuery($query, ["id_c" => array($id, PDO::PARAM_INT)]);
|
||||
}
|
||||
|
||||
public function update(int $id_char, string $name, string $img_char) : bool
|
||||
{
|
||||
$query = "
|
||||
UPDATE Characters
|
||||
SET name = :n, img_char = :i
|
||||
WHERE id_char = :id_c
|
||||
";
|
||||
|
||||
return $this -> co -> executeQuery($query, [
|
||||
"id_c" => array($id_char, PDO::PARAM_INT),
|
||||
"name" => array($name, PDO::PARAM_STR),
|
||||
"i" => array($img_char, PDO::PARAM_STR)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -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)
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
use Entity\CharacterEntity;
|
||||
use Gateway\CharacterGateway;
|
||||
|
||||
|
||||
class CharacterModel
|
||||
{
|
||||
|
||||
private CharacterGateway $gateway;
|
||||
|
||||
public function __construct(characterGateway $gw)
|
||||
{
|
||||
$this -> gateway = $gw;
|
||||
}
|
||||
|
||||
public function createCharacter(int $id_character, string $name , string $img_char) : bool
|
||||
{
|
||||
return $this -> gateway -> create($id_character, $name, $img_char);
|
||||
}
|
||||
|
||||
public function getCharacterById(int $id_character) : ?CharacterEntity
|
||||
{
|
||||
$c = $this -> gateway -> findById($id_character);
|
||||
if ($c)
|
||||
return new CharacterEntity(
|
||||
$c['id_character'],
|
||||
$c['name'],
|
||||
$c['img_path']
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getCharacterByName(string $name) : ?CharacterEntity
|
||||
{
|
||||
$c = $this -> gateway -> findByName($name);
|
||||
if ($c)
|
||||
return new CharacterEntity(
|
||||
$c['id_character'],
|
||||
$c['name'],
|
||||
$c['img_path']
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAllCharacters() : array
|
||||
{
|
||||
$c = $this -> gateway -> findAll();
|
||||
|
||||
$characters = [];
|
||||
|
||||
foreach ($c as $character)
|
||||
{
|
||||
$characters[] = new CharacterEntity(
|
||||
$character['id_character'],
|
||||
$character['name'],
|
||||
$character['img_path']
|
||||
);
|
||||
}
|
||||
return $characters;
|
||||
}
|
||||
|
||||
public function deleteCharacter(int $id_character) : bool
|
||||
{
|
||||
return $this -> gateway -> delete($id_character);
|
||||
}
|
||||
|
||||
public function updateCharacter(int $id_character, string $name, string $img_char) : bool
|
||||
{
|
||||
return $this -> gateway -> update($id_character, $name, $img_char);
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "characterEntity.php";
|
||||
require_once "characterGateway.php";
|
||||
|
||||
class CharacterModel
|
||||
{
|
||||
|
||||
private characterGateway $gateway;
|
||||
|
||||
public function __construct(characterGateway $gateway)
|
||||
{
|
||||
$this -> gateway = $gateway;
|
||||
}
|
||||
|
||||
public function createCharacter(int $id_character, string $name , string $img_path) : bool
|
||||
{
|
||||
$q = new CharacterEntity($id_character, $name, $img_path);
|
||||
|
||||
return $this -> gateway -> create($q);
|
||||
}
|
||||
public function getCharacterById(int $id_character) : ?CharacterEntity
|
||||
{
|
||||
return $this -> gateway -> findById($id_character);
|
||||
}
|
||||
|
||||
public function getCharacterByName(string $name) : ?CharacterEntity
|
||||
{
|
||||
return $this -> gateway -> findByName($name);
|
||||
}
|
||||
|
||||
public function getAllCharacters() : array
|
||||
{
|
||||
return $this -> gateway -> findAll();
|
||||
}
|
||||
|
||||
public function deleteCharacter(int $id_character) : bool
|
||||
{
|
||||
return $this -> gateway -> delete($id_character);
|
||||
}
|
||||
|
||||
public function updateCharacter(int $id_character, string $name, string $img_path) : bool
|
||||
{
|
||||
$q = $this -> gateway -> findById($id_character);
|
||||
|
||||
if($q){
|
||||
$q -> setName($name);
|
||||
$q -> setImgPath($img_path);
|
||||
return $this -> gateway -> update($q);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue