Attribution des vidéos aux équipes (manuelle)

This commit is contained in:
galaxyoyo 2019-09-20 00:02:01 +02:00
parent c48b97cc6d
commit c3aa0386f2
14 changed files with 171 additions and 320 deletions

View File

@ -10,6 +10,7 @@ class Team
private $participants;
private $inscription_date;
private $validation_status;
private $video_team_ids;
private $access_code;
private $year;
@ -60,6 +61,23 @@ class Team
return $team;
}
public static function getAllTeams($problem)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT * FROM `teams` WHERE `problem` = ? AND `year` = $YEAR;");
$req->execute([htmlspecialchars($problem)]);
$teams = [];
while (($data = $req->fetch()) != false) {
$team = new Team();
$team->fill($data);
$teams[] = $team;
}
return $teams;
}
private function fill($data)
{
$this->id = $data["id"];
@ -70,6 +88,7 @@ class Team
$this->participants = [$data["participant_1"], $data["participant_2"], $data["participant_3"], $data["participant_4"], $data["participant_5"]];
$this->inscription_date = $data["inscription_date"];
$this->validation_status = ValidationStatus::fromName($data["validation_status"]);
$this->video_team_ids = [$data["video_team1"], $data["video_team2"]];
$this->access_code = $data["access_code"];
$this->year = $data["year"];
}
@ -155,10 +174,22 @@ class Team
{
global $DB;
$this->validation_status = $status;
/** @noinspection PhpUndefinedMethodInspection */
$DB->prepare("UPDATE `teams` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($status), $this->id]);
}
public function getVideoTeamIds()
{
return $this->video_team_ids;
}
public function setVideoTeamIds($video_team_ids)
{
global $DB;
ensure(sizeof($video_team_ids) == 2, "Une équipe doit recevoir exactement deux vidéos.");
$this->video_team_ids = $video_team_ids;
$DB->prepare("UPDATE `teams` SET `video_team1` = ?, `video_team2` = ? WHERE `id` = ?;")->execute([$video_team_ids[0], $video_team_ids[1], $this->id]);
}
public function getAccessCode()
{
return $this->access_code;

View File

@ -1,7 +1,7 @@
<?php
//if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
// require_once "server_files/403.php";
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
$trigram = htmlspecialchars($_GET["trigram"]);
@ -26,6 +26,43 @@ if (isset($_POST["download_zip"])) {
exit();
}
if (isset($_POST["update_video_teams"])) {
$update_video_teams = new UpdateVideoTeams($_POST);
try {
$update_video_teams->makeVerifications();
$update_video_teams->update();
} catch (AssertionError $e) {
$has_error = true;
$error_message = $e->getMessage();
}
}
class UpdateVideoTeams
{
private $other_teams;
public function __construct($data)
{
foreach ($data as $key => $value)
$this->$key = $value;
}
public function makeVerifications()
{
ensure(sizeof($this->other_teams) == 2, "L'équipe doit recevoir exactement deux vidéos.");
ensure(Team::fromId($this->other_teams[0]) != null, "La première équipe n'existe pas.");
ensure(Team::fromId($this->other_teams[1]) != null, "La seconde équipe n'existe pas.");
}
public function update()
{
global $team;
$team->setVideoTeamIds($this->other_teams);
}
}
$other_teams = Team::getAllTeams($team->getProblem());
$documents = Document::getAllDocuments($team->getProblem(), $team->getId());
require_once "server_files/views/equipe.php";

View File

@ -11,112 +11,6 @@ if (isset($_GET["modifier"]) && $_SESSION["role"] != Role::ADMIN)
$has_error = false;
$error_message = null;
if (isset($_POST["edit_tournament"])) {
$update_tournament = new UpdateTournament($_POST);
try {
$update_tournament->makeVerifications();
$update_tournament->updateTournament();
} catch (AssertionError $e) {
$has_error = true;
$error_message = $e->getMessage();
}
}
$teams = []; //$tournament->getAllTeams();
class UpdateTournament
{
public $name;
public $organizers;
public $size;
public $place;
public $price;
public $date_start;
public $date_end;
public $date_inscription;
public $time_inscription;
public $date_solutions;
public $time_solutions;
public $date_syntheses;
public $time_syntheses;
public $description;
public $final;
public function __construct($data)
{
global $tournament;
foreach ($data as $key => $value)
$this->$key = ($key == "organizers" ? $value : htmlspecialchars($value));
if ($_SESSION["role"] != Role::ADMIN) {
$this->organizers = [];
/** @var User $organizer */
foreach ($tournament->getOrganizers() as $organizer)
$this->organizers[] = $organizer->getId();
}
}
public function makeVerifications()
{
global $tournament;
ensure($this->name != null && $this->name != "", "Le nom est invalide.");
ensure($this->name == $tournament->getName() || !tournamentExists($this->name), "Un tournoi existe déjà avec ce nom.");
ensure(sizeof($this->organizers) > 0, "Aucun organisateur n'a été choisi.");
$orgas = [];
foreach ($this->organizers as $orga_id) {
$orga = User::fromId($orga_id);
ensure($orga != null, "Un organisateur spécifié n'existe pas.");
ensure($orga->getRole() == Role::ORGANIZER || $orga->getRole() == Role::ADMIN, "Une personne indiquée ne peut pas organiser de tournoi.");
$orgas[] = $orga;
}
$this->organizers = $orgas;
ensure(preg_match("#[0-9]*#", $this->size), "Le nombre d'équipes indiqué n'est pas un nombre valide.");
$this->size = intval($this->size);
ensure($this->size >= 3 && $this->size <= 15, "Un tournoi doit avoir au moins 3 et au plus 15 équipes.");
ensure(preg_match("#[0-9]*#", $this->price), "Le tarif pour les participants n'est pas un entier valide.");
$this->price = intval($this->price);
ensure($this->price >= 0, "Le TFJM² ne va pas payer les élèves pour venir.");
ensure($this->price <= 50, "Soyons raisonnable sur le prix.");
ensure(dateWellFormed($this->date_start), "La date de début n'est pas valide.");
ensure(dateWellFormed($this->date_end), "La date de fin n'est pas valide.");
ensure(dateWellFormed($this->date_inscription . " " . $this->time_inscription), "La date de clôture des inscriptions n'est pas valide.");
ensure(dateWellFormed($this->date_solutions . " " . $this->time_solutions), "La date limite de remise des solutions n'est pas valide.");
ensure(dateWellFormed($this->date_syntheses . " " . $this->time_syntheses), "La date limite de remise des notes de synthèse n'est pas valide.");
}
public function updateTournament()
{
global $URL_BASE, $tournament;
$tournament->setName($this->name);
$tournament->setSize($this->size);
$tournament->setPlace($this->place);
$tournament->setPrice($this->price);
$tournament->setStartDate($this->date_start);
$tournament->setEndDate($this->date_end);
$tournament->setInscriptionDate("$this->date_inscription $this->time_inscription");
$tournament->setSolutionsDate("$this->date_solutions $this->time_solutions");
$tournament->setSynthesesDate("$this->date_syntheses $this->time_syntheses");
foreach ($this->organizers as $organizer) {
if (!$tournament->organize($organizer->getId()))
Mailer::sendAddOrganizerForTournamentMail($organizer, $tournament);
}
$tournament->clearOrganizers();
/** @var User $organizer */
foreach ($this->organizers as $organizer)
$tournament->addOrganizer($organizer);
header("Location: $URL_BASE/tournoi/" . $this->name);
exit();
}
}
$teams = Team::getAllTeams($problem);
require_once "server_files/views/probleme.php";

View File

@ -1,12 +1,8 @@
<?php
require_once "header.php";
if (isset($admin)) {
if ($has_error) {
echo "<h2>Erreur : " . $error_message . "</h2>";
} else {
echo "<h2>Organisateur ajouté avec succès ! Ses identifiants ont été transmis par mail.</h2>";
}
if (isset($admin) && !$has_error) {
echo "<h2>Organisateur ajouté avec succès ! Ses identifiants ont été transmis par mail.</h2>";
} ?>
<form method="POST">

View File

@ -9,8 +9,6 @@ if (isset($new_team) && !$has_error) { ?>
<h2>La date limite d'inscription est dépassée.</h2>
<?php } else { ?>
<?php if (isset($error_message) && $error_message) echo "<h2>Erreur : " . $error_message . "</h2>"; ?>
<form method="POST">
<input type="hidden" name="submitted" value="true" />
<table style="width: 100%;">

View File

@ -1,9 +1,7 @@
<?php
require_once "header.php";
if ($has_error)
echo "<h2>Erreur : " . $error_message . "</h2>";
else {
if (!$has_error) {
if (isset($recuperate_account))
echo "<h2>Le mail de récupération de mot de passe a bien été envoyé.</h2>";
elseif (isset($reset_password))

View File

@ -2,9 +2,7 @@
require_once "header.php";
if ($has_error)
echo "<h2>Erreur : $error_message</h2>";
elseif (isset($new_video))
if (isset($new_video) && !$has_error)
echo "<h2>Votre vidéo a bien été envoyée !</h2>";
?>

View File

@ -20,6 +20,28 @@ for ($i = 1; $i <= 5; ++$i) {
}
?>
<?php
if ($_SESSION["role"] == Role::ADMIN) { ?>
<hr />
<form method="POST">
<label for="other_teams">L'équipe va recevoir les questions des équipes suivantes (merci d'en sélectionner exactement 2) :</label>
<select style="width: 100%;" id="other_teams" name="other_teams[]" multiple>
<?php
/** @var Team $other_team */
foreach ($other_teams as $other_team) {
if ($other_team->getId() == $team->getId())
continue;
$team_name = $other_team->getName() . " (" . $other_team->getTrigram() . ")";
$team_id = $other_team->getId();
echo "<option value=\"$team_id\" " . (in_array($other_team->getId(), $team->getVideoTeamIds()) ? "selected" : "") . ">$team_name</option>\n";
}
?>
</select>
<input style="width: 100%;" type="submit" name="update_video_teams" value="Mettre à jour" />
</form>
<?php } ?>
<hr/>
<h2>Autorisations</h2>
@ -31,6 +53,7 @@ for ($i = 1; $i <= 5; ++$i) {
</form>
<?php if ($team->getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?>
<hr />
<form method="POST">
<input style="width: 100%;" type="submit" name="validate" value="Valider l'équipe"/>
</form>

View File

@ -9,16 +9,20 @@
<link REL="shortcut icon" href="<?= $URL_BASE ?>/favicon.ico"/>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" type="text/css" href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css"
href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/bootstrap/css/bootstrap.min.css">
<!-- Custom fonts for this template -->
<link rel="stylesheet" type="text/css" href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css"
href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/font-awesome/css/font-awesome.min.css">
<!-- Plugin CSS -->
<link rel="stylesheet" type="text/css" href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/datatables/dataTables.bootstrap4.css">
<link rel="stylesheet" type="text/css"
href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/vendor/datatables/dataTables.bootstrap4.css">
<!-- Custom styles for this template -->
<link rel="stylesheet" type="text/css" href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/css2/sb-admin.css">
<link rel="stylesheet" type="text/css"
href="https://s3-eu-west-1.amazonaws.com/tfjm2-inscriptions/static/inscription/css2/sb-admin.css">
</head>
<body>
@ -54,7 +58,7 @@
<?php if ($_SESSION["team"]->getValidationStatus() == ValidationStatus::VALIDATED) {
switch (Phase::getCurrentPhase()) {
case Phase::PHASE1: ?>
<li><a href="<?= $URL_BASE ?>/envoyer-video-1">Envoyer ma vidéo (phase 1)</a></li>
<li><a href="<?= $URL_BASE ?>/envoyer-video-1">Envoyer ma vidéo (phase 1)</a></li>
<?php break;
}
} ?>
@ -82,4 +86,8 @@
<div id="main-container">
<div id="main-content">
<div class="container-fluid">
<div class="container-fluid">
<?php
if (isset($has_error) && $has_error) {
echo "<h2>Erreur : " . $error_message . "</h2>";
}

View File

@ -1,11 +1,6 @@
<?php
require_once "header.php";
if ($has_error)
echo "<h2>Erreur : " . $error_message . "</h2>";
?>
<?php
/** @var NewUser $user */
if (isset($user) && !$has_error) {
?>

View File

@ -1,10 +1,7 @@
<?php
require_once "header.php";
if ($has_error)
echo "<h2>Erreur : " . $error_message . "</h2>";
elseif (isset($my_account) || isset($new_password)) {
if (!$has_error && (isset($my_account) || isset($new_password))) {
?>
<h2>Votre compte a bien été mis à jour !</h2>
<?php

View File

@ -1,9 +1,7 @@
<?php
require_once "header.php";
if ($has_error)
echo "<h2>Erreur : " . $error_message . "</h2>";
elseif (isset($send_document))
if (!$has_error && isset($send_document))
echo "<h2>Le fichier a été correctement envoyé !</h2>";
?>

View File

@ -7,185 +7,67 @@ if ($has_error)
<h2>Problème <?= $problem ?></h2>
<?php if (!isset($_GET["modifier"]) && $_SESSION["role"] == Role::ADMIN) { ?>
<a href="<?= $URL_BASE ?>/probleme/<?= $problem ?>/modifier">Éditer le tournoi</a>
<?php } ?>
<hr/>
<?php if (!isset($_GET["modifier"])) { ?>
<hr/>
<h2>Équipes inscrites pour ce problème :</h2>
<table style="border: 1px solid black; width: 100%;">
<thead>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</thead>
<tbody>
<?php
/** @var Team $team */
foreach ($teams as $team) {
?>
<tr>
<td style="border: 1px solid black; text-align: center">
<?php
if (isset($_SESSION["role"]) && $_SESSION["role"] == Role::ADMIN)
echo "<a href=\"$URL_BASE/equipe/" . $team->getTrigram() . "\">" . $team->getName(). "</a>";
else
echo $team->getName();
?>
</td>
<td style="border: 1px solid black; text-align: center"><?= $team->getTrigram() ?></td>
<td style="border: 1px solid black; text-align: center"><?= formatDate($team->getInscriptionDate()) ?></td>
<td style="border: 1px solid black; text-align: center"><?= ValidationStatus::getTranslatedName($team->getValidationStatus()) ?></td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</tfoot>
</table>
<h2>Équipes inscrites pour ce problème :</h2>
<table style="border: 1px solid black; width: 100%;">
<thead>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</thead>
<tbody>
<?php
}
else {
/** @var Team $team */
foreach ($teams as $team) {
?>
<tr>
<td style="border: 1px solid black; text-align: center">
<?php
if (isset($_SESSION["role"]) && $_SESSION["role"] == Role::ADMIN)
echo "<a href=\"$URL_BASE/equipe/" . $team->getTrigram() . "\">" . $team->getName() . "</a>";
else
echo $team->getName();
?>
</td>
<td style="border: 1px solid black; text-align: center"><?= $team->getTrigram() ?></td>
<td style="border: 1px solid black; text-align: center"><?= formatDate($team->getInscriptionDate()) ?></td>
<td style="border: 1px solid black; text-align: center"><?= ValidationStatus::getTranslatedName($team->getValidationStatus()) ?></td>
</tr>
<?php
}
?>
<form method="POST">
<input type="hidden" name="submitted" value="true" />
<table style="width: 100%;">
<tbody>
<tr>
<td style="width: 30%;">
<label for="name">Nom :</label>
</td>
<td style="width: 70%;">
<input style="width: 100%;" type="text" id="name" name="name" value="<?= $tournament->getName() ?>" required />
</td>
</tr>
<?php if ($_SESSION["role"] == Role::ADMIN) { ?>
<tr>
<td>
<label for="organizers">Organisateur :</label>
</td>
<td>
<select style="width: 100%;" id="organizers" name="organizers[]" multiple size="4" required>
<?php
while (($orga_data = $orgas_response->fetch()) !== FALSE) {
echo "<option value=\"" . $orga_data["id"] . "\" " . ($tournament->organize($orga_data["id"]) ? "selected" : "")
. ">" . $orga_data["first_name"] . " " . $orga_data["surname"] . "</option>\n";
}
?>
</select>
</td>
</tr>
<?php } ?>
<tr>
<td>
<label for="size">Nombre d'équipes :</label>
</td>
<td>
<input style="width: 100%;" type="number" id="size" name="size" min="3" max="12" value="<?= $tournament->getSize() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="place">Lieu :</label>
</td>
<td>
<input style="width: 100%;" type="text" id="place" name="place" value="<?= $tournament->getPlace() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="price">Prix par participant</label>
</td>
<td>
<input style="width: 100%;" type="number" id="price" name="price" min="0" max="50" value="<?= $tournament->getPrice() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_start">Dates :</label>
</td>
<td>
Du <input style="width: 45%;" type="date" id="date_start" name="date_start" value="<?= $tournament->getStartDate() ?>" required />
au <input style="width: 45%;" type="date" id="date_end" name="date_end" value="<?= $tournament->getEndDate() ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_inscription">Date limite d'inscription :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_inscription" name="date_inscription" value="<?= substr($tournament->getInscriptionDate(), 0, 10) ?>" required />
<input style="width: 49%;" type="time" id="time_inscription" name="time_inscription" value="<?= substr($tournament->getInscriptionDate(), 11) ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_solutions">Date limite pour rendre les solutions :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_solutions" name="date_solutions" value="<?= substr($tournament->getSolutionsDate(), 0, 10) ?>" required />
<input style="width: 49%;" type="time" id="time_solutions" name="time_solutions" value="<?= substr($tournament->getSolutionsDate(),11) ?>" required />
</td>
</tr>
<tr>
<td>
<label for="date_syntheses">Date limite pour rendre les notes de synthèse :</label>
</td>
<td>
<input style="width: 49%;" type="date" id="date_syntheses" name="date_syntheses"
value="<?= substr($tournament->getSynthesesDate(), 0, 10) ?>" required/>
<input style="width: 49%;" type="time" id="time_syntheses" name="time_syntheses"
value="<?= substr($tournament->getSynthesesDate(), 11) ?>" required/>
</td>
</tr>
<tr>
<td>
<label for="description">Description :</label>
</td>
<td>
<textarea style="width: 100%;" name="description" id="description" required><?= $tournament->getDescription() ?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input style="width: 100%;" type="submit" name="edit_tournament" value="Modifier le tournoi" />
</td>
</tr>
</tbody>
</table>
</form>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th style="border: 1px solid black; text-align: center">
Équipe
</th>
<th style="border: 1px solid black; text-align: center">
Trigramme
</th>
<th style="border: 1px solid black; text-align: center">
Date d'inscription
</th>
<th style="border: 1px solid black; text-align: center">
État de validation de l'inscription
</th>
</tr>
</tfoot>
</table>
<?php require_once "footer.php" ?>

View File

@ -2,10 +2,6 @@
require_once "header.php";
if ($has_error) {
echo "<h2>Erreur : $error_message</h2>";
}
for ($problem = 1; $problem <= 4; ++$problem) {
echo "<h2>Vidéos pour le problème $problem</h2>\n";
/** @var Video $video */