mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-25 18:17:28 +02:00
Nouveaux constructeurs pour les classes
This commit is contained in:
@ -16,7 +16,9 @@ class Team
|
||||
private $access_code;
|
||||
private $year;
|
||||
|
||||
public function __construct($id)
|
||||
private function __construct() {}
|
||||
|
||||
public static function fromId($id)
|
||||
{
|
||||
global $DB;
|
||||
$req = $DB->prepare("SELECT * FROM `teams` WHERE `id` = ?;");
|
||||
@ -26,7 +28,29 @@ class Team
|
||||
if ($data === false)
|
||||
throw new InvalidArgumentException("L'équipe spécifiée n'existe pas.");
|
||||
|
||||
$this->id = $id;
|
||||
$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)
|
||||
throw new InvalidArgumentException("L'équipe spécifiée n'existe pas.");
|
||||
|
||||
$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"];
|
||||
|
Reference in New Issue
Block a user