From 7ad974c30455defd5a58b26a009b9af066f665f8 Mon Sep 17 00:00:00 2001 From: galaxyoyo Date: Sat, 28 Sep 2019 00:48:30 +0200 Subject: [PATCH] =?UTF-8?q?Possibilit=C3=A9=20de=20virer=20ou=20d'ajouter?= =?UTF-8?q?=20des=20personnes=20dans=20les=20=C3=A9quipes=20par=20les=20ad?= =?UTF-8?q?ministrateurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server_files/classes/Team.php | 2 +- server_files/controllers/informations.php | 71 +++++++++++++++++++++++ server_files/model.php | 11 ++-- server_files/views/informations.php | 53 ++++++++++++++++- 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/server_files/classes/Team.php b/server_files/classes/Team.php index 351cb71..aecf1d4 100644 --- a/server_files/classes/Team.php +++ b/server_files/classes/Team.php @@ -73,7 +73,7 @@ class Team public static function getAllTeams($problem) { global $DB, $YEAR; - $req = $DB->prepare("SELECT * FROM `teams` WHERE `problem` = ? AND `year` = $YEAR;"); + $req = $DB->prepare("SELECT * FROM `teams` WHERE " . ($problem <= 0 ? "" : "`problem` = ? AND ") . "`year` = $YEAR;"); $req->execute([htmlspecialchars($problem)]); $teams = []; diff --git a/server_files/controllers/informations.php b/server_files/controllers/informations.php index 2325109..2b6a471 100644 --- a/server_files/controllers/informations.php +++ b/server_files/controllers/informations.php @@ -16,6 +16,77 @@ if ($user === null) $team = Team::fromId($user->getTeamId()); +$has_error = false; +$error_message = null; + +if (isset($_POST["kick"])) { + if ($team == null) { + $has_error = true; + $error_message = "La personne à expulser n'est dans aucune équipe."; + } + else { + quitTeam($id); + $team = null; + } +} + +if (isset($_POST["attribute_team"])) { + $attribute_team = new AttributeTeam($_POST); + try { + $attribute_team->makeVerifications(); + $attribute_team->attribute(); + } catch (AssertionError $e) { + $has_error = true; + $error_message = $e->getMessage(); + } +} + +class AttributeTeam +{ + private $team; + private $min_null_index; + + public function __construct($data) + { + $this->team = Team::fromId($data["team"]); + } + + public function makeVerifications() + { + global $user; + + ensure($this->team != null, "Cette équipe n'existe pas."); + ensure($this->team->getValidationStatus() == ValidationStatus::NOT_READY, "Cette équipe est déjà validée ou en cours de validation."); + + $role = $user->getRole(); + for ($i = 1; $i <= $role == Role::ENCADRANT ? 1 : 5; ++$i) { + if (($role == Role::PARTICIPANT ? $this->team->getParticipants()[$i - 1] : $this->team->getEncadrantId()) == NULL) + break; + } + + $this->min_null_index = $i; + + ensure($role == Role::PARTICIPANT && $this->min_null_index <= 5 || $role == Role::ENCADRANT && $this->min_null_index <= 2, + "Il n'y a plus de place pour vous dans l'équipe."); + } + + public function attribute() + { + global $user, $team; + + $user->setTeamId($this->team->getId()); + + if ($user->getRole() == Role::ENCADRANT) + $this->team->setEncadrant($user->getId()); + else + $this->team->setParticipant($this->min_null_index, $user->getId()); + + Mailer::sendJoinTeamMail($user, $this->team); + + $team = $this->team; + } +} + if ($team != null) $documents = $user->getAllDocuments($team->getProblem()); diff --git a/server_files/model.php b/server_files/model.php index 28c44a6..18c1137 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -21,15 +21,16 @@ function loadUserValues() } } -function quitTeam() +function quitTeam($user_id = -1) { global $DB, $URL_BASE; - header("Location: $URL_BASE"); + if ($user_id == -1) + header("Location: $URL_BASE"); + $user_id = $user_id >= 0 ? $user_id : $_SESSION["user_id"]; /** @var User $user */ - $user = $_SESSION["user"]; - $user_id = $user->getId(); + $user = User::fromId($user_id); $role = $user->getRole(); if ($role == Role::ADMIN) @@ -47,7 +48,7 @@ function quitTeam() $DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;"); } - $DB->exec("DELETE FROM `teams` WHERE `encadrant` IS NULL OR `participant_1` IS NULL;"); + $DB->exec("DELETE FROM `teams` WHERE `encadrant` IS NULL AND `participant_1` IS NULL;"); $req = $DB->query("SELECT `file_id` FROM `documents` WHERE `user` = $user_id;"); while (($data = $req->fetch()) !== false) unlink("$URL_BASE/files/" . $data["file_id"]); diff --git a/server_files/views/informations.php b/server_files/views/informations.php index 3bd83a2..4fe3ad0 100644 --- a/server_files/views/informations.php +++ b/server_files/views/informations.php @@ -4,11 +4,62 @@

getFirstName() . " " . $user->getSurname() ?>

+ +
+ La personne a bien été exclue de l'équipe ! +
+ +
+ La personne a bien rejoint l'équipe ! +
+ + +
+ Rôle : getRole()) ?> +
+ getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
Équipe : getTrigram() . "\">" . $team->getName() . " (" . $team->getTrigram() . ")" ?> + +
+
+
+ + +
+
+
+ + + +
+
+ getValidationStatus() == ValidationStatus::NOT_READY) { ?> +
+ + Virer de l'équipe +
+
@@ -33,7 +84,7 @@
-getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?> +getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT)) { ?>

Autorisation de droit à l'image :