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.
54 lines
1.3 KiB
54 lines
1.3 KiB
<?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;
|
|
}
|
|
|
|
} |