1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 07:02:22 +00:00

Amélioration du code de la page "Notes de synthèse" (vue équipe)

This commit is contained in:
galaxyoyo 2019-09-10 01:02:13 +02:00
parent 44e3e3f639
commit cca62a99d0
3 changed files with 48 additions and 33 deletions

View File

@ -231,34 +231,34 @@ class DestType
public static function getTranslatedName($status) {
switch ($status) {
case self::DEFENSEUR:
return "Défenseur";
case self::OPPOSANT:
return "Opposant";
default:
case self::RAPPORTEUR:
return "Rapporteur";
default:
return "Défenseur";
}
}
public static function getName($status) {
switch ($status) {
case self::DEFENSEUR:
return "DEFENSEUR";
case self::OPPOSANT:
return "OPPOSANT";
default:
case self::RAPPORTEUR:
return "RAPPORTEUR";
default:
return "DEFENSEUR";
}
}
public static function fromName($name) {
switch ($name) {
case "DEFENSEUR":
return self::DEFENSEUR;
case "OPPOSANT":
return self::OPPOSANT;
default:
case "RAPPORTEUR":
return self::RAPPORTEUR;
default:
return self::DEFENSEUR;
}
}
}

View File

@ -54,6 +54,7 @@ class SaveSolution
public function saveSolution()
{
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
do
$id = genRandomPhrase(64);
while (file_exists("$LOCAL_PATH/files/$id"));

View File

@ -11,7 +11,14 @@ $team = $_SESSION["team"];
$tournament = Tournament::fromId($team->getTournamentId());
if (isset($_POST["send_synthesis"])) {
$error_message = saveSynthesis();
$save_synthesis = new SaveSynthesis();
try {
$save_synthesis->makeVerifications();
$save_synthesis->saveSynthesis();
} catch (AssertionError $e) {
$has_error = true;
$error_message = $e->getMessage();
}
}
$syntheses = $tournament->getAllSyntheses($team->getId());
@ -19,36 +26,43 @@ $syntheses_final = null;
if ($team->isSelectedForFinal())
$syntheses_final = $FINAL->getAllSyntheses($team->getId());
function saveSynthesis() {
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
class SaveSynthesis
{
private $dest;
private $file;
$dest = strtoupper(htmlspecialchars($_POST["dest"]));
public function __construct()
{
$this->file = $_FILES["document"];
$this->dest = DestType::fromName(strtoupper(htmlspecialchars($_POST["problem"])));
}
if (!isset($dest) || ($dest != "OPPOSANT" && $dest != "RAPPORTEUR"))
return "Le destinataire est invalide.";
public function makeVerifications()
{
global $LOCAL_PATH;
$file = $_FILES["synthese"];
ensure($this->dest != DestType::DEFENSEUR, "Le destinataire est invalide.");
ensure($this->file["size"] <= 2e6, "Le fichier doit peser moins que 2 Mo.");
ensure(!$this->file["error"], "Une erreur est survenue.");
ensure(finfo_file(finfo_open(FILEINFO_MIME_TYPE), $this->file["tmp_name"]) == "application/pdf", "Le fichier doit être au format PDF.");
ensure(is_dir("$LOCAL_PATH/files") || mkdir("$LOCAL_PATH/files"), "Un problème est survenue dans l'envoi du fichier. Veuillez contacter l'administrateur du serveur.");
}
if ($file["size"] > 5000000 || $file["error"])
return "Une erreur est survenue. Merci de vérifier que le fichier pèse moins que 5 Mo.";
public function saveSynthesis()
{
global $LOCAL_PATH, $DB, $team, $tournament, $FINAL;
do
$id = genRandomPhrase(64);
while (file_exists("$LOCAL_PATH/files/$id"));
if (finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file["tmp_name"]) != 'application/pdf')
return "Le fichier doit être au destmat PDF.";
if (!rename($this->file["tmp_name"], "$LOCAL_PATH/files/$id"))
throw new AssertionError("Une erreur est survenue lors de l'envoi du fichier.");
if (!is_dir("$LOCAL_PATH/files") && !mkdir("$LOCAL_PATH/files"))
return "Les droits sont insuffisants. Veuillez contacter l'administrateur du serveur.";
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $this->dest]);
do
$id = genRandomPhrase(64);
while (file_exists("$LOCAL_PATH/files/$id"));
if (!rename($file["tmp_name"], "$LOCAL_PATH/files/$id"))
return "Une erreur est survenue lors de l'envoi du fichier.";
$req = $DB->prepare("INSERT INTO `syntheses`(`file_id`, `team`, `tournament`, `dest`) VALUES (?, ?, ?, ?);");
$req->execute([$id, $team->getId(), $team->isSelectedForFinal() ? $FINAL->getId() : $tournament->getId(), $dest]);
return false;
return false;
}
}
require_once "server_files/views/syntheses.php";