mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-24 10:28:44 +02:00
Flexibilité sur la validation des vidéos accrue
This commit is contained in:
@ -22,17 +22,22 @@ if (isset($_POST["upload"])) {
|
||||
|
||||
class NewVideo
|
||||
{
|
||||
private $link;
|
||||
public $link;
|
||||
private $valid_link;
|
||||
private $no_change;
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->link = $data["link"];
|
||||
foreach ($data as $key => $value)
|
||||
$this->$key = $value;
|
||||
}
|
||||
|
||||
public function makeVerifications()
|
||||
{
|
||||
ensure(preg_match("#(https?\:\/\/|)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?#", $this->link), "Ce n'est pas une URL valide.");
|
||||
$this->link = preg_replace('/^(?!https?:\/\/)/', 'https://', $this->link);
|
||||
ensure($this->valid_link != null, "Vous devez confirmer que le lien est valide.");
|
||||
ensure($this->no_change != null, "Vous devez vous engager à ne pas changer le contenu du lien et de la vidéo.");
|
||||
}
|
||||
|
||||
public function uploadVideo()
|
||||
@ -41,9 +46,12 @@ class NewVideo
|
||||
|
||||
$req = $DB->prepare("INSERT INTO `videos`(`team`, `problem`, `link`, `reason`, `year`) VALUES (?, ?, ?, ?, ?)");
|
||||
$req->execute([$team->getId(), $team->getProblem(), $this->link, "SOLUTION", $YEAR]);
|
||||
|
||||
Mailer::sendNewVideo($this, $team);
|
||||
}
|
||||
}
|
||||
|
||||
$video = Video::getVideo(Reason::SOLUTION, $team);
|
||||
$video_validated = Video::getVideo(Reason::SOLUTION, $team, Video::ACCEPTED);
|
||||
|
||||
require_once "server_files/views/envoyer_video.php";
|
@ -41,6 +41,7 @@ class MyAccount
|
||||
public $school;
|
||||
public $class;
|
||||
public $description;
|
||||
public $receive_animath_mails;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
@ -65,6 +66,7 @@ class MyAccount
|
||||
ensure(filter_var($this->email, FILTER_VALIDATE_EMAIL), "L'adresse e-mail entrée est invalide.");
|
||||
$this->email = strtolower($this->email);
|
||||
ensure($this->email == $this->user->getEmail() || !userExists($this->email), "Un compte existe déjà avec cette adresse e-mail.");
|
||||
$this->receive_animath_mails = $this->receive_animath_mails != false;
|
||||
}
|
||||
|
||||
public function updateAccount()
|
||||
@ -74,6 +76,7 @@ class MyAccount
|
||||
$this->user->setSchool($this->school);
|
||||
$this->user->setClass($this->class);
|
||||
$this->user->setDescription($this->description);
|
||||
$this->user->setReceiveAnimathMails($this->receive_animath_mails);
|
||||
|
||||
if ($this->email != $this->user->getEmail()) {
|
||||
$this->user->setEmail($this->email);
|
||||
|
@ -3,9 +3,54 @@
|
||||
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";
|
Reference in New Issue
Block a user