WIP done with insertion, got a problem on list team and starting displayTeam
continuous-integration/drone/push Build is passing Details

pull/16/head
Maël DAIM 1 year ago
parent 0859467e3f
commit 30611b9b21

@ -42,9 +42,11 @@ $router->map("GET", "/tactic/[i:id]/edit", fn(int $id) => $editorController->ope
$teamController = new \App\Controller\TeamController(new \App\Model\TeamModel(new \App\Gateway\TeamGateway($con)),$twig); $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("GET","/team/new", fn()=>$teamController->displaySubmitTeam());
$router->map("POST","/team/new", fn()=>$teamController->SubmitTeam($_POST)); $router->map("POST","/team/new", fn()=>$teamController->SubmitTeam($_POST));
$router->map("GET","/team/list", fn()=>$teamController->displayListTeamByName()); $router->map("GET","/team/list", fn()=>$teamController->displayListTeamByName());
$router->map("POST","/team/list", fn()=>$teamController->ListTeamByName($_POST)); $router->map("POST","/team/list", fn()=>$teamController->ListTeamByName($_POST));
/*todo $router->map("GET","/team/[i:id]", fn()=>$teamController->displayTeam);*/
$router->map("GET","/team/[i:id]", fn(int $id)=>$teamController->displayTeam($id));
$match = $router->match(); $match = $router->match();

@ -28,11 +28,7 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
} }
public function displaySubmitTeam() { public function displaySubmitTeam() {
try { return ViewHttpResponse::twig("insert_team.html.twig", []);
$this->twig->display("insert_team.html.twig", []);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
echo " twig error : $e";
}
} }
public function submitTeam(array $request): HttpResponse { public function submitTeam(array $request): HttpResponse {
@ -57,13 +53,10 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
return ViewHttpResponse::twig('sample_form.html.twig', []); /*todo appeler une vue qui display la team au lieu de ça*/ return ViewHttpResponse::twig('sample_form.html.twig', []); /*todo appeler une vue qui display la team au lieu de ça*/
} }
public function displayListTeamByName(){ public function displayListTeamByName(): HttpResponse {
try { return ViewHttpResponse::twig("list_team_by_name.html.twig", []);
$this->twig->display("list_team_by_name.html.twig", []);
} catch (LoaderError | RuntimeError | SyntaxError $e) {
echo " twig error : $e";
}
} }
public function listTeamByName(array $request): HttpResponse { public function listTeamByName(array $request): HttpResponse {
$errors = []; $errors = [];
$request = HttpRequest::from($request, $errors, [ $request = HttpRequest::from($request, $errors, [
@ -75,10 +68,14 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
} }
$results = $this->model->listByName($request['name']); $results = $this->model->listByName($request['name']);
if (empty($results)) { if (empty($results)) {
/*todo appelle de la bonne vue qui va afficher un message qui dit que bah ca retourne rien, proposer de refaire une recherche*/ return ViewHttpResponse::twig('display_teams.html.twig', []);
} }
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]); return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $results]);
} }
public function displayTeam(int $id): HttpResponse{
$results = $this->model->displayTeam($id);
}
} }

@ -5,6 +5,7 @@ namespace App\Data;
use http\Url; use http\Url;
class Team { class Team {
private int $id;
private string $name; private string $name;
private Url $picture; private Url $picture;
private Color $mainColor; private Color $mainColor;
@ -22,7 +23,8 @@ class Team {
* @param Color $secondColor * @param Color $secondColor
* @param array $members * @param array $members
*/ */
public function __construct(string $name, Url $picture, Color $mainColor, Color $secondColor, array $members =[]) { public function __construct(int $id,string $name, Url $picture, Color $mainColor, Color $secondColor, array $members =[]) {
$this->id = $id;
$this->name = $name; $this->name = $name;
$this->picture = $picture; $this->picture = $picture;
$this->mainColor = $mainColor; $this->mainColor = $mainColor;
@ -30,6 +32,13 @@ class Team {
$this->members = $members; $this->members = $members;
} }
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/** /**
* @return string * @return string
*/ */

@ -3,11 +3,9 @@
namespace App\Gateway; namespace App\Gateway;
use App\Connexion; use App\Connexion;
use App\Data\Color;
use PDO; use PDO;
class TeamGateway class TeamGateway {
{
private Connexion $con; private Connexion $con;
public function __construct(Connexion $con) { public function __construct(Connexion $con) {
@ -16,7 +14,7 @@ class TeamGateway
public function insert(string $name, string $picture, int $mainColor, int $secondColor) { public function insert(string $name, string $picture, int $mainColor, int $secondColor) {
$this->con->exec( $this->con->exec(
"INSERT INTO Team VALUES (:teamName , :picture, :mainColor, :secondColor)", "INSERT INTO Team(name, picture, mainColor, secondColor) VALUES (:teamName , :picture, :mainColor, :secondColor)",
[ [
":teamName" => [$name, PDO::PARAM_STR], ":teamName" => [$name, PDO::PARAM_STR],
":picture" => [$picture, PDO::PARAM_STR], ":picture" => [$picture, PDO::PARAM_STR],
@ -28,9 +26,27 @@ class TeamGateway
public function listByName(string $name): array { public function listByName(string $name): array {
return $this->con->fetch( return $this->con->fetch(
"SELECT name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%:match%' ", "SELECT id,name,picture,mainColor,secondColor FROM Team WHERE name LIKE '%' || :name || '%'",
[ [
":match" => [$name, PDO::PARAM_STR] ":name" => [$name, PDO::PARAM_STR]
]
);
}
public function getTeamById(int $id): array{
return $this->con->fetch(
"SELECT name,picture,mainColor,secondColor FROM Team WHERE id = :id",
[
":id" => [$id, PDO::PARAM_INT]
]
);
}
public function getMembersById($id):array{
return $this->con->fetch(
"SELECT p.role,m.email FROM Member m,Team t,Participate p WHERE t.id = :id AND p.idTeam = t.id AND p.idMember = m.id",
[
":id" => [$id, PDO::PARAM_INT]
] ]
); );
} }

@ -9,16 +9,6 @@ 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, */ 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; private TeamGateway $gateway;
/** /**
@ -31,16 +21,20 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
public function createTeam(string $name,string $picture,int $mainColor, int $secondColor) { public function createTeam(string $name,string $picture,int $mainColor, int $secondColor) {
$this->gateway->insert($name,$picture,$mainColor,$secondColor); $this->gateway->insert($name,$picture,$mainColor,$secondColor);
} }
public function listByName(string $name):array { public function listByName(string $name):array {
$teams=[]; $teams=[];
$results = $this->gateway->listByName($name); $results = $this->gateway->listByName($name);
foreach ($results as $row){ foreach ($results as $row){
$teams[] = new Team($row['name'],$row['picture'],$row['mainColor'],$row['secondColor']); $teams[] = new Team($row['id'],$row['name'],$row['picture'],$row['mainColor'],$row['secondColor']);
} }
return $teams; return $teams;
} }
public function displayTeam(int $id): array{
$resultTeam = $this->gateway->getTeamById($id);
$resultMembers = $this->gateway->getMembersById($id);
}
} }

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
<h1>Hello world</h1>
{% if teams is empty %}
<p>Aucune équipe n'a été trouvée</p>
<div class="container">
<h2>Chercher une équipe</h2>
<form action="/team/list" method="post">
<div class="form-group">
<label for="name">Nom de l'équipe :</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">
</div>
</form>
</div>
{% else %}
{% for t in teams %}
<div onclick="window.location.href = '/team/{{ t.id }}'">
<p>Nom de l'équipe: {{ t.name }}</p>
<p>picture : {{ t.picture }}</p>
</div>
{% endfor %}
{% endif %}
</body>
</html>

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
<h1>Hello world</h1>
{% if teams is empty %}
<p>Aucune équipe n'a été trouvée</p>
<div class="container">
<h2>Chercher une équipe</h2>
<form action="/team/list" method="post">
<div class="form-group">
<label for="name">Nom de l'équipe :</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">
</div>
</form>
</div>
{% else %}
{% for t in teams %}
<div onclick="window.location.href = '/team/{{ t.id }}'">
<p>Nom de l'équipe: {{ t.name }}</p>
<p>picture : {{ t.picture }}</p>
</div>
{% endfor %}
{% endif %}
</body>
</html>

@ -61,7 +61,7 @@
<body> <body>
<div class="container"> <div class="container">
<h2>Cer une équipe</h2> <h2>Chercher une équipe</h2>
<form action="/team/list" method="post"> <form action="/team/list" method="post">
<div class="form-group"> <div class="form-group">
<label for="name">Nom de l'équipe :</label> <label for="name">Nom de l'équipe :</label>

Loading…
Cancel
Save