mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 13:12:17 +01:00 
			
		
		
		
	Améliorations du code
This commit is contained in:
		@@ -8,6 +8,7 @@ class Document
 | 
			
		||||
	private $tournament_id;
 | 
			
		||||
	private $type;
 | 
			
		||||
	private $uploaded_at;
 | 
			
		||||
	private $version;
 | 
			
		||||
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
 | 
			
		||||
@@ -21,9 +22,14 @@ class Document
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$user = new Document();
 | 
			
		||||
		$user->fill($data);
 | 
			
		||||
		return $user;
 | 
			
		||||
		return self::fromData($data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function fromData($data)
 | 
			
		||||
	{
 | 
			
		||||
		$doc = new Document();
 | 
			
		||||
		$doc->fill($data);
 | 
			
		||||
		return $doc;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function fill($data)
 | 
			
		||||
@@ -34,6 +40,7 @@ class Document
 | 
			
		||||
		$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()
 | 
			
		||||
@@ -65,6 +72,11 @@ class Document
 | 
			
		||||
	{
 | 
			
		||||
		return $this->uploaded_at;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getVersion()
 | 
			
		||||
	{
 | 
			
		||||
		return $this->version;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Solution
 | 
			
		||||
@@ -74,6 +86,7 @@ class Solution
 | 
			
		||||
	private $tournament_id;
 | 
			
		||||
	private $problem;
 | 
			
		||||
	private $uploaded_at;
 | 
			
		||||
	private $version;
 | 
			
		||||
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
 | 
			
		||||
@@ -87,9 +100,14 @@ class Solution
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$user = new Solution();
 | 
			
		||||
		$user->fill($data);
 | 
			
		||||
		return $user;
 | 
			
		||||
		return self::fromData($data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function fromData($data)
 | 
			
		||||
	{
 | 
			
		||||
		$sol = new Solution();
 | 
			
		||||
		$sol->fill($data);
 | 
			
		||||
		return $sol;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function fill($data)
 | 
			
		||||
@@ -99,6 +117,7 @@ class Solution
 | 
			
		||||
		$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()
 | 
			
		||||
@@ -125,15 +144,21 @@ class Solution
 | 
			
		||||
	{
 | 
			
		||||
		return $this->uploaded_at;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getVersion()
 | 
			
		||||
	{
 | 
			
		||||
		return $this->version;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Synthese
 | 
			
		||||
class Synthesis
 | 
			
		||||
{
 | 
			
		||||
	private $file_id;
 | 
			
		||||
	private $team_id;
 | 
			
		||||
	private $tournament_id;
 | 
			
		||||
	private $dest;
 | 
			
		||||
	private $uploaded_at;
 | 
			
		||||
	private $version;
 | 
			
		||||
 | 
			
		||||
	private function __construct() {}
 | 
			
		||||
 | 
			
		||||
@@ -147,9 +172,14 @@ class Synthese
 | 
			
		||||
		if ($data === false)
 | 
			
		||||
			return null;
 | 
			
		||||
 | 
			
		||||
		$user = new Synthese();
 | 
			
		||||
		$user->fill($data);
 | 
			
		||||
		return $user;
 | 
			
		||||
		return self::fromData($data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function fromData($data)
 | 
			
		||||
	{
 | 
			
		||||
		$synthese = new Synthesis();
 | 
			
		||||
		$synthese->fill($data);
 | 
			
		||||
		return $synthese;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function fill($data)
 | 
			
		||||
@@ -159,6 +189,7 @@ class Synthese
 | 
			
		||||
		$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()
 | 
			
		||||
@@ -185,6 +216,11 @@ class Synthese
 | 
			
		||||
	{
 | 
			
		||||
		return $this->uploaded_at;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function getVersion()
 | 
			
		||||
	{
 | 
			
		||||
		return $this->version;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class DestType
 | 
			
		||||
@@ -233,7 +269,7 @@ class DocumentType
 | 
			
		||||
	const PHOTO_CONSENT = 1;
 | 
			
		||||
	const SANITARY_PLUG = 2;
 | 
			
		||||
	const SOLUTION = 3;
 | 
			
		||||
	const SYNTHESE = 4;
 | 
			
		||||
	const SYNTHESIS = 4;
 | 
			
		||||
 | 
			
		||||
	public static function getTranslatedName($type) {
 | 
			
		||||
		switch ($type) {
 | 
			
		||||
@@ -261,7 +297,7 @@ class DocumentType
 | 
			
		||||
			case self::SOLUTION:
 | 
			
		||||
				return "SOLUTION";
 | 
			
		||||
			default:
 | 
			
		||||
				return "SYNTHESE";
 | 
			
		||||
				return "SYNTHESIS";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -276,7 +312,7 @@ class DocumentType
 | 
			
		||||
			case "SOLUTION":
 | 
			
		||||
				return self::SOLUTION;
 | 
			
		||||
			default:
 | 
			
		||||
				return self::SYNTHESE;
 | 
			
		||||
				return self::SYNTHESIS;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +1,25 @@
 | 
			
		||||
<?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 $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() {}
 | 
			
		||||
	private function __construct()
 | 
			
		||||
	{
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static function fromId($id)
 | 
			
		||||
	{
 | 
			
		||||
@@ -62,7 +65,29 @@ class Tournament
 | 
			
		||||
		return $tournament;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    private function fill($data)
 | 
			
		||||
	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"];
 | 
			
		||||
@@ -223,6 +248,22 @@ class Tournament
 | 
			
		||||
		$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;
 | 
			
		||||
@@ -242,4 +283,55 @@ class Tournament
 | 
			
		||||
	{
 | 
			
		||||
		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`) `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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -359,4 +359,33 @@ class User
 | 
			
		||||
	{
 | 
			
		||||
		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`) `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;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user