1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Phase 1 : envoi des vidéos (en cours)

This commit is contained in:
galaxyoyo 2019-09-17 00:04:45 +02:00
parent 0fdae19f2d
commit a8db4a421c
7 changed files with 160 additions and 14 deletions

View File

@ -4,11 +4,13 @@ require_once "server_files/config.php";
require_once "server_files/classes/Document.php";
require_once "server_files/classes/Phase.php";
require_once "server_files/classes/Reason.php";
require_once "server_files/classes/Role.php";
require_once "server_files/classes/SchoolClass.php";
require_once "server_files/classes/Team.php";
require_once "server_files/classes/User.php";
require_once "server_files/classes/ValidationStatus.php";
require_once "server_files/classes/Video.php";
require_once "server_files/services/mail.php";
require_once "server_files/utils.php";
require_once "server_files/model.php";

View File

@ -0,0 +1,35 @@
<?php
class Reason
{
const SOLUTION = 0;
const ANSWER = 1;
public static function getTranslatedName($class) {
switch ($class) {
case self::ANSWER:
return "Réponse";
default:
return "Solution";
}
}
public static function getName($class) {
switch ($class) {
case self::ANSWER:
return "ANSWER";
default:
return "SOLUTION";
}
}
public static function fromName($name) {
switch ($name) {
case "ANSWER":
return self::ANSWER;
default:
return self::SOLUTION;
}
}
}

View File

@ -186,11 +186,6 @@ class User
$DB->prepare("UPDATE `users` SET `team_id` = ? WHERE `id` = ?;")->execute([$team_id, $this->getId()]);
}
public function getYear()
{
return $this->year;
}
public function getConfirmEmailToken()
{
return $this->confirm_email;

View File

@ -0,0 +1,112 @@
<?php
class Video
{
private $id;
private $team;
private $problem;
private $link;
private $reason;
private $uploaded_at;
private $year;
private $version;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `videos` WHERE `id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
$video = new Video();
$video->fill($data);
return $video;
}
public static function getVideos($reason, $problem, $team_id = -1)
{
global $DB;
$req = $DB->query("SELECT * FROM `videos` AS `t1` "
. "INNER JOIN (SELECT `team`, `problem`, `reason`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `videos` GROUP BY `problem`, `reason`, `team`) `t2` "
. "ON `t1`.`team` = `t2`.`team` AND `t1`.`reason` = `t2`.`reason` AND `t1`.`problem` = `t2`.`problem` "
. "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`problem` = $problem AND `t1`.`reason` = '" . Reason::getName($reason) . "'"
. ($team_id >= 0 ? " AND `t1`.`team` = $team_id" : "") . " ORDER BY `t1`.`problem`, `t1`.`reason`;");
$videos = [];
while (($data = $req->fetch()) !== false) {
$video = new Video();
$video->fill($data);
$videos[] = $video;
}
return $videos;
}
/**
* @param int $reason
* @param Team $team
* @return Video|null
*/
public static function getVideo($reason, Team $team) {
$videos = self::getVideos($reason, $team->getProblem(), $team->getId());
if (sizeof($videos) == 0)
return null;
else
return $videos[0];
}
private function fill($data)
{
foreach ($data as $key => $value)
$this->$key = $value;
$this->reason = Reason::fromName($this->reason);
}
public function getId()
{
return $this->id;
}
public function getTeam()
{
return $this->team;
}
public function getProblem()
{
return $this->problem;
}
public function getLink()
{
return $this->link;
}
public function getReason()
{
return $this->reason;
}
public function getUploadedAt()
{
return $this->uploaded_at;
}
public function getYear()
{
return $this->year;
}
public function getVersion()
{
return $this->version;
}
}

View File

@ -31,7 +31,8 @@ class NewVideo
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.");
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);
}
public function uploadVideo()
@ -43,6 +44,6 @@ class NewVideo
}
}
$videos_req = $DB->query("SELECT * FROM `videos` WHERE `year` = $YEAR;");
$video = Video::getVideo(Reason::SOLUTION, $team);
require_once "server_files/views/envoyer_video.php";

View File

@ -41,6 +41,7 @@ class MyAccount
public $school;
public $class;
public $description;
/** @var User */
private $user;
public function __construct($data)

View File

@ -9,12 +9,12 @@ elseif (isset($new_video))
?>
<?php
while (($data = $videos_req->fetch()) !== false) {
$link = $data["link"];
echo "<a href=\"$link\">$link</a><br />";
if (preg_match("#https?\://www\.youtube\.com\/watch\?v=(.*)#", $link, $matches)) {
$code = $matches[1];
echo "<center><iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$code\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe></center><br />";
if ($video !== null) {
$link = $video->getLink();
echo "Lien de la vidéo déjà envoyée : <a href=\"$link\">$link</a> (version " . $video->getVersion() . ")<br />";
if (preg_match("#(https?\://|)(www\.|)youtube\.com\/watch\?v=(.*)#", $link, $matches)) {
$code = $matches[3];
echo "<center><iframe width=\"854px\" height=\"480px\" src=\"https://www.youtube.com/embed/$code\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe></center><br />";
}
}
?>
@ -24,7 +24,7 @@ while (($data = $videos_req->fetch()) !== false) {
<tbody>
<tr>
<td style="width: 30%;">
<label for="link">Lien de la vidéo :</label>
<label for="link">Lien de la vidéo à soumettre :</label>
</td>
<td style="width: 70%;">
<input style="width: 100%;" type="url" id="link" name="link" />