1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-25 13:37:25 +02:00

Fichier "Mon équipe"

This commit is contained in:
galaxyoyo
2019-09-09 23:28:03 +02:00
parent fac2b29f4a
commit fffdaabe7c
4 changed files with 171 additions and 136 deletions

View File

@ -2,7 +2,8 @@
$FINAL = Tournament::getFinalTournament();
function loadUserValues() {
function loadUserValues()
{
$_SESSION["user"] = $_SESSION["team"] = $_SESSION["tournament"] = null;
unset($_SESSION["user"]);
unset($_SESSION["role"]);
@ -44,7 +45,8 @@ function loadUserValues() {
}
}
function quitTeam() {
function quitTeam()
{
global $DB, $URL_BASE;
header("Location: $URL_BASE");
@ -89,7 +91,8 @@ function quitTeam() {
unset($_SESSION["team"]);
}
function userExists($email) {
function userExists($email)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT `id` FROM `users` WHERE `email` = ? AND `year` = '$YEAR';");
@ -97,7 +100,8 @@ function userExists($email) {
return $req->fetch();
}
function teamExists($name) {
function teamExists($name)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT `id` FROM `teams` WHERE `name` = ? AND `year` = '$YEAR';");
@ -105,7 +109,8 @@ function teamExists($name) {
return $req->fetch();
}
function trigramExists($trigram) {
function trigramExists($trigram)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT `id` FROM `teams` WHERE `trigram` = ? AND `year` = '$YEAR';");
@ -113,7 +118,8 @@ function trigramExists($trigram) {
return $req->fetch();
}
function tournamentExists($name) {
function tournamentExists($name)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT `id` FROM `tournaments` WHERE `name` = ? AND `year` = '$YEAR';");
@ -121,7 +127,55 @@ function tournamentExists($name) {
return $req->fetch();
}
function printDocuments($documents) {
function canValidate(Team $team, Tournament $tournament)
{
global $DB, $YEAR;
$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;
$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"]);
$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"]);
$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;
}
function printDocuments($documents)
{
global $URL_BASE;
foreach ($documents as $document) {
@ -135,7 +189,8 @@ function printDocuments($documents) {
}
}
function getZipFile($document_type, $tournament_id, $team_id = -1) {
function getZipFile($document_type, $tournament_id, $team_id = -1)
{
global $LOCAL_PATH;
$tournament = Tournament::fromId($tournament_id);