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

Copie du site du TFJM² à adapter aux Correspondances

This commit is contained in:
galaxyoyo
2019-09-10 01:48:52 +02:00
commit fa5202fe4f
77 changed files with 5620 additions and 0 deletions

View File

@ -0,0 +1,318 @@
<?php
class Document
{
private $file_id;
private $user_id;
private $team_id;
private $tournament_id;
private $type;
private $uploaded_at;
private $version;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `documents` WHERE `file_id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
return self::fromData($data);
}
public static function fromData($data)
{
$doc = new Document();
$doc->fill($data);
return $doc;
}
private function fill($data)
{
$this->file_id = $data["file_id"];
$this->user_id = $data["user"];
$this->team_id = $data["team"];
$this->tournament_id = $data["tournament"];
$this->type = DocumentType::fromName($data["type"]);
$this->uploaded_at = $data["uploaded_at"];
$this->version = isset($data["version"]) ? $data["version"] : 1;
}
public function getFileId()
{
return $this->file_id;
}
public function getUserId()
{
return $this->user_id;
}
public function getTeamId()
{
return $this->team_id;
}
public function getTournamentId()
{
return $this->tournament_id;
}
public function getType()
{
return $this->type;
}
public function getUploadedAt()
{
return $this->uploaded_at;
}
public function getVersion()
{
return $this->version;
}
}
class Solution
{
private $file_id;
private $team_id;
private $tournament_id;
private $problem;
private $uploaded_at;
private $version;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `solutions` WHERE `file_id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
return self::fromData($data);
}
public static function fromData($data)
{
$sol = new Solution();
$sol->fill($data);
return $sol;
}
private function fill($data)
{
$this->file_id = $data["file_id"];
$this->team_id = $data["team"];
$this->tournament_id = $data["tournament"];
$this->problem = $data["problem"];
$this->uploaded_at = $data["uploaded_at"];
$this->version = isset($data["version"]) ? $data["version"] : 1;
}
public function getFileId()
{
return $this->file_id;
}
public function getTeamId()
{
return $this->team_id;
}
public function getTournamentId()
{
return $this->tournament_id;
}
public function getProblem()
{
return $this->problem;
}
public function getUploadedAt()
{
return $this->uploaded_at;
}
public function getVersion()
{
return $this->version;
}
}
class Synthesis
{
private $file_id;
private $team_id;
private $tournament_id;
private $dest;
private $uploaded_at;
private $version;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `syntheses` WHERE `file_id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
return self::fromData($data);
}
public static function fromData($data)
{
$synthese = new Synthesis();
$synthese->fill($data);
return $synthese;
}
private function fill($data)
{
$this->file_id = $data["file_id"];
$this->team_id = $data["team"];
$this->tournament_id = $data["tournament"];
$this->dest = DestType::fromName($data["dest"]);
$this->uploaded_at = $data["uploaded_at"];
$this->version = isset($data["version"]) ? $data["version"] : 1;
}
public function getFileId()
{
return $this->file_id;
}
public function getTeamId()
{
return $this->team_id;
}
public function getTournamentId()
{
return $this->tournament_id;
}
public function getDest()
{
return $this->dest;
}
public function getUploadedAt()
{
return $this->uploaded_at;
}
public function getVersion()
{
return $this->version;
}
}
class DestType
{
const DEFENSEUR = 0;
const OPPOSANT = 1;
const RAPPORTEUR = 2;
public static function getTranslatedName($status) {
switch ($status) {
case self::OPPOSANT:
return "Opposant";
case self::RAPPORTEUR:
return "Rapporteur";
default:
return "Défenseur";
}
}
public static function getName($status) {
switch ($status) {
case self::OPPOSANT:
return "OPPOSANT";
case self::RAPPORTEUR:
return "RAPPORTEUR";
default:
return "DEFENSEUR";
}
}
public static function fromName($name) {
switch ($name) {
case "OPPOSANT":
return self::OPPOSANT;
case "RAPPORTEUR":
return self::RAPPORTEUR;
default:
return self::DEFENSEUR;
}
}
}
class DocumentType
{
const PARENTAL_CONSENT = 0;
const PHOTO_CONSENT = 1;
const SANITARY_PLUG = 2;
const SOLUTION = 3;
const SYNTHESIS = 4;
public static function getTranslatedName($type) {
switch ($type) {
case self::PARENTAL_CONSENT:
return "Autorisation parentale";
case self::PHOTO_CONSENT:
return "Autorisation de droit à l'image";
case self::SANITARY_PLUG:
return "Fiche sanitaire";
case self::SOLUTION:
return "Solution";
default:
return "Note de synthèse";
}
}
public static function getName($type) {
switch ($type) {
case self::PARENTAL_CONSENT:
return "PARENTAL_CONSENT";
case self::PHOTO_CONSENT:
return "PHOTO_CONSENT";
case self::SANITARY_PLUG:
return "SANITARY_PLUG";
case self::SOLUTION:
return "SOLUTION";
default:
return "SYNTHESIS";
}
}
public static function fromName($name) {
switch ($name) {
case "PARENTAL_CONSENT":
return self::PARENTAL_CONSENT;
case "PHOTO_CONSENT":
return self::PHOTO_CONSENT;
case "SANITARY_PLUG":
return self::SANITARY_PLUG;
case "SOLUTION":
return self::SOLUTION;
default:
return self::SYNTHESIS;
}
}
}

View File

@ -0,0 +1,48 @@
<?php
class Role
{
const PARTICIPANT = 0;
const ENCADRANT = 1;
const ORGANIZER = 2;
const ADMIN = 3;
public static function getTranslatedName($role) {
switch ($role) {
case self::ENCADRANT:
return "Encadrant";
case self::ORGANIZER:
return "Organisateur";
case self::ADMIN:
return "Administrateur";
default:
return "Participant";
}
}
public static function getName($role) {
switch ($role) {
case self::ENCADRANT:
return "ENCADRANT";
case self::ORGANIZER:
return "ORGANIZER";
case self::ADMIN:
return "ADMIN";
default:
return "PARTICIPANT";
}
}
public static function fromName($name) {
switch ($name) {
case "ENCADRANT":
return self::ENCADRANT;
case "ORGANIZER":
return self::ORGANIZER;
case "ADMIN":
return self::ADMIN;
default:
return self::PARTICIPANT;
}
}
}

View File

@ -0,0 +1,41 @@
<?php
class SchoolClass
{
const SECONDE = 0;
const PREMIERE = 1;
const TERMINALE = 2;
public static function getTranslatedName($class) {
switch ($class) {
case self::SECONDE:
return "Seconde ou inférieur";
case self::PREMIERE:
return "Première";
default:
return "Terminale";
}
}
public static function getName($class) {
switch ($class) {
case self::SECONDE:
return "SECONDE";
case self::PREMIERE:
return "PREMIERE";
default:
return "TERMINALE";
}
}
public static function fromName($name) {
switch ($name) {
case "SECONDE":
return self::SECONDE;
case "PREMIERE":
return self::PREMIERE;
default:
return self::TERMINALE;
}
}
}

View File

@ -0,0 +1,185 @@
<?php
class Team
{
private $id;
private $name;
private $trigram;
private $tournament;
private $encadrants;
private $participants;
private $inscription_date;
private $validation_status;
private $final_selection;
private $access_code;
private $year;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `teams` WHERE `id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
$team = new Team();
$team->fill($data);
return $team;
}
public static function fromTrigram($trigram)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT * FROM `teams` WHERE `trigram` = ? AND `year` = $YEAR;");
$req->execute([htmlspecialchars($trigram)]);
$data = $req->fetch();
if ($data === false)
return null;
$team = new Team();
$team->fill($data);
return $team;
}
public static function fromAccessCode($access_code)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT * FROM `teams` WHERE `access_code` = ? AND `year` = $YEAR;");
$req->execute([htmlspecialchars($access_code)]);
$data = $req->fetch();
if ($data === false)
return null;
$team = new Team();
$team->fill($data);
return $team;
}
private function fill($data)
{
$this->id = $data["id"];
$this->name = $data["name"];
$this->trigram = $data["trigram"];
$this->tournament = $data["tournament"];
$this->encadrants = [$data["encadrant_1"], $data["encadrant_2"]];
$this->participants = [$data["participant_1"], $data["participant_2"], $data["participant_3"], $data["participant_4"], $data["participant_5"], $data["participant_6"]];
$this->inscription_date = $data["inscription_date"];
$this->validation_status = ValidationStatus::fromName($data["validation_status"]);
$this->final_selection = $data["final_selection"] == true;
$this->access_code = $data["access_code"];
$this->year = $data["year"];
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
global $DB;
$this->name = $name;
$DB->prepare("UPDATE `teams` SET `name` = ? WHERE `id` = ?;")->execute([$name, $this->id]);
}
public function getTrigram()
{
return $this->trigram;
}
public function setTrigram($trigram)
{
global $DB;
$this->trigram = $trigram;
$DB->prepare("UPDATE `teams` SET `trigram` = ? WHERE `id` = ?;")->execute([$trigram, $this->id]);
}
public function getTournamentId()
{
return $this->tournament;
}
public function setTournamentId($tournament)
{
global $DB;
$this->tournament = $tournament;
$DB->prepare("UPDATE `teams` SET `tournament` = ? WHERE `id` = ?;")->execute([$tournament, $this->id]);
}
public function getEncadrants()
{
return $this->encadrants;
}
public function setEncadrant($i, $encadrant)
{
global $DB;
$this->encadrants[$i - 1] = $encadrant;
/** @noinspection SqlResolve */
$DB->prepare("UPDATE `teams` SET `encadrant_$i` = ? WHERE `id` = ?;")->execute([$encadrant, $this->id]);
}
public function getParticipants()
{
return $this->participants;
}
public function setParticipant($i, $participant)
{
global $DB;
$this->participants[$i - 1] = $participant;
/** @noinspection SqlResolve */
$DB->prepare("UPDATE `teams` SET `participant_$i` = ? WHERE `id` = ?;")->execute([$participant, $this->id]);
}
public function getInscriptionDate()
{
return $this->inscription_date;
}
public function getValidationStatus()
{
return $this->validation_status;
}
public function setValidationStatus($status)
{
global $DB;
$this->validation_status = $status;
/** @noinspection PhpUndefinedMethodInspection */
$DB->prepare("UPDATE `teams` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($status), $this->id]);
}
public function isSelectedForFinal()
{
return $this->final_selection;
}
public function selectForFinal($selected)
{
global $DB;
$this->final_selection = $selected;
$DB->prepare("UPDATE `teams` SET `final_selection` = ? WHERE `id` = ?;")->execute([$selected, $this->id]);
}
public function getAccessCode()
{
return $this->access_code;
}
public function getYear()
{
return $this->year;
}
}

View File

@ -0,0 +1,357 @@
<?php
/** @noinspection SqlAggregates */
class Tournament
{
private $id;
private $name;
private $size;
private $place;
private $price;
private $description;
private $date_start, $date_end;
private $date_inscription;
private $date_solutions;
private $date_syntheses;
private $final;
private $organizers = [];
private $year;
private function __construct()
{
}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `tournaments` WHERE `id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
$tournament = new Tournament();
$tournament->fill($data);
return $tournament;
}
public static function fromName($name)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT * FROM `tournaments` WHERE `name` = ? AND `year` = $YEAR;");
$req->execute([htmlspecialchars($name)]);
$data = $req->fetch();
if ($data === false)
return null;
$tournament = new Tournament();
$tournament->fill($data);
return $tournament;
}
public static function getFinalTournament()
{
global $DB, $YEAR;
$req = $DB->query("SELECT * FROM `tournaments` WHERE `final` AND `year` = $YEAR;");
$data = $req->fetch();
if ($data === false)
return null;
$tournament = new Tournament();
$tournament->fill($data);
return $tournament;
}
public static function getAllTournaments($include_final = true, $only_future = false)
{
global $DB, $YEAR;
$sql = "SELECT * FROM `tournaments` WHERE ";
if (!$include_final)
$sql .= "`final` = 0 AND ";
if ($only_future)
$sql .= "`date_start` > CURRENT_DATE AND ";
$sql .= "`year` = $YEAR ORDER BY `date_start`, `name`;";
$req = $DB->query($sql);
$tournaments = [];
while (($data = $req->fetch()) !== false) {
$tournament = new Tournament();
$tournament->fill($data);
$tournaments[] = $tournament;
}
return $tournaments;
}
private function fill($data)
{
$this->id = $data["id"];
$this->name = $data["name"];
$this->size = $data["size"];
$this->place = $data["place"];
$this->price = $data["price"];
$this->description = $data["description"];
$this->date_start = $data["date_start"];
$this->date_end = $data["date_end"];
$this->date_inscription = $data["date_inscription"];
$this->date_solutions = $data["date_solutions"];
$this->date_syntheses = $data["date_syntheses"];
$this->final = $data["final"] == true;
$this->year = $data["year"];
global $DB;
$req = $DB->prepare("SELECT `organizer` FROM `organizers` WHERE `tournament` = ?;");
$req->execute([$this->id]);
while (($data = $req->fetch()) !== false)
$this->organizers[] = User::fromId($data["organizer"]);
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
global $DB;
$this->name = $name;
$DB->prepare("UPDATE `tournaments` SET `name` = ? WHERE `id` = ?;")->execute([$name, $this->id]);
}
public function getSize()
{
return $this->size;
}
public function setSize($size)
{
global $DB;
$this->size = $size;
$DB->prepare("UPDATE `tournaments` SET `size` = ? WHERE `id` = ?;")->execute([$size, $this->id]);
}
public function getPlace()
{
return $this->place;
}
public function setPlace($place)
{
global $DB;
$this->place = $place;
$DB->prepare("UPDATE `tournaments` SET `place` = ? WHERE `id` = ?;")->execute([$place, $this->id]);
}
public function getPrice()
{
return $this->price;
}
public function setPrice($price)
{
global $DB;
$this->price = $price;
$DB->prepare("UPDATE `tournaments` SET `price` = ? WHERE `id` = ?;")->execute([$price, $this->id]);
}
public function getDescription()
{
return $this->description;
}
public function setDescription($desc)
{
global $DB;
$this->description = $desc;
$DB->prepare("UPDATE `tournaments` SET `description` = ? WHERE `id` = ?;")->execute([$desc, $this->id]);
}
public function getStartDate()
{
return $this->date_start;
}
public function setStartDate($date)
{
global $DB;
$this->date_start = $date;
$DB->prepare("UPDATE `tournaments` SET `date_start` = ? WHERE `id` = ?;")->execute([$date, $this->id]);
}
public function getEndDate()
{
return $this->date_end;
}
public function setEndDate($date)
{
global $DB;
$this->date_end = $date;
$DB->prepare("UPDATE `tournaments` SET `date_end` = ? WHERE `id` = ?;")->execute([$date, $this->id]);
}
public function getInscriptionDate()
{
return $this->date_inscription;
}
public function setInscriptionDate($date)
{
global $DB;
$this->date_inscription = $date;
$DB->prepare("UPDATE `tournaments` SET `date_inscription` = ? WHERE `id` = ?;")->execute([$date, $this->id]);
}
public function getSolutionsDate()
{
return $this->date_solutions;
}
public function setSolutionsDate($date)
{
global $DB;
$this->date_solutions = $date;
$DB->prepare("UPDATE `tournaments` SET `date_solutions` = ? WHERE `id` = ?;")->execute([$date, $this->id]);
}
public function getSynthesesDate()
{
return $this->date_syntheses;
}
public function setSynthesesDate($date)
{
global $DB;
$this->date_syntheses = $date;
$DB->prepare("UPDATE `tournaments` SET `date_syntheses` = ? WHERE `id` = ?;")->execute([$date, $this->id]);
}
public function isFinal()
{
return $this->final;
}
public function setFinal($final)
{
global $DB;
$this->final = $final;
$DB->prepare("UPDATE `tournaments` SET `final` = ? WHERE `id` = ?;")->execute([$final, $this->id]);
}
public function getAllTeams()
{
global $DB, $YEAR;
if ($this->final)
$req = $DB->query("SELECT `id` FROM `teams` WHERE `final_selection` AND `year` = $YEAR;");
else
$req = $DB->query("SELECT `id` FROM `teams` WHERE `tournament` = $this->id AND `year` = $YEAR;");
$teams = [];
while (($data = $req->fetch()) !== false)
$teams[] = Team::fromId($data["id"]);
return $teams;
}
public function getOrganizers()
{
return $this->organizers;
}
public function organize($user_id)
{
foreach ($this->organizers as $organizer) {
if ($organizer->getId() == $user_id)
return true;
}
return false;
}
public function addOrganizer(User $user)
{
global $DB;
$this->organizers[] = $user;
$req = $DB->prepare("INSERT INTO `organizers`(`organizer`, `tournament`) VALUES(?, ?);");
$req->execute([$user->getId(), $this->id]);
}
public function clearOrganizers()
{
global $DB;
$this->organizers = [];
$req = $DB->prepare("DELETE FROM `organizers` WHERE `tournament` = ?;");
$req->execute([$this->id]);
}
public function getYear()
{
return $this->year;
}
public function getAllDocuments($team_id = -1)
{
global $DB;
$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`, `team`, `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` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`type`;");
$docs = [];
while (($data = $req->fetch()) !== false)
$docs[] = Document::fromData($data);
return $docs;
}
public function getAllSolutions($team_id = -1)
{
global $DB;
$req = $DB->query("SELECT * FROM `solutions` AS `t1` "
. "INNER JOIN (SELECT `team`, `problem`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `solutions` GROUP BY `tournament`, `team`, `problem`) `t2` "
. "ON `t1`.`team` = `t2`.`team` AND `t1`.`problem` = `t2`.`problem` AND `t1`.`tournament` = `t2`.`tournament` "
. "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`problem`;");
$sols = [];
while (($data = $req->fetch()) !== false)
$sols[] = Solution::fromData($data);
return $sols;
}
public function getAllSyntheses($team_id = -1)
{
global $DB;
$req = $DB->query("SELECT * FROM `syntheses` AS `t1` "
. "INNER JOIN (SELECT `team`, `dest`, `tournament`, MAX(`uploaded_at`) AS `last_upload`, COUNT(`team`) AS `version` FROM `syntheses` GROUP BY `tournament`, `team`, `dest`) `t2` "
. "ON `t1`.`team` = `t2`.`team` AND `t1`.`dest` = `t2`.`dest` AND `t1`.`tournament` = `t2`.`tournament` "
. "WHERE `t1`.`uploaded_at` = `t2`.`last_upload` AND `t1`.`tournament` = $this->id " . ($team_id == -1 ? "" : "AND `t1`.`team` = $team_id") . " ORDER BY `t1`.`team`, `t1`.`dest`;");
$syntheses = [];
while (($data = $req->fetch()) !== false)
$syntheses[] = Synthesis::fromData($data);
return $syntheses;
}
}

View File

@ -0,0 +1,391 @@
<?php
class User
{
private $id;
public $email;
private $pwd_hash;
public $surname;
public $first_name;
public $birth_date;
public $gender;
public $address;
public $postal_code;
public $city;
public $country;
public $phone_number;
public $school;
public $class;
public $responsible_name;
public $responsible_phone;
public $responsible_email;
public $description;
private $role;
private $team_id;
private $year;
private $confirm_email;
private $forgotten_password;
private $inscription_date;
private function __construct() {}
public static function fromId($id)
{
global $DB;
$req = $DB->prepare("SELECT * FROM `users` WHERE `id` = ?;");
$req->execute([htmlspecialchars($id)]);
$data = $req->fetch();
if ($data === false)
return null;
$user = new User();
$user->fill($data);
return $user;
}
public static function fromEmail($email)
{
global $DB, $YEAR;
$req = $DB->prepare("SELECT * FROM `users` WHERE `email` = ? AND `year` = $YEAR;");
$req->execute([htmlspecialchars($email)]);
$data = $req->fetch();
if ($data === false)
return null;
$user = new User();
$user->fill($data);
return $user;
}
private function fill($data)
{
$this->id = $data["id"];
$this->email = $data["email"];
$this->pwd_hash = $data["pwd_hash"];
$this->surname = $data["surname"];
$this->first_name = $data["first_name"];
$this->birth_date = $data["birth_date"];
$this->gender = $data["gender"];
$this->address = $data["address"];
$this->postal_code = $data["postal_code"];
$this->city = $data["city"];
$this->country = $data["country"];
$this->phone_number = $data["phone_number"];
$this->school = $data["school"];
$this->class = SchoolClass::fromName($data["class"]);
$this->responsible_name = $data["responsible_name"];
$this->responsible_phone = $data["responsible_phone"];
$this->responsible_email = $data["responsible_email"];
$this->description = $data["description"];
$this->role = Role::fromName($data["role"]);
$this->team_id = $data["team_id"];
$this->year = $data["year"];
$this->confirm_email = $data["confirm_email"];
$this->forgotten_password = $data["forgotten_password"];
$this->inscription_date = $data["inscription_date"];
}
public function getEmail()
{
return $this->email;
}
public function setEmail($email)
{
global $DB;
$this->email = $email;
$DB->prepare("UPDATE `users` SET `email` = ? WHERE `id` = ?;")->execute([$email, $this->getId()]);
}
public function getId()
{
return $this->id;
}
public function checkPassword($password)
{
return password_verify($password, $this->pwd_hash);
}
public function setPassword($password)
{
$this->setPasswordHash(password_hash($password, PASSWORD_BCRYPT));
}
private function setPasswordHash($password_hash)
{
global $DB;
$this->pwd_hash = $password_hash;
$DB->prepare("UPDATE `users` SET `pwd_hash` = ? WHERE `id` = ?;")->execute([$password_hash, $this->getId()]);
}
public function getSurname()
{
return $this->surname;
}
public function setSurname($surname)
{
global $DB;
$this->surname = $surname;
$DB->prepare("UPDATE `users` SET `surname` = ? WHERE `id` = ?;")->execute([$surname, $this->getId()]);
}
public function getFirstName()
{
return $this->first_name;
}
public function setFirstName($first_name)
{
global $DB;
$this->first_name = $first_name;
$DB->prepare("UPDATE `users` SET `first_name` = ? WHERE `id` = ?;")->execute([$first_name, $this->getId()]);
}
public function getBirthDate()
{
return $this->birth_date;
}
public function setBirthDate($birth_date)
{
global $DB;
$this->birth_date = $birth_date;
$DB->prepare("UPDATE `users` SET `birth_date` = ? WHERE `id` = ?;")->execute([$birth_date, $this->getId()]);
}
public function getGender()
{
return $this->gender;
}
public function setGender($gender)
{
global $DB;
$this->gender = $gender;
$DB->prepare("UPDATE `users` SET `gender` = ? WHERE `id` = ?;")->execute([$gender, $this->getId()]);
}
public function getAddress()
{
return $this->address;
}
public function setAddress($address)
{
global $DB;
$this->address = $address;
$DB->prepare("UPDATE `users` SET `address` = ? WHERE `id` = ?;")->execute([$address, $this->getId()]);
}
public function getPostalCode()
{
return $this->postal_code;
}
public function setPostalCode($postal_code)
{
global $DB;
$this->postal_code = $postal_code;
$DB->prepare("UPDATE `users` SET `postal_code` = ? WHERE `id` = ?;")->execute([$postal_code, $this->getId()]);
}
public function getCity()
{
return $this->city;
}
public function setCity($city)
{
global $DB;
$this->city = $city;
$DB->prepare("UPDATE `users` SET `city` = ? WHERE `id` = ?;")->execute([$city, $this->getId()]);
}
public function getCountry()
{
return $this->country;
}
public function setCountry($country)
{
global $DB;
$this->country = $country;
$DB->prepare("UPDATE `users` SET `country` = ? WHERE `id` = ?;")->execute([$country, $this->getId()]);
}
public function getPhoneNumber()
{
return $this->phone_number;
}
public function setPhoneNumber($phone_number)
{
global $DB;
$this->phone_number = $phone_number;
$DB->prepare("UPDATE `users` SET `phone_number` = ? WHERE `id` = ?;")->execute([$phone_number, $this->getId()]);
}
public function getSchool()
{
return $this->school;
}
public function setSchool($school)
{
global $DB;
$this->school = $school;
$DB->prepare("UPDATE `users` SET `school` = ? WHERE `id` = ?;")->execute([SchoolClass::getName($school), $this->getId()]);
}
public function getClass()
{
return $this->class;
}
public function setClass($class)
{
global $DB;
$this->class = $class;
$DB->prepare("UPDATE `users` SET `class` = ? WHERE `id` = ?;")->execute([SchoolClass::getName($class), $this->getId()]);
}
public function getResponsibleName()
{
return $this->responsible_name;
}
public function setResponsibleName($responsible_name)
{
global $DB;
$this->responsible_name = $responsible_name;
$DB->prepare("UPDATE `users` SET `responsible_name` = ? WHERE `id` = ?;")->execute([$responsible_name, $this->getId()]);
}
public function getResponsiblePhone()
{
return $this->responsible_phone;
}
public function setResponsiblePhone($responsible_phone)
{
global $DB;
$this->responsible_phone = $responsible_phone;
$DB->prepare("UPDATE `users` SET `responsible_phone` = ? WHERE `id` = ?;")->execute([$responsible_phone, $this->getId()]);
}
public function getResponsibleEmail()
{
return $this->responsible_email;
}
public function setResponsibleEmail($responsible_email)
{
global $DB;
$this->responsible_email = $responsible_email;
$DB->prepare("UPDATE `users` SET `responsible_email` = ? WHERE `id` = ?;")->execute([$responsible_email, $this->getId()]);
}
public function getDescription()
{
return $this->description;
}
public function setDescription($desc)
{
global $DB;
$this->description = $desc;
$DB->prepare("UPDATE `users` SET `description` = ? WHERE `id` = ?;")->execute([$desc, $this->getId()]);
}
public function getRole()
{
return $this->role;
}
public function setRole($role)
{
global $DB;
$this->role = $role;
/** @noinspection PhpUndefinedMethodInspection */
$DB->prepare("UPDATE `users` SET `role` = ? WHERE `id` = ?;")->execute([Role::getName($role), $this->getId()]);
}
public function getTeamId()
{
return $this->team_id;
}
public function setTeamId($team_id)
{
global $DB;
$this->team_id = $team_id;
$DB->prepare("UPDATE `users` SET `team_id` = ? WHERE `id` = ?;")->execute([$team_id, $this->getId()]);
}
public function getYear()
{
return $this->year;
}
public function getConfirmEmailToken()
{
return $this->confirm_email;
}
public function setConfirmEmailToken($token)
{
global $DB;
$this->confirm_email = $token;
$DB->prepare("UPDATE `users` SET `confirm_email` = ? WHERE `id` = ?;")->execute([$token, $this->getId()]);
}
public function getForgottenPasswordToken()
{
return $this->forgotten_password;
}
public function setForgottenPasswordToken($token)
{
global $DB;
$this->forgotten_password = $token;
$DB->prepare("UPDATE `users` SET `forgotten_password` = ? WHERE `id` = ?;")->execute([$token, $this->getId()]);
}
public function getInscriptionDate()
{
return $this->inscription_date;
}
public function getAllDocuments($tournament_id)
{
global $DB;
$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`.`user` = $this->id ORDER BY `t1`.`type`;");
$docs = [];
while (($data = $req->fetch()) !== false)
$docs[] = Document::fromData($data);
return $docs;
}
public function getOrganizedTournaments()
{
global $DB;
$req = $DB->query("SELECT `tournament` FROM `organizers` JOIN `tournaments` ON `tournaments`.`id` = `tournament` WHERE `organizer` = $this->id ORDER BY `date_start`, `name`;");
$tournaments = [];
while (($data = $req->fetch()) !== false)
$tournaments[] = Tournament::fromId($data["tournament"]);
return $tournaments;
}
}

View File

@ -0,0 +1,41 @@
<?php
class ValidationStatus
{
const NOT_READY = 0;
const WAITING = 1;
const VALIDATED = 2;
public static function getTranslatedName($status) {
switch ($status) {
case self::WAITING:
return "En attente de validation";
case self::VALIDATED:
return "Inscription validée";
default:
return "Inscription non terminée";
}
}
public static function getName($status) {
switch ($status) {
case self::WAITING:
return "WAITING";
case self::VALIDATED:
return "VALIDATED";
default:
return "NOT_READY";
}
}
public static function fromName($name) {
switch ($name) {
case "WAITING":
return self::WAITING;
case "VALIDATED":
return self::VALIDATED;
default:
return self::NOT_READY;
}
}
}