mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-29 02:30:57 +02:00
Ajout d'une classe pour les fichiers à télécharger, meilleur support des organisateurs d'un tournoi
This commit is contained in:
282
server_files/classes/Document.php
Normal file
282
server_files/classes/Document.php
Normal file
@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
class Document
|
||||
{
|
||||
private $file_id;
|
||||
private $user_id;
|
||||
private $team_id;
|
||||
private $tournament_id;
|
||||
private $type;
|
||||
private $uploaded_at;
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public static function fromId($id)
|
||||
{
|
||||
global $DB;
|
||||
$req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;");
|
||||
$req->execute([htmlspecialchars($id)]);
|
||||
$data = $req->fetch();
|
||||
|
||||
if ($data === false)
|
||||
return null;
|
||||
|
||||
$user = new Document();
|
||||
$user->fill($data);
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function fill($data)
|
||||
{
|
||||
$this->file_id = $data["file_id"];
|
||||
$this->user_id = $data["user"];
|
||||
$this->team_id = $data["team"];
|
||||
$this->tournament_id = $data["tournament"];
|
||||
$this->type = DocumentType::fromName($data["type"]);
|
||||
$this->uploaded_at = $data["uploaded_at"];
|
||||
}
|
||||
|
||||
public function getFileId()
|
||||
{
|
||||
return $this->file_id;
|
||||
}
|
||||
|
||||
public function getUserId()
|
||||
{
|
||||
return $this->user_id;
|
||||
}
|
||||
|
||||
public function getTeamId()
|
||||
{
|
||||
return $this->team_id;
|
||||
}
|
||||
|
||||
public function getTournamentId()
|
||||
{
|
||||
return $this->tournament_id;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function getUploadedAt()
|
||||
{
|
||||
return $this->uploaded_at;
|
||||
}
|
||||
}
|
||||
|
||||
class Solution
|
||||
{
|
||||
private $file_id;
|
||||
private $team_id;
|
||||
private $tournament_id;
|
||||
private $problem;
|
||||
private $uploaded_at;
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public static function fromId($id)
|
||||
{
|
||||
global $DB;
|
||||
$req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;");
|
||||
$req->execute([htmlspecialchars($id)]);
|
||||
$data = $req->fetch();
|
||||
|
||||
if ($data === false)
|
||||
return null;
|
||||
|
||||
$user = new Solution();
|
||||
$user->fill($data);
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function fill($data)
|
||||
{
|
||||
$this->file_id = $data["file_id"];
|
||||
$this->team_id = $data["team_id"];
|
||||
$this->tournament_id = $data["tournament_id"];
|
||||
$this->problem = $data["problem"];
|
||||
$this->uploaded_at = $data["uploaded_at"];
|
||||
}
|
||||
|
||||
public function getFileId()
|
||||
{
|
||||
return $this->file_id;
|
||||
}
|
||||
|
||||
public function getTeamId()
|
||||
{
|
||||
return $this->team_id;
|
||||
}
|
||||
|
||||
public function getTournamentId()
|
||||
{
|
||||
return $this->tournament_id;
|
||||
}
|
||||
|
||||
public function getProblem()
|
||||
{
|
||||
return $this->problem;
|
||||
}
|
||||
|
||||
public function getUploadedAt()
|
||||
{
|
||||
return $this->uploaded_at;
|
||||
}
|
||||
}
|
||||
|
||||
class Synthese
|
||||
{
|
||||
private $file_id;
|
||||
private $team_id;
|
||||
private $tournament_id;
|
||||
private $dest;
|
||||
private $uploaded_at;
|
||||
|
||||
private function __construct() {}
|
||||
|
||||
public static function fromId($id)
|
||||
{
|
||||
global $DB;
|
||||
$req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;");
|
||||
$req->execute([htmlspecialchars($id)]);
|
||||
$data = $req->fetch();
|
||||
|
||||
if ($data === false)
|
||||
return null;
|
||||
|
||||
$user = new Synthese();
|
||||
$user->fill($data);
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function fill($data)
|
||||
{
|
||||
$this->file_id = $data["file_id"];
|
||||
$this->team_id = $data["team"];
|
||||
$this->tournament_id = $data["tournament"];
|
||||
$this->dest = DestType::fromName($data["dest"]);
|
||||
$this->uploaded_at = $data["uploaded_at"];
|
||||
}
|
||||
|
||||
public function getFileId()
|
||||
{
|
||||
return $this->file_id;
|
||||
}
|
||||
|
||||
public function getTeamId()
|
||||
{
|
||||
return $this->team_id;
|
||||
}
|
||||
|
||||
public function getTournamentId()
|
||||
{
|
||||
return $this->tournament_id;
|
||||
}
|
||||
|
||||
public function getDest()
|
||||
{
|
||||
return $this->dest;
|
||||
}
|
||||
|
||||
public function getUploadedAt()
|
||||
{
|
||||
return $this->uploaded_at;
|
||||
}
|
||||
}
|
||||
|
||||
class DestType
|
||||
{
|
||||
const DEFENSEUR = 0;
|
||||
const OPPOSANT = 1;
|
||||
const RAPPORTEUR = 2;
|
||||
|
||||
public static function getTranslatedName($status) {
|
||||
switch ($status) {
|
||||
case self::DEFENSEUR:
|
||||
return "Défenseur";
|
||||
case self::OPPOSANT:
|
||||
return "Opposant";
|
||||
default:
|
||||
return "Rapporteur";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getName($status) {
|
||||
switch ($status) {
|
||||
case self::DEFENSEUR:
|
||||
return "DEFENSEUR";
|
||||
case self::OPPOSANT:
|
||||
return "OPPOSANT";
|
||||
default:
|
||||
return "RAPPORTEUR";
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromName($name) {
|
||||
switch ($name) {
|
||||
case "DEFENSEUR":
|
||||
return self::DEFENSEUR;
|
||||
case "OPPOSANT":
|
||||
return self::OPPOSANT;
|
||||
default:
|
||||
return self::RAPPORTEUR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DocumentType
|
||||
{
|
||||
const PARENTAL_CONSENT = 0;
|
||||
const PHOTO_CONSENT = 1;
|
||||
const SANITARY_PLUG = 2;
|
||||
const SOLUTION = 3;
|
||||
const SYNTHESE = 4;
|
||||
|
||||
public static function getTranslatedName($type) {
|
||||
switch ($type) {
|
||||
case self::PARENTAL_CONSENT:
|
||||
return "Autorisation parentale";
|
||||
case self::PHOTO_CONSENT:
|
||||
return "Autorisation de droit à l'image";
|
||||
case self::SANITARY_PLUG:
|
||||
return "Fiche sanitaire";
|
||||
case self::SOLUTION:
|
||||
return "Solution";
|
||||
default:
|
||||
return "Note de synthèse";
|
||||
}
|
||||
}
|
||||
|
||||
public static function getName($type) {
|
||||
switch ($type) {
|
||||
case self::PARENTAL_CONSENT:
|
||||
return "PARENTAL_CONSENT";
|
||||
case self::PHOTO_CONSENT:
|
||||
return "PHOTO_CONSENT";
|
||||
case self::SANITARY_PLUG:
|
||||
return "SANITARY_PLUG";
|
||||
case self::SOLUTION:
|
||||
return "SOLUTION";
|
||||
default:
|
||||
return "SYNTHESE";
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromName($name) {
|
||||
switch ($name) {
|
||||
case "PARENTAL_CONSENT":
|
||||
return self::PARENTAL_CONSENT;
|
||||
case "PHOTO_CONSENT":
|
||||
return self::PHOTO_CONSENT;
|
||||
case "SANITARY_PLUG":
|
||||
return self::SANITARY_PLUG;
|
||||
case "SOLUTION":
|
||||
return self::SOLUTION;
|
||||
default:
|
||||
return self::SYNTHESE;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user