plateforme-corres2math/server_files/controllers/suivi_tournoi.php

110 lines
4.2 KiB
PHP

<?php
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
require_once "server_files/403.php";
$has_error = false;
$error_message = null;
if (isset($_POST["validate_video"])) {
$validate_video = new ValidateVideo($_POST);
try {
$validate_video->makeVerifications();
$validate_video->validate();
}
catch (AssertionError $e) {
$has_error = true;
$error_message = $e->getMessage();
}
}
class ValidateVideo
{
private $video_id;
private $accept;
private $reject;
/** @var Video */
private $video;
public function __construct($data)
{
foreach ($data as $key => $value)
$this->$key = $value;
}
public function makeVerifications()
{
$this->video = Video::fromId($this->video_id);
ensure($this->video != null, "La vidéo n'existe pas.");
ensure($this->video->getValidation() == 0, "La vidéo est déjà validée / rejetée.");
ensure(($this->accept == null || $this->reject == null) && $this->accept != $this->reject, "Impossible de déterminer s'il faut accepter ou non la vidéo.");
}
public function validate()
{
$this->video->setValidation($this->accept ? 1 : -1);
Mailer::validateVideo($this->video);
}
}
$videos = [];
for ($problem = 1; $problem <= 4; ++$problem)
$videos[] = Video::getVideos(Reason::SOLUTION, $problem);
$waiting_teams = [];
switch (Phase::getCurrentPhase()) {
case Phase::PHASE1:
$req = $DB->query("SELECT DISTINCT `teams`.`id` FROM `teams` WHERE `validation_status` = '" . ValidationStatus::getName(ValidationStatus::VALIDATED) . "'"
. " AND `id` NOT IN (SELECT DISTINCT `team` FROM `videos` WHERE `reason` = 'SOLUTION' AND `validation` = " . Video::ACCEPTED . ")"
. " AND `year` = $YEAR;");
break;
case Phase::PHASE2:
$req = $DB->query("SELECT DISTINCT `teams`.`id` FROM `teams`"
. " WHERE `id` NOT IN (SELECT `q1`.`from` FROM `questions` AS `q1`"
. " JOIN `questions` AS `q2` ON `q2`.`from` = `q1`.`from` AND `q2`.`number` = 1"
. " JOIN `questions` AS `q3` ON `q3`.`from` = `q1`.`from` AND `q3`.`number` = 2"
. " JOIN `questions` AS `q4` ON `q4`.`from` = `q1`.`from` AND `q4`.`number` = 3"
. " JOIN `questions` AS `q5` ON `q5`.`from` = `q1`.`from` AND `q5`.`number` = 4"
. " JOIN `questions` AS `q6` ON `q6`.`from` = `q1`.`from` AND `q6`.`number` = 5"
. " WHERE `q1`.`question` != '" . Question::DEFAULT_QUESTIONS[0] . "'"
. " OR `q2`.`question` != '" . Question::DEFAULT_QUESTIONS[1] . "'"
. " OR `q3`.`question` != '" . Question::DEFAULT_QUESTIONS[2] . "'"
. " OR `q4`.`question` IS NOT NULL"
. " OR `q5`.`question` IS NOT NULL"
. " OR `q6`.`question` IS NOT NULL)"
. " AND `validation_status` = '" . ValidationStatus::getName(ValidationStatus::VALIDATED) . "'"
. " AND `year` = $YEAR;");
break;
case Phase::PHASE3:
$req = $DB->query("SELECT DISTINCT `teams`.`id` FROM `teams`"
. " WHERE `id` NOT IN (SELECT `q1`.`to` FROM `questions` AS `q1`"
. " JOIN `questions` AS `q2` ON `q2`.`to` = `q1`.`to` AND `q2`.`number` = 1"
. " JOIN `questions` AS `q3` ON `q3`.`to` = `q1`.`to` AND `q3`.`number` = 2"
. " JOIN `questions` AS `q4` ON `q4`.`to` = `q1`.`to` AND `q4`.`number` = 3"
. " JOIN `questions` AS `q5` ON `q5`.`to` = `q1`.`to` AND `q5`.`number` = 4"
. " JOIN `questions` AS `q6` ON `q6`.`to` = `q1`.`to` AND `q6`.`number` = 5"
. " WHERE `q1`.`answer` IS NOT NULL"
. " OR `q2`.`answer` IS NOT NULL"
. " OR `q3`.`answer` IS NOT NULL"
. " OR `q4`.`answer` IS NOT NULL"
. " OR `q5`.`answer` IS NOT NULL"
. " OR `q6`.`answer` IS NOT NULL)"
. " AND `validation_status` = '" . ValidationStatus::getName(ValidationStatus::VALIDATED) . "'"
. " AND `year` = $YEAR;");
break;
case Phase::PHASE4:
$req = $DB->query("SELECT DISTINCT `teams`.`id` FROM `teams` WHERE `validation_status` = '" . ValidationStatus::getName(ValidationStatus::VALIDATED) . "'"
. " AND (`id` NOT IN (SELECT DISTINCT `team` FROM `videos` WHERE `reason` = 'ANSWER1' AND `validation` = " . Video::ACCEPTED . ")"
. " OR `id` NOT IN (SELECT DISTINCT `team` FROM `videos` WHERE `reason` = 'ANSWER2' AND `validation` = " . Video::ACCEPTED . "))"
. " AND `year` = $YEAR;");
break;
}
if (isset($req)) {
while (($data = $req->fetch()) !== false)
$waiting_teams[] = Team::fromId($data["id"]);
}
require_once "server_files/views/suivi_tournoi.php";