diff --git a/server_files/classes/Team.php b/server_files/classes/Team.php index fb1de50..e48aa8b 100644 --- a/server_files/classes/Team.php +++ b/server_files/classes/Team.php @@ -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; diff --git a/server_files/controllers/equipe.php b/server_files/controllers/equipe.php index 0eb8034..fa2c96e 100644 --- a/server_files/controllers/equipe.php +++ b/server_files/controllers/equipe.php @@ -1,7 +1,7 @@ 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"; diff --git a/server_files/controllers/probleme.php b/server_files/controllers/probleme.php index c06aa02..383b3c7 100644 --- a/server_files/controllers/probleme.php +++ b/server_files/controllers/probleme.php @@ -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"; diff --git a/server_files/views/ajouter_admin.php b/server_files/views/ajouter_admin.php index d256b78..d4f2ac4 100644 --- a/server_files/views/ajouter_admin.php +++ b/server_files/views/ajouter_admin.php @@ -1,12 +1,8 @@ Erreur : " . $error_message . ""; - } else { - echo "