mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 15:37:27 +02:00
Nouveaux constructeurs pour les classes
This commit is contained in:
@ -17,9 +17,11 @@ class Tournament
|
||||
private $final;
|
||||
private $year;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
global $DB;
|
||||
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();
|
||||
@ -27,7 +29,29 @@ class Tournament
|
||||
if ($data === false)
|
||||
throw new InvalidArgumentException("Le tournoi spécifié n'existe pas.");
|
||||
|
||||
$this->id = $id;
|
||||
$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)
|
||||
throw new InvalidArgumentException("Le tournoi spécifié n'existe pas.");
|
||||
|
||||
$tournament = new Tournament();
|
||||
$tournament->fill($data);
|
||||
return $tournament;
|
||||
}
|
||||
|
||||
private function fill($data)
|
||||
{
|
||||
$this->id = $data["id"];
|
||||
$this->name = $data["name"];
|
||||
$this->size = $data["size"];
|
||||
$this->place = $data["place"];
|
||||
@ -40,7 +64,7 @@ class Tournament
|
||||
$this->date_syntheses = $data["date_syntheses"];
|
||||
$this->final = $data["final"] == true;
|
||||
$this->year = $data["year"];
|
||||
}
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
|
Reference in New Issue
Block a user