From 7d6e899f761b2830ad088341f04cd5cd8da9fee2 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 18 Jan 2020 14:43:42 +0100 Subject: [PATCH] Support des lettres de motivation --- server_files/classes/Document.php | 7 ++++++ server_files/classes/User.php | 11 +++++++++ server_files/controllers/mon_compte.php | 3 ++- server_files/controllers/view_file.php | 16 ++++++++---- server_files/model.php | 28 ++++++++++++++++++--- server_files/views/mon_compte.php | 1 + server_files/views/mon_equipe.php | 2 +- server_files/views/paiement.php | 33 ++++++++++++++++++++++--- 8 files changed, 87 insertions(+), 14 deletions(-) diff --git a/server_files/classes/Document.php b/server_files/classes/Document.php index 76622e9..47897be 100644 --- a/server_files/classes/Document.php +++ b/server_files/classes/Document.php @@ -271,6 +271,7 @@ class DocumentType const SOLUTION = 3; const SYNTHESIS = 4; const SCHOLARSHIP = 5; + const MOTIVATION_LETTER = 6; public static function getTranslatedName($type) { switch ($type) { @@ -282,6 +283,8 @@ class DocumentType return "Fiche sanitaire"; case self::SCHOLARSHIP: return "Notification de bourse"; + case self::MOTIVATION_LETTER: + return "Lettre de motivation"; case self::SOLUTION: return "Solution"; default: @@ -299,6 +302,8 @@ class DocumentType return "SANITARY_PLUG"; case self::SCHOLARSHIP: return "SCHOLARSHIP"; + case self::MOTIVATION_LETTER: + return "MOTIVATION_LETTER"; case self::SOLUTION: return "SOLUTION"; default: @@ -316,6 +321,8 @@ class DocumentType return self::SANITARY_PLUG; case "SCHOLARSHIP": return self::SCHOLARSHIP; + case "MOTIVATION_LETTER": + return self::MOTIVATION_LETTER; case "SOLUTION": return self::SOLUTION; default: diff --git a/server_files/classes/User.php b/server_files/classes/User.php index 96b310f..161195b 100644 --- a/server_files/classes/User.php +++ b/server_files/classes/User.php @@ -435,6 +435,17 @@ class User while (($data = $req->fetch()) !== false) $docs[] = Document::fromData($data); + if ($this->team_id > 0) { + $req = $DB->query("SELECT * FROM `documents` AS `t1` " + . "INNER JOIN (SELECT `user`, `type`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `documents` GROUP BY `tournament`, `type`, `user`) `t2` " + . "ON `t1`.`user` = `t2`.`user` AND `t1`.`type` = `t2`.`type` AND `t1`.`tournament` = `t2`.`tournament` " + . "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $tournament_id AND `t1`.`team` = $this->team_id " + . "AND `t1`.`type` = 'MOTIVATION_LETTER';"); + + while (($data = $req->fetch()) !== false) + $docs[] = Document::fromData($data); + } + return $docs; } diff --git a/server_files/controllers/mon_compte.php b/server_files/controllers/mon_compte.php index 4f709ca..219ded5 100644 --- a/server_files/controllers/mon_compte.php +++ b/server_files/controllers/mon_compte.php @@ -205,7 +205,8 @@ class SendDocument $req = $DB->prepare("INSERT INTO `documents`(`file_id`, `user`, `team`, `tournament`, `type`) VALUES (?, ?, ?, ?, ?);"); - $req->execute([$id, $_SESSION["user_id"], $_SESSION["team"]->getId(), $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]); + $req->execute([$id, $this->type == DocumentType::getName(DocumentType::MOTIVATION_LETTER) ? -1 : $_SESSION["user_id"], $_SESSION["team"]->getId(), + $_SESSION["team"]->isSelectedForFinal() ? $FINAL->getId() : $_SESSION["team"]->getTournamentId(), $this->type]); } } diff --git a/server_files/controllers/view_file.php b/server_files/controllers/view_file.php index 10d4fe4..f576f9e 100644 --- a/server_files/controllers/view_file.php +++ b/server_files/controllers/view_file.php @@ -48,11 +48,11 @@ if ($file !== null) { $user = User::fromId($file->getUserId()); $type = $file->getType(); - if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT) && $user->getId() != $_SESSION["user_id"]) - require_once "server_files/403.php"; + if (($_SESSION["role"] == Role::PARTICIPANT || $_SESSION["role"] == Role::ENCADRANT)) { + if ($type != DocumentType::MOTIVATION_LETTER && $user->getId() != $_SESSION["user_id"] || $file->getTeamId() != $team->getId()) + require_once "server_files/403.php"; + } - $surname = $user->getSurname(); - $first_name = $user->getFirstName(); switch ($type) { case DocumentType::PARENTAL_CONSENT: $name = "Autorisation parentale"; @@ -67,7 +67,13 @@ if ($file !== null) { $name = "Notification de bourse"; break; } - $name .= " de $first_name $surname.pdf"; + if ($type == DocumentType::MOTIVATION_LETTER) + $name = "Lettre de motivation de l'équipe $trigram.pdf"; + else { + $surname = $user->getSurname(); + $first_name = $user->getFirstName(); + $name .= " de $first_name $surname.pdf"; + } } } else diff --git a/server_files/model.php b/server_files/model.php index d4122d1..8e94f4f 100644 --- a/server_files/model.php +++ b/server_files/model.php @@ -136,6 +136,7 @@ function canValidate(Team $team, Tournament $tournament) $d = $req->fetch(); $can_validate &= $d["version"] > 0; } + for ($i = 1; $i <= 6; ++$i) { if ($team->getParticipants()[$i] === NULL) continue; @@ -159,6 +160,11 @@ function canValidate(Team $team, Tournament $tournament) } } + $req = $DB->prepare("SELECT COUNT(*) AS `version` FROM `documents` WHERE `team` = ? AND `tournament` = ? AND `type` = ?;"); + $req->execute([$team->getId(), $tournament->getId(), "MOTIVATION_LETTER"]); + $d = $req->fetch(); + $can_validate &= $d["version"] > 0; + return $can_validate; } @@ -172,12 +178,20 @@ function printDocuments($documents) echo "
\n"; foreach ($documents as $document) { $file_id = $document->getFileId(); - $user = User::fromId($document->getUserId()); - $surname = $user->getSurname(); - $first_name = $user->getFirstName(); $name = DocumentType::getTranslatedName($document->getType()); $version = $document->getVersion(); - echo "$name de $first_name $surname (version $version) : Télécharger
\n"; + if ($document->getType() == DocumentType::MOTIVATION_LETTER) { + $team = Team::fromId($document->getTeamId()); + echo "Lettre de motivation de l'équipe " . $team->getTrigram(); + } + else { + $user = User::fromId($document->getUserId()); + $surname = $user->getSurname(); + $first_name = $user->getFirstName(); + echo "$name de $first_name $surname"; + } + + echo " (version $version) : Télécharger
\n"; } echo "
\n"; } @@ -228,6 +242,12 @@ function getZipFile($document_type, $tournament_id, $team_id = -1) case DocumentType::PHOTO_CONSENT: $name = "Autorisation de droit à l'image de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; break; + case DocumentType::SCHOLARSHIP: + $name = "Notification de bourse de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; + break; + case DocumentType::MOTIVATION_LETTER: + $name = "Lettre de motivation de l'équipe " . $team->getTrigram() . ".pdf"; + break; default: $name = "Fiche sanitaire de " . $user->getFirstName() . " " . $user->getSurname() . ".pdf"; break; diff --git a/server_files/views/mon_compte.php b/server_files/views/mon_compte.php index aa70979..a574578 100644 --- a/server_files/views/mon_compte.php +++ b/server_files/views/mon_compte.php @@ -227,6 +227,7 @@ if (!$has_error && (isset($my_account) || isset($new_password))) { + diff --git a/server_files/views/mon_equipe.php b/server_files/views/mon_equipe.php index 037df24..95f2b65 100644 --- a/server_files/views/mon_equipe.php +++ b/server_files/views/mon_equipe.php @@ -115,7 +115,7 @@ require_once "header.php";
Pour demander à valider votre équipe, vous devez avoir au moins un encadrant, quatre participants, choisi un problème et soumis une autorisation de droit à l'image, une fiche sanitaire et une autorisation - parentale (si besoin) par participant. + parentale (si besoin) par participant, ainsi qu'une lettre de motivation à transmettre aux organisateurs.
getValidationStatus() == ValidationStatus::NOT_READY) { ?>
- getValidationStatus() == ValidationStatus::NOT_READY) { ?> - + - +
+ + getValidationStatus() == ValidationStatus::WAITING) { ?>
@@ -62,6 +88,7 @@ if ($payment->getValidationStatus() == ValidationStatus::NOT_READY) { ?> Informations sur le paiement : getTransactionInfos() ?>
+