2019-09-16 22:19:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if (!isset($_SESSION["user_id"]) || $_SESSION["role"] != Role::ADMIN)
|
|
|
|
require_once "server_files/403.php";
|
|
|
|
|
2019-09-18 22:31:53 +00:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 22:19:01 +00:00
|
|
|
$videos = [];
|
|
|
|
|
|
|
|
for ($problem = 1; $problem <= 4; ++$problem)
|
|
|
|
$videos[] = Video::getVideos(Reason::SOLUTION, $problem);
|
|
|
|
|
2019-09-18 22:31:53 +00:00
|
|
|
|
2019-09-16 22:19:01 +00:00
|
|
|
require_once "server_files/views/videos_solutions.php";
|