1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-06-24 11:48:46 +02:00

Suppression de contenu inutile pour les correspondances

This commit is contained in:
galaxyoyo
2019-09-11 18:41:45 +02:00
parent 07e7b94f5c
commit 340be7faf5
34 changed files with 86 additions and 1985 deletions

View File

@ -2,11 +2,10 @@
function loadUserValues()
{
$_SESSION["user"] = $_SESSION["team"] = $_SESSION["tournament"] = null;
$_SESSION["user"] = $_SESSION["team"] = null;
unset($_SESSION["user"]);
unset($_SESSION["role"]);
unset($_SESSION["team"]);
unset($_SESSION["tournament"]);
if (isset($_SESSION["user_id"])) {
$user = $_SESSION["user"] = User::fromId($_SESSION["user_id"]);
@ -21,12 +20,6 @@ function loadUserValues()
exit();
}
if (isset($_GET["be-organizer"])) {
quitTeam();
$user->setRole(Role::ORGANIZER);
exit();
}
if (isset($_GET["be-participant"])) {
quitTeam();
$user->setRole(Role::PARTICIPANT);
@ -52,14 +45,16 @@ function quitTeam()
$user_id = $user->getId();
$role = $user->getRole();
if ($role == Role::ADMIN || $role == Role::ORGANIZER)
if ($role == Role::ADMIN)
return;
for ($i = 1; $i <= ($role == Role::ENCADRANT ? 2 : 6); ++$i)
/** @noinspection SqlResolve */
$DB->exec("UPDATE `teams` SET `" . strtolower(Role::getName($role)) . "_$i` = NULL WHERE `" . strtolower(Role::getName($role)) . "_$i` = $user_id;");
if ($role == Role::PARTICIPANT)
for ($i = 1; $i <= 6; ++$i)
/** @noinspection SqlResolve */
$DB->exec("UPDATE `teams` SET `participant_$i` = NULL WHERE `participant_$i` = $user_id;");
else
$DB->exec("UPDATE `teams` SET `encadrant` = NULL WHERE `encadrant` = $user_id;");
$user->setTeamId(null);
$DB->exec("UPDATE `teams` SET `encadrant_1` = `encadrant_2`, `encadrant_2` = NULL WHERE `encadrant_1` IS NULL;");
for ($i = 1; $i <= 5; ++$i) {
/** @noinspection SqlResolve */
$DB->exec("UPDATE `teams` SET `participant_$i` = `participant_" . strval($i + 1) . "`, `participant_" . strval($i + 1) . "` = NULL WHERE `participant_$i` IS NULL;");
@ -70,19 +65,6 @@ function quitTeam()
unlink("$URL_BASE/files/" . $data["file_id"]);
$DB->exec("DELETE FROM `documents` WHERE `user` = $user_id;");
if ($DB->exec("DELETE FROM `teams` WHERE `encadrant_1` IS NULL AND `participant_1` IS NULL;") > 0) {
$team_id = $user->getTeamId();
$req = $DB->query("SELECT `file_id` FROM `solutions` WHERE `team` = $team_id;");
while (($data = $req->fetch()) !== false)
unlink("$URL_BASE/files/" . $data["file_id"]);
$DB->exec("DELETE FROM `solutions` WHERE `team` = $team_id;");
$req = $DB->query("SELECT `file_id` FROM `syntheses` WHERE `team` = $team_id;");
while (($data = $req->fetch()) !== false)
unlink("$URL_BASE/files/" . $data["file_id"]);
$DB->exec("DELETE FROM `syntheses` WHERE `team` = $team_id;");
}
$_SESSION["team"] = null;
unset($_SESSION["team"]);
}
@ -114,57 +96,29 @@ function trigramExists($trigram)
return $req->fetch();
}
function tournamentExists($name)
function canValidate(Team $team)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT `id` FROM `tournaments` WHERE `name` = ? AND `year` = '$YEAR';");
$req->execute([$name]);
return $req->fetch();
}
function canValidate(Team $team, Tournament $tournament)
{
global $DB, $YEAR;
global $DB;
$can_validate = $team->getValidationStatus() == ValidationStatus::NOT_READY;
$can_validate &= $team->getEncadrants()[0] != NULL;
$can_validate &= $team->getParticipants()[3] != NULL;
for ($i = 1; $i <= 2; ++$i) {
if ($team->getEncadrants()[$i - 1] === NULL)
continue;
$can_validate &= $team->getEncadrantId() != null;
$can_validate &= $team->getParticipants()[3] != null;
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;");
$req->execute([$team->getEncadrants()[$i - 1], $tournament->getId(), "PHOTO_CONSENT"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;");
$req->execute([$team->getEncadrants()[$i - 1], $tournament->getId(), "SANITARY_PLUG"]);
if ($team->getEncadrantId() != null) {
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;");
$req->execute([$team->getEncadrantId(), $team->getProblem(), "PHOTO_CONSENT"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
}
for ($i = 1; $i <= 6; ++$i) {
if ($team->getParticipants()[$i] === NULL)
continue;
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;");
$req->execute([$team->getParticipants()[$i], $tournament->getId(), "PHOTO_CONSENT"]);
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `problem` = ? AND `type` = ?;");
$req->execute([$team->getParticipants()[$i], $team->getProblem(), "PHOTO_CONSENT"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;");
$req->execute([$team->getParticipants()[$i], $tournament->getId(), "SANITARY_PLUG"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
$birth_date = $DB->query("SELECT `birth_date` FROM `users` WHERE `id` = " . $team->getParticipants()[$i] . ";")->fetch()["birth_date"];
if ($birth_date > strval($YEAR - 18) . substr($tournament->getStartDate(), 4)) {
$req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `user` = ? AND `tournament` = ? AND `type` = ?;");
$req->execute([$team->getParticipants()[$i], $tournament->getId(), "PARENTAL_CONSENT"]);
$d = $req->fetch();
$can_validate &= $d["version"] > 0;
}
}
return $can_validate;
@ -185,11 +139,9 @@ function printDocuments($documents)
}
}
function getZipFile($document_type, $tournament_id, $team_id = -1)
function getZipFile($problem, $team_id = -1)
{
global $LOCAL_PATH;
$tournament = Tournament::fromId($tournament_id);
global $LOCAL_PATH, $DB;
$zip = new ZipArchive();
@ -199,44 +151,16 @@ function getZipFile($document_type, $tournament_id, $team_id = -1)
die("Impossible de créer le fichier zip.");
}
switch ($document_type) {
case DocumentType::SOLUTION:
$data = $tournament->getAllSolutions($team_id);
break;
case DocumentType::SYNTHESIS:
$data = $tournament->getAllSyntheses($team_id);
break;
default:
$data = $tournament->getAllDocuments($team_id);
break;
}
// TODO Replace DB query
$resp = $DB->query("SELECT * FROM `documents` WHERE `problem` = $problem" . ($team_id >= 0 ? " AND `team` = $team_id" : "") . ";");
/** @var Document | Solution | Synthesis $file */
foreach ($data as $file) {
/** @var Document $file */
//foreach ($data as $file) {
while (($data = $resp->fetch()) != false) {
$file = Document::fromData($data);
$file_id = $file->getFileId();
$team = Team::fromId($file->getTeamId());
switch ($document_type) {
case DocumentType::SOLUTION:
$name = "Problème " . $file->getProblem() . " " . $team->getTrigram() . ".pdf";
break;
case DocumentType::SYNTHESIS:
$name = "Note de synthèse " . $team->getTrigram() . " pour " . ($file->getDest() == DestType::OPPOSANT ? "l'opposant" : "le rapporteur") . ".pdf";
break;
default:
$user = User::fromId($file->getUserId());
switch ($file->getType()) {
case DocumentType::PARENTAL_CONSENT:
$name = "Autorisation parentale de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
break;
case DocumentType::PHOTO_CONSENT:
$name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
break;
default:
$name = "Fiche sanitaire de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
break;
}
break;
}
$user = User::fromId($file->getUserId());
$name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf";
$zip->addFile("$LOCAL_PATH/files/$file_id", $name);
}