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.
WF-Website/src/Model/CharacterModel.php

80 lines
2.1 KiB

<?php
namespace Model;
use Entity\CharacterEntity;
use Gateway\CharacterGateway;
use Gateway\Gateway;
class CharacterModel extends Model
{
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[0]['id_caracter'],
$c[0]['caracter'],
$c[0]['id_img']
);
return null;
}
public function getAllPerso() :array{
$res = $this->gateway->findAll();
foreach($res as $c){
$charac[] = new CharacterEntity(
$c['id_caracter'],
$c['caracter'],
$c['id_img']
);
}
return $charac;
}
public function getCharacterByName(string $name) : ?CharacterEntity
{
$c = $this -> gateway -> findByName($name);
if ($c)
return new CharacterEntity(
$c[0]['id_caracter'],
$c[0]['caracter'],
$c[0]['id_img']
);
return null;
}
public function getAllCharacters() : array
{
$c = $this -> gateway -> findAll();
$characters = [];
foreach ($c as $character)
{
$characters[] = new CharacterEntity(
$character['id_caracter'],
$character['caracter'],
$character['id_img']
);
}
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);
}
}