mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 12:32:18 +01:00 
			
		
		
		
	Utilisation des nouvelles classes, amélioration du code
This commit is contained in:
		@@ -1,27 +1,37 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Role extends SplEnum
 | 
			
		||||
class Role
 | 
			
		||||
{
 | 
			
		||||
    const __default = self::PARTICIPANT;
 | 
			
		||||
 | 
			
		||||
    const PARTICIPANT = 0;
 | 
			
		||||
    const ENCADRANT = 1;
 | 
			
		||||
    const ORGANIZER = 2;
 | 
			
		||||
    const ADMIN = 3;
 | 
			
		||||
 | 
			
		||||
    public function getName() {
 | 
			
		||||
        switch ($this) {
 | 
			
		||||
            case self::ENCADRANT:
 | 
			
		||||
                return "Encadrant";
 | 
			
		||||
            case self::ORGANIZER:
 | 
			
		||||
                return "Organisateur";
 | 
			
		||||
            case self::ADMIN:
 | 
			
		||||
                return "Administrateur";
 | 
			
		||||
            default:
 | 
			
		||||
                return "Participant";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ class Team
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("L'équipe spécifiée n'existe pas.");
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$team = new Team();
 | 
			
		||||
		$team->fill($data);
 | 
			
		||||
@@ -41,7 +41,22 @@ class Team
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("L'équipe spécifiée n'existe pas.");
 | 
			
		||||
			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);
 | 
			
		||||
@@ -145,7 +160,7 @@ class Team
 | 
			
		||||
		global $DB;
 | 
			
		||||
		$this->validation_status = $status;
 | 
			
		||||
		/** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
		$DB->prepare("UPDATE `teams` SET `validation_status` = ? WHERE `id` = ?;")->execute([$status->getName(), $this->id]);
 | 
			
		||||
		$DB->prepare("UPDATE `teams` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($status), $this->id]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function isSelectedForFinal()
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ class Tournament
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("Le tournoi spécifié n'existe pas.");
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$tournament = new Tournament();
 | 
			
		||||
		$tournament->fill($data);
 | 
			
		||||
@@ -42,7 +42,21 @@ class Tournament
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("Le tournoi spécifié n'existe pas.");
 | 
			
		||||
			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);
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,7 @@ class User
 | 
			
		||||
	private $year;
 | 
			
		||||
	private $confirm_email;
 | 
			
		||||
	private $forgotten_password;
 | 
			
		||||
	private $inscription_date;
 | 
			
		||||
	
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
 | 
			
		||||
@@ -38,7 +39,7 @@ class User
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("L'utilisateur spécifié n'existe pas.");
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$user = new User();
 | 
			
		||||
		$user->fill($data);
 | 
			
		||||
@@ -53,7 +54,7 @@ class User
 | 
			
		||||
		$data = $req->fetch();
 | 
			
		||||
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			throw new InvalidArgumentException("L'utilisateur spécifié n'existe pas.");
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$user = new User();
 | 
			
		||||
		$user->fill($data);
 | 
			
		||||
@@ -85,6 +86,7 @@ class User
 | 
			
		||||
		$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()
 | 
			
		||||
@@ -166,7 +168,7 @@ class User
 | 
			
		||||
	{
 | 
			
		||||
		global $DB;
 | 
			
		||||
		$this->gender = $gender;
 | 
			
		||||
		$DB->prepare("UPDATE `users` SET `email` = ? WHERE `id` = ?;")->execute([$gender, $this->getId()]);
 | 
			
		||||
		$DB->prepare("UPDATE `users` SET `gender` = ? WHERE `id` = ?;")->execute([$gender, $this->getId()]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getAddress()
 | 
			
		||||
@@ -311,7 +313,7 @@ class User
 | 
			
		||||
		global $DB;
 | 
			
		||||
		$this->role = $role;
 | 
			
		||||
		/** @noinspection PhpUndefinedMethodInspection */
 | 
			
		||||
		$DB->prepare("UPDATE `users` SET `email` = ? WHERE `id` = ?;")->execute([$role->getName(), $this->getId()]);
 | 
			
		||||
		$DB->prepare("UPDATE `users` SET `role` = ? WHERE `id` = ?;")->execute([Role::getName($role), $this->getId()]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getTeamId()
 | 
			
		||||
@@ -354,4 +356,9 @@ class User
 | 
			
		||||
		$this->forgotten_password = $token;
 | 
			
		||||
		$DB->prepare("UPDATE `users` SET `forgotten_password` = ? WHERE `id` = ?;")->execute([$token, $this->getId()]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getInscriptionDate()
 | 
			
		||||
	{
 | 
			
		||||
		return $this->inscription_date;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,15 +1,13 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
class ValidationStatus extends SplEnum
 | 
			
		||||
class ValidationStatus
 | 
			
		||||
{
 | 
			
		||||
    const __default = self::NOT_READY;
 | 
			
		||||
 | 
			
		||||
    const NOT_READY = 0;
 | 
			
		||||
    const WAITING = 1;
 | 
			
		||||
    const VALIDATED = 2;
 | 
			
		||||
 | 
			
		||||
    public function getName() {
 | 
			
		||||
        switch ($this) {
 | 
			
		||||
    public static function getTranslatedName($status) {
 | 
			
		||||
        switch ($status) {
 | 
			
		||||
            case self::WAITING:
 | 
			
		||||
                return "En attente de validation";
 | 
			
		||||
            case self::VALIDATED:
 | 
			
		||||
@@ -19,6 +17,17 @@ class ValidationStatus extends SplEnum
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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":
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user