mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 14:57:27 +02:00
Améliorations du code
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user