WIP did a few little changes
continuous-integration/drone/push Build is passing Details

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

@ -74,7 +74,8 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/
} }
public function displayTeam(int $id): HttpResponse{ 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]);
} }
} }

@ -11,6 +11,7 @@ class Member {
*/ */
private int $userId; private int $userId;
private string $email;
/** /**
* @var MemberRole the member's role * @var MemberRole the member's role
*/ */
@ -18,13 +19,16 @@ class Member {
/** /**
* @param int $userId * @param int $userId
* @param string $email
* @param MemberRole $role * @param MemberRole $role
*/ */
public function __construct(int $userId, MemberRole $role) { public function __construct(int $userId, string $email, MemberRole $role) {
$this->userId = $userId; $this->userId = $userId;
$this->email = $email;
$this->role = $role; $this->role = $role;
} }
/** /**
* @return int * @return int
*/ */
@ -39,4 +43,11 @@ class Member {
return $this->role; return $this->role;
} }
/**
* @return string
*/
public function getEmail(): string {
return $this->email;
}
} }

@ -44,7 +44,7 @@ class TeamGateway {
public function getMembersById($id):array{ public function getMembersById($id):array{
return $this->con->fetch( 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] ":id" => [$id, PDO::PARAM_INT]
] ]

@ -1,8 +1,11 @@
<?php <?php
namespace App\Model; namespace App\Model;
use App\Data\Color;
use App\Gateway\TeamGateway; use App\Gateway\TeamGateway;
use App\Data\Team; use App\Data\Team;
use App\Data\Member;
use App\Data\MemberRole;
/** /**
* *
@ -14,27 +17,37 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po
/** /**
* @param TeamGateway $gateway * @param TeamGateway $gateway
*/ */
public function __construct(TeamGateway $gateway) public function __construct(TeamGateway $gateway) {
{
$this->gateway = $gateway; $this->gateway = $gateway;
} }
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['id'],$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{ public function displayTeam(int $id): Team {
$resultTeam = $this->gateway->getTeamById($id); $members = [];
$result = $this->gateway->getTeamById($id);
$resultMembers = $this->gateway->getMembersById($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;
} }
} }

@ -6,30 +6,12 @@
</head> </head>
<body> <body>
<h1>Hello world</h1> <h1>{{ team.name }}</h1>
{% if teams is empty %}
<p>Aucune équipe n'a été trouvée</p> {% for m in team.members %}
<div class="container"> <p> m.email </p>
<h2>Chercher une équipe</h2> {% endfor %}
<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> </body>
</html> </html>

@ -6,8 +6,6 @@
</head> </head>
<body> <body>
<h1>Hello world</h1>
{% if teams is empty %} {% if teams is empty %}
<p>Aucune équipe n'a été trouvée</p> <p>Aucune équipe n'a été trouvée</p>
<div class="container"> <div class="container">

Loading…
Cancel
Save