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("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)));

@ -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<string, mixed> $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);
}
}

@ -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;
}
</style>
</head>
<body>
@ -72,12 +71,12 @@
</popup>
{% endif %}
{% if team is defined %}
<div class="team container">
<div class="team">
<div>
<h1>{{ team.getInfo().getName() }}</h1>
<img src="{{ team.getInfo().getPicture() }}" alt="Logo d'équipe" class="logo">
</div>
<div>
<div id="colors">
<div class="color"><p>Couleur principale : </p>
<div class="square" id="main_color"></div>
</div>
@ -85,16 +84,16 @@
<div class="square" id="second_color"></div>
</div>
</div>
{% if %}
<button id="delete" onclick="window.location.href = '{{ path("/team/#{team.getInfo().getId()}/delete") }}'">Supprimer</button>
{% endif %}
{% for m in team.listMembers() %}
<p> {{ m.getUserId() }} </p>
{% if m.getRole().isCoach() %}
<div class="player">
<p> {{ m.getUserId() }} </p>
{% if m.getRole().isCoach() %}
<p> : Coach</p>
{% else %}
{% else %}
<p> : Joueur</p>
{% endif %}
{% endif %}
</div>
{% endfor %}
</div>
{% else %}

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

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

@ -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);
}
/**

@ -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 {

@ -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' ;
}
}

Loading…
Cancel
Save