formated the code and verification plus some more css
continuous-integration/drone/push Build is failing Details

pull/16/head
Maël DAIM 1 year ago
parent 7199a80562
commit 76e64a5ae5

@ -49,14 +49,14 @@ $router->map("GET", "/tactic/new", fn() => $editorController->makeNew());
$router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->openEditorFor($id));
$router->map("GET", "/tactic/[i:id]", fn(int $id) => $visualizerController->openVisualizer($id));
$teamController = new \App\Controller\TeamController(new \App\Model\TeamModel(new \App\Gateway\TeamGateway($con)),$twig);
$router->map("GET","/team/new", fn()=>$teamController->displaySubmitTeam());
$router->map("POST","/team/new", fn()=>$teamController->SubmitTeam($_POST));
$teamController = new \App\Controller\TeamController(new \App\Model\TeamModel(new \App\Gateway\TeamGateway($con)));
$router->map("GET", "/team/new", fn() => $teamController->displaySubmitTeam());
$router->map("POST", "/team/new", fn() => $teamController->SubmitTeam($_POST));
$router->map("GET","/team/list", fn()=>$teamController->displayListTeamByName());
$router->map("POST","/team/list", fn()=>$teamController->ListTeamByName($_POST));
$router->map("GET", "/team/list", fn() => $teamController->displayListTeamByName());
$router->map("POST", "/team/list", fn() => $teamController->ListTeamByName($_POST));
$router->map("GET","/team/[i:id]", fn(int $id)=>$teamController->getTeam($id));
$router->map("GET", "/team/[i:id]", fn(int $id) => $teamController->getTeam($id));
$match = $router->match();

@ -8,10 +8,8 @@ use App\Http\ViewHttpResponse;
use App\Model\TeamModel;
use App\Validation\FieldValidationFail;
use App\Validation\Validators;
use \Twig\Environment;
class TeamController
{
class TeamController {
private TeamModel $model;
/**
@ -21,10 +19,14 @@ class TeamController
$this->model = $model;
}
public function displaySubmitTeam() : HttpResponse {
public function displaySubmitTeam(): HttpResponse {
return ViewHttpResponse::twig("insert_team.html.twig", []);
}
/**
* @param array<string, mixed> $request
* @return HttpResponse
*/
public function submitTeam(array $request): HttpResponse {
$errors = [];
@ -32,7 +34,7 @@ class TeamController
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()],
"mainColor" => [Validators::regex('/#(?:[0-9a-fA-F]{6})/')],
"secondColor" => [Validators::regex('/#(?:[0-9a-fA-F]{6})/')],
"picture" => [Validators::isURL()]
"picture" => [Validators::isURL()],
]);
if (!empty($errors)) {
$badFields = [];
@ -50,10 +52,14 @@ class TeamController
return ViewHttpResponse::twig("list_team_by_name.html.twig", []);
}
/**
* @param array<string , mixed> $request
* @return HttpResponse
*/
public function listTeamByName(array $request): HttpResponse {
$errors = [];
$request = HttpRequest::from($request, $errors, [
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()]
"name" => [Validators::lenBetween(1, 32), Validators::nameWithSpaces()],
]);
if (!empty($errors) && $errors[0] instanceof FieldValidationFail) {
@ -75,5 +81,3 @@ class TeamController
return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]);
}
}

@ -2,31 +2,31 @@
namespace App\Data;
use \InvalidArgumentException;
use InvalidArgumentException;
class Color {
/**
* @var string 6 bytes unsigned int that represents an RGB color
* @var string that represents an hexadecimal color code
*/
private string $hex;
/**
* @param string $value 6 bytes unsigned int that represents an RGB color
* @throws \InvalidArgumentException if the value is negative or greater than 0xFFFFFF
* @throws InvalidArgumentException if the value is negative or greater than 0xFFFFFF
*/
private function __construct(string $value) {
if ($value < 0 || $value > 0xFFFFFF) {
throw new InvalidArgumentException("int color value is invalid, must be positive and lower than 0xFFFFFF");
}
$this->value = $value;
$this->hex = $value;
}
/**
* @return string
*/
public function getValue(): string {
return $this->value;
return $this->hex;
}
public static function from(string $value): Color {
@ -39,10 +39,9 @@ class Color {
}
public static function tryFrom(string $value): ?Color {
if (!preg_match('/#(?:[0-9a-fA-F]{6})/',$value)) {
if (!preg_match('/#(?:[0-9a-fA-F]{6})/', $value)) {
return null;
}
return new Color($value);
}
}

@ -10,7 +10,6 @@ use http\Exception\InvalidArgumentException;
* encapsulates an integer value and use it as an enumeration discriminant
*/
final class MemberRole {
private const ROLE_PLAYER = 0;
private const ROLE_COACH = 1;
private const MIN = self::ROLE_PLAYER;
@ -25,11 +24,11 @@ final class MemberRole {
$this->value = $val;
}
public static function player(){
public static function player(): MemberRole {
return new MemberRole(MemberRole::ROLE_PLAYER);
}
public static function coach(){
public static function coach(): MemberRole {
return new MemberRole(MemberRole::ROLE_COACH);
}

@ -21,7 +21,7 @@ class Team {
* @param Color $secondColor
* @param Member[] $members
*/
public function __construct(int $id,string $name, string $picture, Color $mainColor, Color $secondColor, array $members =[]) {
public function __construct(int $id, string $name, string $picture, Color $mainColor, Color $secondColor, array $members = []) {
$this->id = $id;
$this->name = $name;
$this->picture = $picture;

@ -12,52 +12,68 @@ class TeamGateway {
$this->con = $con;
}
public function insert(string $name, string $picture, string $mainColor, string $secondColor) {
public function insert(string $name, string $picture, string $mainColor, string $secondColor): void {
$this->con->exec(
"INSERT INTO Team(name, picture, mainColor, secondColor) VALUES (:teamName , :picture, :mainColor, :secondColor)",
[
":teamName" => [$name, PDO::PARAM_STR],
":picture" => [$picture, PDO::PARAM_STR],
":mainColor" => [$mainColor, PDO::PARAM_STR],
":secondColor" => [$secondColor, PDO::PARAM_STR]
":secondColor" => [$secondColor, PDO::PARAM_STR],
]
);
}
/**
* @param string $name
* @return array<string,mixed>[]
*/
public function listByName(string $name): array {
return $this->con->fetch(
"SELECT id,name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%' || :name || '%'",
[
":name" => [$name, PDO::PARAM_STR]
":name" => [$name, PDO::PARAM_STR],
]
);
}
public function getTeamById(int $id): array{
/**
* @param int $id
* @return array<string,mixed>[]
*/
public function getTeamById(int $id): array {
return $this->con->fetch(
"SELECT id,name,picture,mainColor,secondColor FROM Team WHERE id = :id",
[
":id" => [$id, PDO::PARAM_INT]
":id" => [$id, PDO::PARAM_INT],
]
);
}
public function getIdTeamByName(string $name): array{
/**
* @param string $name
* @return array<string,int>[]
*/
public function getIdTeamByName(string $name): array {
return $this->con->fetch(
"SELECT id FROM Team WHERE name = :name",
[
":name" => [$name, PDO::PARAM_STR]
":name" => [$name, PDO::PARAM_STR],
]
);
}
public function getMembersById($id):array{
/**
* @param int $id
* @return array<string,mixed>[]
*/
public function getMembersById(int $id): array {
return $this->con->fetch(
"SELECT m.role,u.id FROM User u,Team t,Member m WHERE t.id = :id AND m.idTeam = t.id AND m.idMember = u.id",
[
":id" => [$id, PDO::PARAM_INT]
"SELECT m.role,u.id FROM User u,Team t,Member m WHERE t.id = :id AND m.idTeam = t.id AND m.idMember = u.id",
[
":id" => [$id, PDO::PARAM_INT],
]
);
}
}
}

@ -8,8 +8,7 @@ use App\Data\Member;
use App\Data\MemberRole;
use App\Data\Color;
class TeamModel
{
class TeamModel {
private TeamGateway $gateway;
/**
@ -48,4 +47,4 @@ class TeamModel
}
return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members);
}
}
}

@ -56,7 +56,7 @@ class Validators {
return self::regex("/^[0-9]+$/");
}
public static function isIntInRange(int $min,int $max): Validator {
public static function isIntInRange(int $min, int $max): Validator {
return new SimpleFunctionValidator(
fn(string $val) => intval($val) >= $min && intval($val) <= $max,
fn(string $name) => [new FieldValidationFail($name, "The value is not in the range $min to $max ")]
@ -65,11 +65,8 @@ class Validators {
public static function isURL(): Validator {
return new SimpleFunctionValidator(
fn($val) => filter_var($val, FILTER_VALIDATE_URL) ,
fn($val) => filter_var($val, FILTER_VALIDATE_URL),
fn(string $name) => [new FieldValidationFail($name, "The value is not an URL")]
);
}
}

@ -22,9 +22,15 @@
#mainColor{
background-color: {{ team.mainColor.getValue() }};
{% if team.mainColor.getValue() == "#ffffff" %}
border-color: #666666;
{% endif %}
}
#secondColor{
background-color: {{ team.secondColor.getValue() }};
{% if team.secondColor.getValue() == "#ffffff" %}
border-color: #666666;
{% endif %}
}
.container{
@ -39,9 +45,6 @@
}
.colors{
justify-content: space-between;
}
.color{
flex-direction: row;
justify-content: space-between;
@ -65,12 +68,10 @@
<h1>{{ team.name }}</h1>
<img src="{{ team.picture }}" alt="Logo d'équipe" class="logo">
</div>
<div class="colors">
<div>
<div class="color"><p>Couleur principale : </p><div class="square" id="mainColor"></div> </div>
<div class="color"><p>Couleur secondaire : </p><div class="square" id="secondColor"></div></div>
</div>
{% for m in team.members %}
<p> m.id </p>
{% endfor %}

Loading…
Cancel
Save