diff --git a/public/index.php b/public/index.php index c31e289..952e215 100644 --- a/public/index.php +++ b/public/index.php @@ -96,6 +96,7 @@ function getRoutes(): AltoRouter { $ar->map("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s))); $ar->map("POST", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->listTeamByName($_POST, $s))); $ar->map("GET", "/team/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTeamController()->displayTeam($id, $s))); + $ar->map("GET", "/team/[i:id]/delete", Action::auth(fn(SessionHandle $s) => getTeamController()->deleteTeamByid($_POST, $s))); $ar->map("GET", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->displayAddMember($s))); $ar->map("POST", "/team/members/add", Action::auth(fn(SessionHandle $s) => getTeamController()->addMember($_POST, $s))); $ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s))); diff --git a/src/App/Controller/TeamController.php b/src/App/Controller/TeamController.php index e90ae67..748594a 100644 --- a/src/App/Controller/TeamController.php +++ b/src/App/Controller/TeamController.php @@ -108,16 +108,20 @@ class TeamController { return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $teams]); } - + /** + * @param array $request + * @param SessionHandle $session + * @return HttpResponse + */ public function deleteTeamByid(array $request,SessionHandle $session):HttpResponse{ $a = $session->getAccount(); - if(isCoach($a->getEmail(),intval($request['idTeam']))){ - + $ret = $this->model->deleteTeam($a->getEmail(),intval($request['idTeam'])); + if($ret != 0){ + return ViewHttpResponse::twig('display_team.html.twig',['notDeleted' => true]); } - return ; + return ViewHttpResponse::redirect('home.twig'); } - /** * @param int $id * @param SessionHandle $session diff --git a/src/App/Views/display_team.html.twig b/src/App/Views/display_team.html.twig index 7f23b8b..2a3f9ab 100644 --- a/src/App/Views/display_team.html.twig +++ b/src/App/Views/display_team.html.twig @@ -53,6 +53,11 @@ width: 80px; } + #delete{ + border-radius:10px ; + background-color: red; + color: white; + } @@ -61,7 +66,7 @@
- +{% if team is defined %}

{{ team.getInfo().getName() }}

@@ -75,7 +80,9 @@
- + {% if %} + + {% endif %} {% for m in team.listMembers() %}

{{ m.getUserId() }}

{% if m.getRole().isCoach() %} @@ -85,7 +92,11 @@ {% endif %} {% endfor %} - +{% else %} +
+

Cette équipe ne peut être affichée

+
+{% endif %}
\ No newline at end of file diff --git a/src/App/Views/display_teams.html.twig b/src/App/Views/display_teams.html.twig index 1e1420a..3713265 100644 --- a/src/App/Views/display_teams.html.twig +++ b/src/App/Views/display_teams.html.twig @@ -22,9 +22,9 @@ {% else %} {% for t in teams %} -
-

Nom de l'équipe : {{ t.name }}

- logo de l'équipe +
+

Nom de l'équipe : {{ t.getName() }}

+ logo de l'équipe
{% endfor %} {% endif %} diff --git a/src/Core/Gateway/TeamGateway.php b/src/Core/Gateway/TeamGateway.php index 925b625..a827b72 100644 --- a/src/Core/Gateway/TeamGateway.php +++ b/src/Core/Gateway/TeamGateway.php @@ -34,7 +34,6 @@ class TeamGateway { return intval($this->con->lastInsertId()); } - /** * @param string $name * @return TeamInfo[] @@ -56,11 +55,11 @@ class TeamGateway { */ public function getTeamById(int $id): ?TeamInfo { $row = $this->con->fetch( - "SELECT * FROM Team WHERE id = :id", - [ - ":id" => [$id, PDO::PARAM_INT], - ] - )[0] ?? null; + "SELECT * FROM Team WHERE id = :id", + [ + ":id" => [$id, PDO::PARAM_INT], + ] + )[0] ?? null; if ($row == null) { return null; } @@ -74,12 +73,36 @@ class TeamGateway { */ public function getTeamIdByName(string $name): ?int { return $this->con->fetch( - "SELECT id FROM Team WHERE name = :name", + "SELECT id FROM Team WHERE name = :name", + [ + ":name" => [$name, PDO::PARAM_INT], + ] + )[0]['id'] ?? null; + } + + public function isCoach(string $email, int $idTeam): ?string { + return $this->con->fetch( + "SELECT role FROM Member WHERE id_team=:team AND id_user = (SELECT id FROM Account WHERE email=:email)", + [ + "team" => [$idTeam, PDO::PARAM_INT], + "email" => [$email, PDO::PARAM_STR] + ] + )[0]['role'] ?? null; + + } + + public function deleteTeam(int $idTeam): void { + $this->con->exec( + "DELETE FROM Member WHERE id_team=:team", + [ + "team" => [$idTeam, PDO::PARAM_INT] + ] + ); + $this->con->exec( + "DELETE FROM TEAM WHERE id=:team", [ - ":name" => [$name, PDO::PARAM_INT], + "team" => [$idTeam, PDO::PARAM_INT] ] - )[0]['id'] ?? null; + ); } - - public function isCoach(string $email,int $idTeam): } diff --git a/src/Core/Model/TeamModel.php b/src/Core/Model/TeamModel.php index 569b181..fb31635 100644 --- a/src/Core/Model/TeamModel.php +++ b/src/Core/Model/TeamModel.php @@ -79,7 +79,15 @@ class TeamModel { return $teamId; } - public function isCoach($email,$idTeam): bool{ + public function deleteTeam(string $email, int $idTeam): int{ + if($this->isCoach($email,$idTeam) == "Coach" ){ + $this->teams->deleteTeam($idTeam); + return 0; + } + return -1; + } + public function isCoach(string $email,int $idTeam): bool{ + return $this->teams->isCoach($email,$idTeam) == 'Coach' ; } }