From 54fc6fd395e8971f8614bcdb3291d91a697a5468 Mon Sep 17 00:00:00 2001 From: Yohann Date: Fri, 18 Oct 2019 22:23:00 +0200 Subject: [PATCH] =?UTF-8?q?Export=20des=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dispatcher.php | 1 + server_files/classes/SchoolClass.php | 12 +- server_files/controllers/exporter_donnees.php | 42 ++++++ server_files/model.php | 124 ++++++++++++++++++ server_files/views/equipe.php | 107 +++++++-------- server_files/views/exporter_donnees.php | 29 ++++ server_files/views/header.php | 5 +- 7 files changed, 264 insertions(+), 56 deletions(-) create mode 100644 server_files/controllers/exporter_donnees.php create mode 100644 server_files/views/exporter_donnees.php diff --git a/dispatcher.php b/dispatcher.php index 9284f20..11f91ce 100644 --- a/dispatcher.php +++ b/dispatcher.php @@ -42,6 +42,7 @@ $ROUTES["^connexion/?$"] = ["server_files/controllers/connexion.php"]; $ROUTES["^deconnexion/?$"] = ["server_files/controllers/deconnexion.php"]; $ROUTES["^envoyer-video-1$"] = ["server_files/controllers/envoyer_video.php"]; $ROUTES["^equipe/([A-Z]{3})/?$"] = ["server_files/controllers/equipe.php", "trigram"]; +$ROUTES["^exporter-donnees/?$"] = ["server_files/controllers/exporter_donnees.php"]; $ROUTES["^file/([a-z0-9]{64})/?$"] = ["server_files/controllers/view_file.php", "file_id"]; $ROUTES["^informations/([0-9]*)/.*?$"] = ["server_files/controllers/informations.php", "id"]; $ROUTES["^inscription/?$"] = ["server_files/controllers/inscription.php"]; diff --git a/server_files/classes/SchoolClass.php b/server_files/classes/SchoolClass.php index cde1604..7159047 100644 --- a/server_files/classes/SchoolClass.php +++ b/server_files/classes/SchoolClass.php @@ -8,22 +8,26 @@ class SchoolClass public static function getTranslatedName($class) { switch ($class) { + case null: + return "Adulte"; case self::SECONDE: return "Seconde ou inférieur"; case self::PREMIERE: return "Première"; - default: + case self::TERMINALE: return "Terminale"; } } public static function getName($class) { switch ($class) { + case null: + return null; case self::SECONDE: return "SECONDE"; case self::PREMIERE: return "PREMIERE"; - default: + case self::TERMINALE: return "TERMINALE"; } } @@ -34,8 +38,10 @@ class SchoolClass return self::SECONDE; case "PREMIERE": return self::PREMIERE; - default: + case "TERMINALE": return self::TERMINALE; + default: + return null; } } } \ No newline at end of file diff --git a/server_files/controllers/exporter_donnees.php b/server_files/controllers/exporter_donnees.php new file mode 100644 index 0000000..736cb09 --- /dev/null +++ b/server_files/controllers/exporter_donnees.php @@ -0,0 +1,42 @@ +query("SELECT `id` FROM `users` WHERE `year` = $YEAR;"); + while (($data = $req->fetch()) !== false) { + $user = User::fromId($data["id"]); + + $csv .= $user->getId() . ","; + $csv .= $user->getSurname() . ","; + $csv .= $user->getFirstName() . ","; + $csv .= $user->getEmail() . ","; + $csv .= $user->getSchool() . ","; + $csv .= $user->getCity() . ","; + $csv .= $user->getCountry() . ","; + $csv .= SchoolClass::getTranslatedName($user->getClass()) . ","; + $csv .= $user->getDescription() . ","; + $csv .= Role::getTranslatedName($user->getRole()) . ","; + $csv .= ($user->getTeamId() == null ? "" : Team::fromId($user->getTeamId())->getTrigram()) . ","; + $csv .= ($user->doReceiveAnimathMails() ? "oui" : "non") . ","; + $csv .= $user->getInscriptionDate() . "\n"; + } + file_put_contents($file_name, $csv, FILE_APPEND); + + return $file_name; +} + +function exportTeamData() { + global $DB, $YEAR; + + $file_name = tempnam("tmp", "corres2math-"); + + $csv = "Identifiant,Nom,Trigramme,Problème,Encadrant,Participant 1,Participant 2,Participant 3,Participant 4,Participant 5," + . "Date d'inscription,Autorise la publication,État de validation,Code d'accès\n"; + + $req = $DB->query("SELECT `id` FROM `teams` WHERE `year` = $YEAR ORDER BY `problem`;"); + while (($data = $req->fetch()) !== false) { + $team = Team::fromId($data["id"]); + + $csv .= $team->getId() . ","; + $csv .= $team->getName() . ","; + $csv .= $team->getTrigram() . ","; + $csv .= $team->getProblem() . ","; + $csv .= $team->getEncadrantId() . ","; + $csv .= $team->getParticipants()[0] . ","; + $csv .= $team->getParticipants()[1] . ","; + $csv .= $team->getParticipants()[2] . ","; + $csv .= $team->getParticipants()[3] . ","; + $csv .= $team->getParticipants()[4] . ","; + $csv .= $team->getInscriptionDate() . ","; + $csv .= $team->allowPublish() . ","; + $csv .= ValidationStatus::getTranslatedName($team->getValidationStatus()) . ","; + $csv .= $team->getAccessCode() . "\n"; + } + file_put_contents($file_name, $csv, FILE_APPEND); + + return $file_name; +} + +function exportProblemsData() { + global $DB, $URL_BASE, $YEAR; + + $file_name = tempnam("tmp", "corres2math-"); + + $csv = "Équipe,Problème,Lien,Équipe 1 ayant reçu la vidéo," + . "Question 1,Pièce jointe,Réponse,Pièce jointe," + . "Question 2,Pièce jointe,Réponse,Pièce jointe," + . "Question 3,Pièce jointe,Réponse,Pièce jointe," + . "Question 4,Pièce jointe,Réponse,Pièce jointe," + . "Question 5,Pièce jointe,Réponse,Pièce jointe," + . "Question 6,Pièce jointe,Réponse,Pièce jointe," + . "Vidéo de réponse," + . "Équipe 2 ayant reçu la vidéo," + . "Question 1,Pièce jointe,Réponse,Pièce jointe," + . "Question 2,Pièce jointe,Réponse,Pièce jointe," + . "Question 3,Pièce jointe,Réponse,Pièce jointe," + . "Question 4,Pièce jointe,Réponse,Pièce jointe," + . "Question 5,Pièce jointe,Réponse,Pièce jointe," + . "Question 6,Pièce jointe,Réponse,Pièce jointe," + . "Vidéo de réponse\n"; + + $req = $DB->query("SELECT `id` FROM `teams` WHERE `validation_status` = 'VALIDATED' AND `year` = $YEAR ORDER BY `problem`;"); + while (($data = $req->fetch()) !== false) { + $team = Team::fromId($data["id"]); + $video = Video::getVideo(Reason::SOLUTION, $team); + $questions_received = Question::getQuestionsTo($team); + + $csv .= $team->getTrigram() . ","; + $csv .= $team->getProblem() . ","; + $csv .= ($video == null ? "" : $video->getLink()) . ","; + for ($i = 0; $i < 2; ++$i) { + /** @var Question[] $questions */ + $questions = $questions_received[$i]; + $asker = Team::fromId($questions[0]->getFrom()); + $csv .= $asker->getTrigram() . ","; + + for ($j = 0; $j < 6; ++$j) { + $question = $questions[$j]; + + if ($question == null) { + $csv .= ",,,,"; + continue; + } + + $csv .= $question->getQuestion() . ","; + $csv .= ($question->getAttachedFile() == null ? "" : $URL_BASE . "/file/" . $question->getAttachedFile()) . ','; + $csv .= $question->getAnswer() . ","; + $csv .= ($question->getAttachedFileAnswer() == null ? "" : $URL_BASE . "/file/" . $question->getAttachedFileAnswer()) . ','; + } + + $answer = Video::getVideo($asker->getVideoTeamIds()[0] == $team->getId() ? Reason::ANSWER1 : Reason::ANSWER2, + $asker, Video::ACCEPTED); + $csv .= $answer == null ? "" : $answer->getLink(); + $csv .= ($i == 0 ? "," : "\n"); + } + } + file_put_contents($file_name, $csv, FILE_APPEND); + + return $file_name; +} + function displayVideo($link) { if (preg_match("#(https?\://|)(www\.|)youtube\.com\/watch\?v=(.*)#", $link, $matches)) { diff --git a/server_files/views/equipe.php b/server_files/views/equipe.php index 52ecad8..79e7bb5 100644 --- a/server_files/views/equipe.php +++ b/server_files/views/equipe.php @@ -18,7 +18,8 @@ - + @@ -33,60 +34,61 @@ : getValidationStatus()) ?>
- getEncadrantId() !== null) { - $encadrant = User::fromId($team->getEncadrantId()); - $id = $encadrant->getId(); - echo "Encadrant : getFirstName() . " " . $encadrant->getSurname() . "\">" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "
"; - } - for ($i = 1; $i <= 5; ++$i) { - if ($team->getParticipants()[$i - 1] == NULL) - continue; - $participant = User::fromId($team->getParticipants()[$i - 1]); - $id = $participant->getId(); - echo "Participant $i : getFirstName() . " " . $participant->getSurname() . "\">" . $participant->getFirstName() . " " . $participant->getSurname() . "
"; - } - ?> + getEncadrantId() !== null) { + $encadrant = User::fromId($team->getEncadrantId()); + $id = $encadrant->getId(); + echo "Encadrant : getFirstName() . " " . $encadrant->getSurname() . "\">" . $encadrant->getFirstName() . " " . $encadrant->getSurname() . "
"; + } + for ($i = 1; $i <= 5; ++$i) { + if ($team->getParticipants()[$i - 1] == NULL) + continue; + $participant = User::fromId($team->getParticipants()[$i - 1]); + $id = $participant->getId(); + echo "Participant $i : getFirstName() . " " . $participant->getSurname() . "\">" . $participant->getFirstName() . " " . $participant->getSurname() . "
"; + } + ?>
Autorise Animath à diffuser les vidéos : allowPublish() ? "oui" : "non" ?>
- - getValidationStatus() == ValidationStatus::VALIDATED) { ?> -
- -
-
-
-
- - = Phase::PHASE2 ? "disabled" : "" ?>> + getId() == $team->getId()) + continue; - $team_name = $other_team->getName() . " (" . $other_team->getTrigram() . ")"; - $team_id = $other_team->getId(); - echo "\n"; - } - ?> - -
+ $team_name = $other_team->getName() . " (" . $other_team->getTrigram() . ")"; + $team_id = $other_team->getId(); + echo "\n"; + } + ?> +
-
- - - -
-
- + +
+ + + +
+
@@ -100,7 +102,7 @@ if ($_SESSION["role"] == Role::ADMIN) { ?> value="Télécharger l'archive"/> -getValidationStatus() == ValidationStatus::WAITING && $_SESSION["role"] == Role::ADMIN) { ?> +getValidationStatus() == ValidationStatus::WAITING) { ?>
@@ -111,11 +113,12 @@ if ($_SESSION["role"] == Role::ADMIN) { ?>
- getValidationStatus() == ValidationStatus::NOT_READY && $_SESSION["role"] == Role::ADMIN) { ?> + getValidationStatus() == ValidationStatus::NOT_READY) { ?>
- +
+ +
+

Exporter les données

+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +