delete team's action almost done
continuous-integration/drone/push Build is passing Details

pull/84/head
Maël DAIM 2 years ago
parent dde6eaa8d4
commit 1914671699

@ -96,6 +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/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)));

@ -108,16 +108,20 @@ class TeamController {
return ViewHttpResponse::twig('display_teams.html.twig', ['teams' => $teams]);
}
/**
* @param array<string, mixed> $request
* @param SessionHandle $session
* @return HttpResponse
*/
public function deleteTeamByid(array $request,SessionHandle $session):HttpResponse{
$a = $session->getAccount();
if(isCoach($a->getEmail(),intval($request['idTeam']))){
$ret = $this->model->deleteTeam($a->getEmail(),intval($request['idTeam']));
if($ret != 0){
return ViewHttpResponse::twig('display_team.html.twig',['notDeleted' => true]);
}
return ;
return ViewHttpResponse::redirect('home.twig');
}
/**
* @param int $id
* @param SessionHandle $session

@ -53,6 +53,11 @@
width: 80px;
}
#delete{
border-radius:10px ;
background-color: red;
color: white;
}
</style>
</head>
<body>
@ -61,7 +66,7 @@
</header>
<section class="container">
{% if team is defined %}
<div class="team container">
<div>
<h1>{{ team.getInfo().getName() }}</h1>
@ -75,7 +80,9 @@
<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() %}
@ -85,7 +92,11 @@
{% endif %}
{% endfor %}
</div>
{% else %}
<div>
<h3>Cette équipe ne peut être affichée</h3>
</div>
{% endif %}
</section>
</body>
</html>

@ -22,9 +22,9 @@
</div>
{% else %}
{% for t in teams %}
<div class="team" onclick="window.location.href = '{{ path("/team/#{t.id}") }}'">
<p>Nom de l'équipe : {{ t.name }}</p>
<img src="{{ t.picture }}" alt="logo de l'équipe">
<div class="team" onclick="window.location.href = '{{ path("/team/#{t.getId()}") }}'">
<p>Nom de l'équipe : {{ t.getName() }}</p>
<img src="{{ t.getPicture() }}" alt="logo de l'équipe">
</div>
{% endfor %}
{% endif %}

@ -34,7 +34,6 @@ class TeamGateway {
return intval($this->con->lastInsertId());
}
/**
* @param string $name
* @return TeamInfo[]
@ -56,11 +55,11 @@ class TeamGateway {
*/
public function getTeamById(int $id): ?TeamInfo {
$row = $this->con->fetch(
"SELECT * FROM Team WHERE id = :id",
[
":id" => [$id, PDO::PARAM_INT],
]
)[0] ?? null;
"SELECT * FROM Team WHERE id = :id",
[
":id" => [$id, PDO::PARAM_INT],
]
)[0] ?? null;
if ($row == null) {
return null;
}
@ -74,12 +73,36 @@ class TeamGateway {
*/
public function getTeamIdByName(string $name): ?int {
return $this->con->fetch(
"SELECT id FROM Team WHERE name = :name",
"SELECT id FROM Team WHERE name = :name",
[
":name" => [$name, PDO::PARAM_INT],
]
)[0]['id'] ?? null;
}
public function isCoach(string $email, int $idTeam): ?string {
return $this->con->fetch(
"SELECT role FROM Member WHERE id_team=:team AND id_user = (SELECT id FROM Account WHERE email=:email)",
[
"team" => [$idTeam, PDO::PARAM_INT],
"email" => [$email, PDO::PARAM_STR]
]
)[0]['role'] ?? null;
}
public function deleteTeam(int $idTeam): void {
$this->con->exec(
"DELETE FROM Member WHERE id_team=:team",
[
"team" => [$idTeam, PDO::PARAM_INT]
]
);
$this->con->exec(
"DELETE FROM TEAM WHERE id=:team",
[
":name" => [$name, PDO::PARAM_INT],
"team" => [$idTeam, PDO::PARAM_INT]
]
)[0]['id'] ?? null;
);
}
public function isCoach(string $email,int $idTeam):
}

@ -79,7 +79,15 @@ class TeamModel {
return $teamId;
}
public function isCoach($email,$idTeam): bool{
public function deleteTeam(string $email, int $idTeam): int{
if($this->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