diff --git a/public/index.php b/public/index.php index 952e215..278e7f1 100644 --- a/public/index.php +++ b/public/index.php @@ -96,7 +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/[i:id]/delete", Action::auth(fn(int $id,SessionHandle $s) => getTeamController()->deleteTeamByid($id,$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 748594a..01fdb14 100644 --- a/src/App/Controller/TeamController.php +++ b/src/App/Controller/TeamController.php @@ -71,6 +71,7 @@ class TeamController { return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]); } $teamId = $this->model->createTeam($request['name'], $request['picture'], $request['main_color'], $request['second_color']); + $this->model->addMember($session->getAccount()->getEmail(),$teamId,'Coach'); return $this->displayTeam($teamId, $session); } @@ -99,7 +100,7 @@ class TeamController { return ViewHttpResponse::twig('list_team_by_name.html.twig', ['bad_field' => $badField]); } - $teams = $this->model->listByName($request['name']); + $teams = $this->model->listByName($request['name'],$session->getAccount()->getId()); if (empty($teams)) { return ViewHttpResponse::twig('display_teams.html.twig', []); @@ -109,17 +110,17 @@ class TeamController { } /** - * @param array $request + * @param int $id * @param SessionHandle $session * @return HttpResponse */ - public function deleteTeamByid(array $request,SessionHandle $session):HttpResponse{ + public function deleteTeamByid(int $id,SessionHandle $session):HttpResponse{ $a = $session->getAccount(); - $ret = $this->model->deleteTeam($a->getEmail(),intval($request['idTeam'])); + $ret = $this->model->deleteTeam($a->getEmail(),$id); if($ret != 0){ return ViewHttpResponse::twig('display_team.html.twig',['notDeleted' => true]); } - return ViewHttpResponse::redirect('home.twig'); + return ViewHttpResponse::redirect('/'); } /** @@ -164,7 +165,6 @@ class TeamController { "team" => [Validators::isInteger()], "email" => [Validators::email(), Validators::lenBetween(5, 256)], ]); - 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 905e3c5..d013865 100644 --- a/src/App/Views/display_team.html.twig +++ b/src/App/Views/display_team.html.twig @@ -11,10 +11,6 @@ align-items: center; } - section { - width: 60%; - } - .square { width: 50px; height: 50px; @@ -30,19 +26,17 @@ border: solid; } - .container { + section { background-color: #fff; display: flex; flex-direction: column; align-items: center; + width: 60%; } - .team { - border-color: darkgrey; - border-radius: 20px; - + #colors{ + flex-direction: row; } - .color { flex-direction: row; justify-content: space-between; @@ -58,6 +52,11 @@ background-color: red; color: white; } + + .player{ + flex-direction: row; + justify-content: space-evenly; + } @@ -72,12 +71,12 @@ {% endif %} {% if team is defined %} -
+

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

-
+

Couleur principale :

@@ -85,16 +84,16 @@
- {% if %} - {% endif %} {% for m in team.listMembers() %} -

{{ m.getUserId() }}

- {% if m.getRole().isCoach() %} +
+

{{ m.getUserId() }}

+ {% if m.getRole().isCoach() %}

: Coach

- {% else %} + {% else %}

: Joueur

- {% endif %} + {% endif %} +
{% endfor %}
{% else %} diff --git a/src/App/Views/display_teams.html.twig b/src/App/Views/display_teams.html.twig index 4c17a5e..3e3ab12 100644 --- a/src/App/Views/display_teams.html.twig +++ b/src/App/Views/display_teams.html.twig @@ -10,7 +10,6 @@ background-color: #f1f1f1; align-items: center; } - section{ flex-direction: row; justify-content: space-around; diff --git a/src/App/Views/list_team_by_name.html.twig b/src/App/Views/list_team_by_name.html.twig index 3b93f94..092a149 100644 --- a/src/App/Views/list_team_by_name.html.twig +++ b/src/App/Views/list_team_by_name.html.twig @@ -7,6 +7,9 @@ body { font-family: Arial, sans-serif; background-color: #f1f1f1; + display: flex; + flex-direction: column; + align-items: center; } .container { diff --git a/src/Core/Gateway/MemberGateway.php b/src/Core/Gateway/MemberGateway.php index 999bf10..4c8bb8a 100644 --- a/src/Core/Gateway/MemberGateway.php +++ b/src/Core/Gateway/MemberGateway.php @@ -41,13 +41,13 @@ class MemberGateway { */ public function getMembersOfTeam(int $teamId): array { $rows = $this->con->fetch( - "SELECT a.id,m.role,a.email,a.username FROM Account a,Team t,Member m WHERE t.id = :id AND m.id_team = t.id AND m.id_user = a.id", + "SELECT a.id,m.role FROM Account a,Team t,Member m WHERE t.id = :id AND m.id_team = t.id AND m.id_user = a.id", [ ":id" => [$teamId, PDO::PARAM_INT], ] ); - return array_map(fn($row) => new Member($row['id_user'], $row['id_team'], MemberRole::fromName($row['role'])), $rows); + return array_map(fn($row) => new Member($row['id'], $teamId, MemberRole::fromName($row['role'])), $rows); } /** diff --git a/src/Core/Gateway/TeamGateway.php b/src/Core/Gateway/TeamGateway.php index 11735c2..ba882a6 100644 --- a/src/Core/Gateway/TeamGateway.php +++ b/src/Core/Gateway/TeamGateway.php @@ -38,14 +38,14 @@ class TeamGateway { * @param string $name * @return TeamInfo[] */ - public function listByName(string $name): array { + public function listByName(string $name,int $id): array { $result = $this->con->fetch( - "SELECT * FROM Team WHERE name LIKE '%' || :name || '%'", + "SELECT t.* FROM Team t, Member m WHERE t.name LIKE '%' || :name || '%' AND t.id=m.id_team AND m.id_user=:id", [ ":name" => [$name, PDO::PARAM_STR], + "id" => [$id, PDO::PARAM_INT] ] ); - return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], Color::from($row['main_color']), Color::from($row['second_color'])), $result); } @@ -87,7 +87,6 @@ class TeamGateway { "email" => [$email, PDO::PARAM_STR] ] )[0]['role'] ?? null; - } public function deleteTeam(int $idTeam): void { diff --git a/src/Core/Model/TeamModel.php b/src/Core/Model/TeamModel.php index fb31635..0661206 100644 --- a/src/Core/Model/TeamModel.php +++ b/src/Core/Model/TeamModel.php @@ -52,8 +52,8 @@ class TeamModel { * @param string $name * @return TeamInfo[] */ - public function listByName(string $name): array { - return $this->teams->listByName($name); + public function listByName(string $name,int $id): array { + return $this->teams->listByName($name,$id); } /** @@ -66,7 +66,6 @@ class TeamModel { return new Team($teamInfo, $members); } - /** * delete a member from given team identifier * @param string $mail @@ -80,14 +79,12 @@ class TeamModel { } public function deleteTeam(string $email, int $idTeam): int{ - if($this->isCoach($email,$idTeam) == "Coach" ){ + if($this->teams->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' ; - } + }