From 6848d56244fd9b70e1ca0aab83571abc0831a21d Mon Sep 17 00:00:00 2001 From: "mael.daim" Date: Mon, 11 Dec 2023 17:18:46 +0100 Subject: [PATCH] fixed delete team bugs, added a pop up, starting to translate the team panel in react, starting edit team action --- front/style/teamPanel.css | 47 +++++++++++++++++++++++++++ front/views/TeamPanel.tsx | 32 ++++++++++++++++++ src/App/Controller/TeamController.php | 5 ++- src/App/Views/display_team.html.twig | 5 ++- src/App/Views/insert_team.html.twig | 1 - src/Core/Gateway/MemberGateway.php | 25 ++++++++++---- src/Core/Gateway/TeamGateway.php | 5 ++- src/Core/Model/TeamModel.php | 10 ++++-- 8 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 front/style/teamPanel.css create mode 100644 front/views/TeamPanel.tsx diff --git a/front/style/teamPanel.css b/front/style/teamPanel.css new file mode 100644 index 0000000..d766e76 --- /dev/null +++ b/front/style/teamPanel.css @@ -0,0 +1,47 @@ +body { + background-color: #f1f1f1; + display: flex; + flex-direction: column; + align-items: center; +} + +.square { + width: 50px; + height: 50px; +} + +#main_color { + border: solid; +} + +section { + background-color: #fff; + display: flex; + flex-direction: column; + align-items: center; + width: 60%; +} + +#colors{ + flex-direction: row; +} +.color { + flex-direction: row; + justify-content: space-between; +} + +.logo { + height: 80px; + width: 80px; +} + +#delete{ + border-radius:10px ; + background-color: red; + color: white; +} + +.player{ + flex-direction: row; + justify-content: space-evenly; +} diff --git a/front/views/TeamPanel.tsx b/front/views/TeamPanel.tsx new file mode 100644 index 0000000..ae116ce --- /dev/null +++ b/front/views/TeamPanel.tsx @@ -0,0 +1,32 @@ + +import '../style/teamPanel.css' + + +interface TeamInfo{ + id: number + name: string + picture: string + mainColor: string + secondColor: string +} + +interface Team { + info: TeamInfo + members: Member[] +} + +interface Member{ + id: number + + role: string +} + + +export default function TeamPanel({isCoach}: {isCoach: boolean}){ + + return

prout ({isCoach ? "vrai" : "faux"})

+} + + + + diff --git a/src/App/Controller/TeamController.php b/src/App/Controller/TeamController.php index 01538f6..46adc07 100644 --- a/src/App/Controller/TeamController.php +++ b/src/App/Controller/TeamController.php @@ -138,7 +138,8 @@ class TeamController { ], HttpCodes::FORBIDDEN); } else{ - return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]); + $role = $this->model->isCoach($id,$session->getAccount()->getEmail()); + return ViewHttpResponse::react('views/TeamPanel.tsx', ['team' => ["a" => "b"], 'isCoach' => $role]); } } @@ -169,7 +170,6 @@ class TeamController { */ public function deleteMember(array $request, SessionHandle $session): HttpResponse { $errors = []; - $request = HttpRequest::from($request, $errors, [ "team" => [Validators::isInteger()], "email" => [Validators::email(), Validators::lenBetween(5, 256)], @@ -177,5 +177,4 @@ class TeamController { return $this->displayTeam($this->model->deleteMember($request['email'], intval($request['team'])), $session); } - } diff --git a/src/App/Views/display_team.html.twig b/src/App/Views/display_team.html.twig index d013865..8928e84 100644 --- a/src/App/Views/display_team.html.twig +++ b/src/App/Views/display_team.html.twig @@ -84,7 +84,10 @@
- + {% if isCoach %} + + + {% endif %} {% for m in team.listMembers() %}

{{ m.getUserId() }}

diff --git a/src/App/Views/insert_team.html.twig b/src/App/Views/insert_team.html.twig index 9f4694b..0c10114 100644 --- a/src/App/Views/insert_team.html.twig +++ b/src/App/Views/insert_team.html.twig @@ -54,7 +54,6 @@ background-color: #0056b3; } - diff --git a/src/Core/Gateway/MemberGateway.php b/src/Core/Gateway/MemberGateway.php index c82281b..91dcf43 100644 --- a/src/Core/Gateway/MemberGateway.php +++ b/src/Core/Gateway/MemberGateway.php @@ -66,24 +66,37 @@ class MemberGateway { ); } - public function isCoach(string $email, int $idTeam): ?string { - return $this->con->fetch( + /** + * @param string $email + * @param int $idTeam + * @return bool + */ + public function isCoach(string $email, int $idTeam): bool { + $result = $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; + )[0]['role']; + return $result == 'Coach'; } - public function isMemberOfTeam(int $idTeam,int $idCurrentUser): ?int { - return $this->con->fetch( + /** + * @param int $idTeam + * @param int $idCurrentUser + * @return bool + */ + public function isMemberOfTeam(int $idTeam,int $idCurrentUser): bool { + $result = $this->con->fetch( "SELECT id_user FROM Member WHERE id_team = :team AND id_user = :user", [ "team" => [$idTeam, PDO::PARAM_INT], "user" => [$idCurrentUser, PDO::PARAM_INT] ] - )[0]['idUser'] ?? null; + )[0]['id_user'] ?? null; + return $result == null; } + } diff --git a/src/Core/Gateway/TeamGateway.php b/src/Core/Gateway/TeamGateway.php index 240aa40..5478968 100644 --- a/src/Core/Gateway/TeamGateway.php +++ b/src/Core/Gateway/TeamGateway.php @@ -36,6 +36,7 @@ class TeamGateway { /** * @param string $name + * @param int $id * @return TeamInfo[] */ public function listByName(string $name,int $id): array { @@ -51,7 +52,7 @@ class TeamGateway { /** * @param int $id - * @return TeamInfo + * @return ?TeamInfo */ public function getTeamById(int $id): ?TeamInfo { $row = $this->con->fetch( @@ -79,8 +80,6 @@ class TeamGateway { )[0]['id'] ?? null; } - - public function deleteTeam(int $idTeam): void { $this->con->exec( "DELETE FROM Member WHERE id_team=:team", diff --git a/src/Core/Model/TeamModel.php b/src/Core/Model/TeamModel.php index 09f52cd..260da3a 100644 --- a/src/Core/Model/TeamModel.php +++ b/src/Core/Model/TeamModel.php @@ -50,6 +50,7 @@ class TeamModel { /** * @param string $name + * @param int $id * @return TeamInfo[] */ public function listByName(string $name,int $id): array { @@ -62,7 +63,7 @@ class TeamModel { * @return ?Team */ public function getTeam(int $idTeam, int $idCurrentUser): ?Team { - if($this->members->isMemberOfTeam($idTeam,$idCurrentUser) == null){ + if($this->members->isMemberOfTeam($idTeam,$idCurrentUser)){ return null; } $teamInfo = $this->teams->getTeamById($idTeam); @@ -83,12 +84,15 @@ class TeamModel { } public function deleteTeam(string $email, int $idTeam): int{ - if($this->members->isCoach($email,$idTeam) == "Coach" ){ + $this->members->isCoach($email,$idTeam); + if($this->members->isCoach($email,$idTeam)){ $this->teams->deleteTeam($idTeam); return 0; } return -1; } - + public function isCoach(int $idTeam, string $email): bool{ + return $this->members->isCoach($email,$idTeam); + } }