mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-25 22:17:25 +02:00
Export des données
This commit is contained in:
@ -151,6 +151,130 @@ function getZipFile($problem, $team_id = -1)
|
||||
return $file_name;
|
||||
}
|
||||
|
||||
function exportUserData() {
|
||||
global $DB, $YEAR;
|
||||
|
||||
$file_name = tempnam("tmp", "corres2math-");
|
||||
|
||||
$csv = "Identifiant,Nom,Prénom,E-mail,École,Ville,Pays,Classe,Description,Rôle,Équipe,Autorise l'envoi de mails,Date d'inscription\n";
|
||||
|
||||
$req = $DB->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)) {
|
||||
|
Reference in New Issue
Block a user