add fonctional delete action, some more css, and repaired getmembersofteambyid
continuous-integration/drone/push Build is passing Details

pull/84/head
Maël DAIM 1 year ago
parent fbe31a4de9
commit 66aaf0c8fb

@ -96,7 +96,7 @@ function getRoutes(): AltoRouter {
$ar->map("GET", "/team/search", Action::auth(fn(SessionHandle $s) => getTeamController()->displayListTeamByName($s))); $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("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]", 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("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("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))); $ar->map("GET", "/team/members/remove", Action::auth(fn(SessionHandle $s) => getTeamController()->displayDeleteMember($s)));

@ -71,6 +71,7 @@ class TeamController {
return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]); return ViewHttpResponse::twig('insert_team.html.twig', ['bad_fields' => $badFields]);
} }
$teamId = $this->model->createTeam($request['name'], $request['picture'], $request['main_color'], $request['second_color']); $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); return $this->displayTeam($teamId, $session);
} }
@ -99,7 +100,7 @@ class TeamController {
return ViewHttpResponse::twig('list_team_by_name.html.twig', ['bad_field' => $badField]); 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)) { if (empty($teams)) {
return ViewHttpResponse::twig('display_teams.html.twig', []); return ViewHttpResponse::twig('display_teams.html.twig', []);
@ -109,17 +110,17 @@ class TeamController {
} }
/** /**
* @param array<string, mixed> $request * @param int $id
* @param SessionHandle $session * @param SessionHandle $session
* @return HttpResponse * @return HttpResponse
*/ */
public function deleteTeamByid(array $request,SessionHandle $session):HttpResponse{ public function deleteTeamByid(int $id,SessionHandle $session):HttpResponse{
$a = $session->getAccount(); $a = $session->getAccount();
$ret = $this->model->deleteTeam($a->getEmail(),intval($request['idTeam'])); $ret = $this->model->deleteTeam($a->getEmail(),$id);
if($ret != 0){ if($ret != 0){
return ViewHttpResponse::twig('display_team.html.twig',['notDeleted' => true]); 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()], "team" => [Validators::isInteger()],
"email" => [Validators::email(), Validators::lenBetween(5, 256)], "email" => [Validators::email(), Validators::lenBetween(5, 256)],
]); ]);
return $this->displayTeam($this->model->deleteMember($request['email'], intval($request['team'])), $session); return $this->displayTeam($this->model->deleteMember($request['email'], intval($request['team'])), $session);
} }
} }

@ -11,10 +11,6 @@
align-items: center; align-items: center;
} }
section {
width: 60%;
}
.square { .square {
width: 50px; width: 50px;
height: 50px; height: 50px;
@ -30,19 +26,17 @@
border: solid; border: solid;
} }
.container { section {
background-color: #fff; background-color: #fff;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
width: 60%;
} }
.team { #colors{
border-color: darkgrey; flex-direction: row;
border-radius: 20px;
} }
.color { .color {
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
@ -58,6 +52,11 @@
background-color: red; background-color: red;
color: white; color: white;
} }
.player{
flex-direction: row;
justify-content: space-evenly;
}
</style> </style>
</head> </head>
<body> <body>
@ -72,12 +71,12 @@
</popup> </popup>
{% endif %} {% endif %}
{% if team is defined %} {% if team is defined %}
<div class="team container"> <div class="team">
<div> <div>
<h1>{{ team.getInfo().getName() }}</h1> <h1>{{ team.getInfo().getName() }}</h1>
<img src="{{ team.getInfo().getPicture() }}" alt="Logo d'équipe" class="logo"> <img src="{{ team.getInfo().getPicture() }}" alt="Logo d'équipe" class="logo">
</div> </div>
<div> <div id="colors">
<div class="color"><p>Couleur principale : </p> <div class="color"><p>Couleur principale : </p>
<div class="square" id="main_color"></div> <div class="square" id="main_color"></div>
</div> </div>
@ -85,16 +84,16 @@
<div class="square" id="second_color"></div> <div class="square" id="second_color"></div>
</div> </div>
</div> </div>
{% if %}
<button id="delete" onclick="window.location.href = '{{ path("/team/#{team.getInfo().getId()}/delete") }}'">Supprimer</button> <button id="delete" onclick="window.location.href = '{{ path("/team/#{team.getInfo().getId()}/delete") }}'">Supprimer</button>
{% endif %}
{% for m in team.listMembers() %} {% for m in team.listMembers() %}
<p> {{ m.getUserId() }} </p> <div class="player">
{% if m.getRole().isCoach() %} <p> {{ m.getUserId() }} </p>
{% if m.getRole().isCoach() %}
<p> : Coach</p> <p> : Coach</p>
{% else %} {% else %}
<p> : Joueur</p> <p> : Joueur</p>
{% endif %} {% endif %}
</div>
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}

@ -10,7 +10,6 @@
background-color: #f1f1f1; background-color: #f1f1f1;
align-items: center; align-items: center;
} }
section{ section{
flex-direction: row; flex-direction: row;
justify-content: space-around; justify-content: space-around;

@ -7,6 +7,9 @@
body { body {
font-family: Arial, sans-serif; font-family: Arial, sans-serif;
background-color: #f1f1f1; background-color: #f1f1f1;
display: flex;
flex-direction: column;
align-items: center;
} }
.container { .container {

@ -41,13 +41,13 @@ class MemberGateway {
*/ */
public function getMembersOfTeam(int $teamId): array { public function getMembersOfTeam(int $teamId): array {
$rows = $this->con->fetch( $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], ":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);
} }
/** /**

@ -38,14 +38,14 @@ class TeamGateway {
* @param string $name * @param string $name
* @return TeamInfo[] * @return TeamInfo[]
*/ */
public function listByName(string $name): array { public function listByName(string $name,int $id): array {
$result = $this->con->fetch( $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], ":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); 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] "email" => [$email, PDO::PARAM_STR]
] ]
)[0]['role'] ?? null; )[0]['role'] ?? null;
} }
public function deleteTeam(int $idTeam): void { public function deleteTeam(int $idTeam): void {

@ -52,8 +52,8 @@ class TeamModel {
* @param string $name * @param string $name
* @return TeamInfo[] * @return TeamInfo[]
*/ */
public function listByName(string $name): array { public function listByName(string $name,int $id): array {
return $this->teams->listByName($name); return $this->teams->listByName($name,$id);
} }
/** /**
@ -66,7 +66,6 @@ class TeamModel {
return new Team($teamInfo, $members); return new Team($teamInfo, $members);
} }
/** /**
* delete a member from given team identifier * delete a member from given team identifier
* @param string $mail * @param string $mail
@ -80,14 +79,12 @@ class TeamModel {
} }
public function deleteTeam(string $email, int $idTeam): int{ 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); $this->teams->deleteTeam($idTeam);
return 0; return 0;
} }
return -1; return -1;
} }
public function isCoach(string $email,int $idTeam): bool{
return $this->teams->isCoach($email,$idTeam) == 'Coach' ;
}
} }

Loading…
Cancel
Save