mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-01-07 13:42:22 +00:00
Possibilité de virer ou d'ajouter des personnes dans les équipes par les administrateurs
This commit is contained in:
parent
c1f37ff530
commit
7ad974c304
@ -73,7 +73,7 @@ class Team
|
|||||||
public static function getAllTeams($problem)
|
public static function getAllTeams($problem)
|
||||||
{
|
{
|
||||||
global $DB, $YEAR;
|
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)]);
|
$req->execute([htmlspecialchars($problem)]);
|
||||||
|
|
||||||
$teams = [];
|
$teams = [];
|
||||||
|
@ -16,6 +16,77 @@ if ($user === null)
|
|||||||
|
|
||||||
$team = Team::fromId($user->getTeamId());
|
$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)
|
if ($team != null)
|
||||||
$documents = $user->getAllDocuments($team->getProblem());
|
$documents = $user->getAllDocuments($team->getProblem());
|
||||||
|
|
||||||
|
@ -21,15 +21,16 @@ function loadUserValues()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function quitTeam()
|
function quitTeam($user_id = -1)
|
||||||
{
|
{
|
||||||
global $DB, $URL_BASE;
|
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 */
|
/** @var User $user */
|
||||||
$user = $_SESSION["user"];
|
$user = User::fromId($user_id);
|
||||||
$user_id = $user->getId();
|
|
||||||
$role = $user->getRole();
|
$role = $user->getRole();
|
||||||
|
|
||||||
if ($role == Role::ADMIN)
|
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("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;");
|
$req = $DB->query("SELECT `file_id` FROM `documents` WHERE `user` = $user_id;");
|
||||||
while (($data = $req->fetch()) !== false)
|
while (($data = $req->fetch()) !== false)
|
||||||
unlink("$URL_BASE/files/" . $data["file_id"]);
|
unlink("$URL_BASE/files/" . $data["file_id"]);
|
||||||
|
@ -4,11 +4,62 @@
|
|||||||
<h1 class="display-4"><?= $user->getFirstName() . " " . $user->getSurname() ?></h1>
|
<h1 class="display-4"><?= $user->getFirstName() . " " . $user->getSurname() ?></h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if (!$has_error) {
|
||||||
|
if (isset($_POST["kick"])) { ?>
|
||||||
|
<div class="alert alert-success">
|
||||||
|
La personne a bien été exclue de l'équipe !
|
||||||
|
</div>
|
||||||
|
<?php } elseif (isset($attribute_team)) { ?>
|
||||||
|
<div class="alert alert-success">
|
||||||
|
La personne a bien rejoint l'équipe !
|
||||||
|
</div>
|
||||||
|
<?php }
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<strong>Rôle :</strong> <?= Role::getTranslatedName($user->getRole()) ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
|
<?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
|
||||||
<div class="alert alert-info">
|
<div class="alert alert-info">
|
||||||
<strong>Équipe
|
<strong>Équipe
|
||||||
:</strong> <?= $team === null ? "Pas d'équipe" : "<a href=\"/equipe/" . $team->getTrigram() . "\">"
|
:</strong> <?= $team === null ? "Pas d'équipe" : "<a href=\"/equipe/" . $team->getTrigram() . "\">"
|
||||||
. $team->getName() . " (" . $team->getTrigram() . ")</a>" ?>
|
. $team->getName() . " (" . $team->getTrigram() . ")</a>" ?>
|
||||||
|
<?php if ($team == null) { ?>
|
||||||
|
<form method="POST">
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="form-group col-md-12">
|
||||||
|
<label for="team">Attribuer une équipe :</label>
|
||||||
|
<select class="custom-select" id="team" name="team">
|
||||||
|
<?php
|
||||||
|
/** @var Team $t */
|
||||||
|
foreach (Team::getAllTeams(-1) as $t) {
|
||||||
|
if ($t->getValidationStatus() != ValidationStatus::NOT_READY)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$team_name = $t->getName() . " (" . $t->getTrigram() . "), problème " . $t->getProblem();
|
||||||
|
$team_id = $t->getId();
|
||||||
|
echo "<option value=\"$team_id\">$team_name</option>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<?php if (Phase::getCurrentPhase() < Phase::PHASE2) { ?>
|
||||||
|
<input type="submit" class="btn btn-secondary btn-lg btn-block" name="attribute_team"
|
||||||
|
value="Affecter dans une équipe"/>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<?php } elseif ($team->getValidationStatus() == ValidationStatus::NOT_READY) { ?>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="kick" />
|
||||||
|
<a href="#" onclick="this.parentNode.submit()">Virer de l'équipe</a>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
@ -33,7 +84,7 @@
|
|||||||
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
||||||
<?php if ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT) { ?>
|
<?php if ($team != null && ($user->getRole() == Role::PARTICIPANT || $user->getRole() == Role::ENCADRANT)) { ?>
|
||||||
<div class="mt-4 mb-4">
|
<div class="mt-4 mb-4">
|
||||||
<h1 class="display-5">Autorisation de droit à l'image :</h1>
|
<h1 class="display-5">Autorisation de droit à l'image :</h1>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user