1
0
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:
galaxyoyo
2019-09-06 14:02:32 +02:00
parent a1ef162bdb
commit b5d567e364
3 changed files with 102 additions and 31 deletions

View File

@ -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"];