1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-06-25 00:20:28 +02: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

@ -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;
}
}