mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-26 06:22:20 +00:00
56 lines
1.3 KiB
PHP
56 lines
1.3 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);
|
|
|
|
|
|
require_once "server_files/views/videos_solutions.php"; |