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.
Application-Web/src/Model/TeamModel.php

53 lines
1.4 KiB

<?php
namespace App\Model;
use App\Data\Color;
use App\Gateway\TeamGateway;
use App\Data\Team;
/**
*
*/
class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) pour le controller qui l'utilise, catch celle de la gw, */
{
/**
* Attributes used to handle errors
*/
public const ERROR_INVALID_COLOR = 0;
public const ERROR_INVALID_NAME = 1;
public const ERROR_INVALID_PICTURE = 2;
public const ERROR_INVALID_SEARCH = 3;
public const ERROR_NO_DATA_FOUND = 4;
private TeamGateway $gateway;
/**
* @param TeamGateway $gateway
*/
public function __construct(TeamGateway $gateway)
{
$this->gateway = $gateway;
}
public function createTeam(string $name,string $picture,int $mainColor, int $secondColor) {
$this->gateway->insert($name,$picture,$mainColor,$secondColor);
}
public function listByName(string $name,array &$errors):array {
$teams=[];
if(Validation::hasHTMLInjection($name)){
$errors = self::ERROR_INVALID_SEARCH;
}
$results = $this->gateway->listByName($name);
if(empty($results)){
$errors = self::ERROR_NO_DATA_FOUND;
}
foreach ($results as $row){
$teams[] = new Team($row['name'],$row['picture'],$row['mainColor'],$row['secondColor']);
}
return $results;
}
}