fixed delete team bugs, added a pop up, starting to translate the team panel in react, starting edit team action
continuous-integration/drone/push Build is passing Details

pull/84/head
Maël DAIM 1 year ago
parent 14968b773d
commit 6848d56244

@ -0,0 +1,47 @@
body {
background-color: #f1f1f1;
display: flex;
flex-direction: column;
align-items: center;
}
.square {
width: 50px;
height: 50px;
}
#main_color {
border: solid;
}
section {
background-color: #fff;
display: flex;
flex-direction: column;
align-items: center;
width: 60%;
}
#colors{
flex-direction: row;
}
.color {
flex-direction: row;
justify-content: space-between;
}
.logo {
height: 80px;
width: 80px;
}
#delete{
border-radius:10px ;
background-color: red;
color: white;
}
.player{
flex-direction: row;
justify-content: space-evenly;
}

@ -0,0 +1,32 @@
import '../style/teamPanel.css'
interface TeamInfo{
id: number
name: string
picture: string
mainColor: string
secondColor: string
}
interface Team {
info: TeamInfo
members: Member[]
}
interface Member{
id: number
role: string
}
export default function TeamPanel({isCoach}: {isCoach: boolean}){
return <p>prout ({isCoach ? "vrai" : "faux"})</p>
}

@ -138,7 +138,8 @@ class TeamController {
], HttpCodes::FORBIDDEN);
}
else{
return ViewHttpResponse::twig('display_team.html.twig', ['team' => $result]);
$role = $this->model->isCoach($id,$session->getAccount()->getEmail());
return ViewHttpResponse::react('views/TeamPanel.tsx', ['team' => ["a" => "b"], 'isCoach' => $role]);
}
}
@ -169,7 +170,6 @@ class TeamController {
*/
public function deleteMember(array $request, SessionHandle $session): HttpResponse {
$errors = [];
$request = HttpRequest::from($request, $errors, [
"team" => [Validators::isInteger()],
"email" => [Validators::email(), Validators::lenBetween(5, 256)],
@ -177,5 +177,4 @@ class TeamController {
return $this->displayTeam($this->model->deleteMember($request['email'], intval($request['team'])), $session);
}
}

@ -84,7 +84,10 @@
<div class="square" id="second_color"></div>
</div>
</div>
<button id="delete" onclick="window.location.href = '{{ path("/team/#{team.getInfo().getId()}/delete") }}'">Supprimer</button>
{% if isCoach %}
<button id="delete" onclick="confirm('Êtes-vous sûr de supprimer cette équipe?') ? window.location.href = '{{ path("/team/#{team.getInfo().getId()}/delete") }}' : {}">Supprimer</button>
<button></button>
{% endif %}
{% for m in team.listMembers() %}
<div class="player">
<p> {{ m.getUserId() }} </p>

@ -54,7 +54,6 @@
background-color: #0056b3;
}
</style>
</head>
<body>

@ -66,24 +66,37 @@ class MemberGateway {
);
}
public function isCoach(string $email, int $idTeam): ?string {
return $this->con->fetch(
/**
* @param string $email
* @param int $idTeam
* @return bool
*/
public function isCoach(string $email, int $idTeam): bool {
$result = $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;
)[0]['role'];
return $result == 'Coach';
}
public function isMemberOfTeam(int $idTeam,int $idCurrentUser): ?int {
return $this->con->fetch(
/**
* @param int $idTeam
* @param int $idCurrentUser
* @return bool
*/
public function isMemberOfTeam(int $idTeam,int $idCurrentUser): bool {
$result = $this->con->fetch(
"SELECT id_user FROM Member WHERE id_team = :team AND id_user = :user",
[
"team" => [$idTeam, PDO::PARAM_INT],
"user" => [$idCurrentUser, PDO::PARAM_INT]
]
)[0]['idUser'] ?? null;
)[0]['id_user'] ?? null;
return $result == null;
}
}

@ -36,6 +36,7 @@ class TeamGateway {
/**
* @param string $name
* @param int $id
* @return TeamInfo[]
*/
public function listByName(string $name,int $id): array {
@ -51,7 +52,7 @@ class TeamGateway {
/**
* @param int $id
* @return TeamInfo
* @return ?TeamInfo
*/
public function getTeamById(int $id): ?TeamInfo {
$row = $this->con->fetch(
@ -79,8 +80,6 @@ class TeamGateway {
)[0]['id'] ?? null;
}
public function deleteTeam(int $idTeam): void {
$this->con->exec(
"DELETE FROM Member WHERE id_team=:team",

@ -50,6 +50,7 @@ class TeamModel {
/**
* @param string $name
* @param int $id
* @return TeamInfo[]
*/
public function listByName(string $name,int $id): array {
@ -62,7 +63,7 @@ class TeamModel {
* @return ?Team
*/
public function getTeam(int $idTeam, int $idCurrentUser): ?Team {
if($this->members->isMemberOfTeam($idTeam,$idCurrentUser) == null){
if($this->members->isMemberOfTeam($idTeam,$idCurrentUser)){
return null;
}
$teamInfo = $this->teams->getTeamById($idTeam);
@ -83,12 +84,15 @@ class TeamModel {
}
public function deleteTeam(string $email, int $idTeam): int{
if($this->members->isCoach($email,$idTeam) == "Coach" ){
$this->members->isCoach($email,$idTeam);
if($this->members->isCoach($email,$idTeam)){
$this->teams->deleteTeam($idTeam);
return 0;
}
return -1;
}
public function isCoach(int $idTeam, string $email): bool{
return $this->members->isCoach($email,$idTeam);
}
}

Loading…
Cancel
Save