diff --git a/src/Controller/TeamController.php b/src/Controller/TeamController.php index 8228d6a..ffbcb8e 100644 --- a/src/Controller/TeamController.php +++ b/src/Controller/TeamController.php @@ -74,7 +74,8 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/ } public function displayTeam(int $id): HttpResponse{ - $results = $this->model->displayTeam($id); + $result = $this->model->displayTeam($id); + return ViewHttpResponse::twig('display_team.html.twig',['team' => $result]); } } diff --git a/src/Data/Member.php b/src/Data/Member.php index 91b09c4..9bf0b52 100755 --- a/src/Data/Member.php +++ b/src/Data/Member.php @@ -11,6 +11,7 @@ class Member { */ private int $userId; + private string $email; /** * @var MemberRole the member's role */ @@ -18,13 +19,16 @@ class Member { /** * @param int $userId + * @param string $email * @param MemberRole $role */ - public function __construct(int $userId, MemberRole $role) { + public function __construct(int $userId, string $email, MemberRole $role) { $this->userId = $userId; + $this->email = $email; $this->role = $role; } + /** * @return int */ @@ -39,4 +43,11 @@ class Member { return $this->role; } + /** + * @return string + */ + public function getEmail(): string { + return $this->email; + } + } \ No newline at end of file diff --git a/src/Gateway/TeamGateway.php b/src/Gateway/TeamGateway.php index 7d9c014..1540c73 100644 --- a/src/Gateway/TeamGateway.php +++ b/src/Gateway/TeamGateway.php @@ -44,7 +44,7 @@ class TeamGateway { 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", + "SELECT p.role,m.email,m.id 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] ] diff --git a/src/Model/TeamModel.php b/src/Model/TeamModel.php index 30c9fde..8c5c8f5 100644 --- a/src/Model/TeamModel.php +++ b/src/Model/TeamModel.php @@ -1,8 +1,11 @@ gateway = $gateway; } - public function createTeam(string $name,string $picture,int $mainColor, int $secondColor) { - $this->gateway->insert($name,$picture,$mainColor,$secondColor); + public function createTeam(string $name, string $picture, int $mainColor, int $secondColor) { + $this->gateway->insert($name, $picture, $mainColor, $secondColor); } - public function listByName(string $name):array { - $teams=[]; + public function listByName(string $name): array { + $teams = []; $results = $this->gateway->listByName($name); - foreach ($results as $row){ - $teams[] = new Team($row['id'],$row['name'],$row['picture'],$row['mainColor'],$row['secondColor']); + foreach ($results as $row) { + $teams[] = new Team($row['id'], $row['name'], $row['picture'], $row['mainColor'], $row['secondColor']); } return $teams; } - public function displayTeam(int $id): array{ - $resultTeam = $this->gateway->getTeamById($id); + public function displayTeam(int $id): Team { + $members = []; + $result = $this->gateway->getTeamById($id); $resultMembers = $this->gateway->getMembersById($id); - + foreach ($resultMembers as $row) { + if ($row['role'] == 'C') { + $role = 1; + } else { + $role = 2; + } + $members[] = new Member($row['id'], $row['email'], $role); + } + $team = new Team($result['id'], $result['name'], $result['picture'], $result['mainColor'], $result['secondColor'], $members); + return $team; } + } \ No newline at end of file diff --git a/src/Views/display_team.html.twig b/src/Views/display_team.html.twig index a1f88fc..d06322f 100644 --- a/src/Views/display_team.html.twig +++ b/src/Views/display_team.html.twig @@ -6,30 +6,12 @@
-Aucune équipe n'a été trouvée
-Nom de l'équipe: {{ t.name }}
-picture : {{ t.picture }}
-m.email
+{% endfor %}