2019-09-09 23:48:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Team
|
|
|
|
{
|
|
|
|
private $id;
|
|
|
|
private $name;
|
|
|
|
private $trigram;
|
2019-09-10 23:17:05 +00:00
|
|
|
private $problem;
|
|
|
|
private $encadrant;
|
2019-09-09 23:48:52 +00:00
|
|
|
private $participants;
|
|
|
|
private $inscription_date;
|
|
|
|
private $validation_status;
|
2019-09-19 22:02:01 +00:00
|
|
|
private $video_team_ids;
|
2019-09-09 23:48:52 +00:00
|
|
|
private $access_code;
|
|
|
|
private $year;
|
|
|
|
|
|
|
|
private function __construct() {}
|
|
|
|
|
|
|
|
public static function fromId($id)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$req = $DB->prepare("SELECT * FROM `teams` WHERE `id` = ?;");
|
|
|
|
$req->execute([htmlspecialchars($id)]);
|
|
|
|
$data = $req->fetch();
|
|
|
|
|
|
|
|
if ($data === false)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
$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)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
$team = new Team();
|
|
|
|
$team->fill($data);
|
|
|
|
return $team;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fromAccessCode($access_code)
|
|
|
|
{
|
|
|
|
global $DB, $YEAR;
|
|
|
|
$req = $DB->prepare("SELECT * FROM `teams` WHERE `access_code` = ? AND `year` = $YEAR;");
|
|
|
|
$req->execute([htmlspecialchars($access_code)]);
|
|
|
|
$data = $req->fetch();
|
|
|
|
|
|
|
|
if ($data === false)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
$team = new Team();
|
|
|
|
$team->fill($data);
|
|
|
|
return $team;
|
|
|
|
}
|
|
|
|
|
2019-09-19 22:02:01 +00:00
|
|
|
public static function getAllTeams($problem)
|
|
|
|
{
|
|
|
|
global $DB, $YEAR;
|
|
|
|
$req = $DB->prepare("SELECT * FROM `teams` WHERE `problem` = ? AND `year` = $YEAR;");
|
|
|
|
$req->execute([htmlspecialchars($problem)]);
|
|
|
|
|
|
|
|
$teams = [];
|
|
|
|
|
|
|
|
while (($data = $req->fetch()) != false) {
|
|
|
|
$team = new Team();
|
|
|
|
$team->fill($data);
|
|
|
|
$teams[] = $team;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $teams;
|
|
|
|
}
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
private function fill($data)
|
|
|
|
{
|
|
|
|
$this->id = $data["id"];
|
|
|
|
$this->name = $data["name"];
|
|
|
|
$this->trigram = $data["trigram"];
|
2019-09-10 23:17:05 +00:00
|
|
|
$this->problem = $data["problem"];
|
|
|
|
$this->encadrant = $data["encadrant"];
|
2019-09-12 12:11:59 +00:00
|
|
|
$this->participants = [$data["participant_1"], $data["participant_2"], $data["participant_3"], $data["participant_4"], $data["participant_5"]];
|
2019-09-09 23:48:52 +00:00
|
|
|
$this->inscription_date = $data["inscription_date"];
|
|
|
|
$this->validation_status = ValidationStatus::fromName($data["validation_status"]);
|
2019-09-19 22:02:01 +00:00
|
|
|
$this->video_team_ids = [$data["video_team1"], $data["video_team2"]];
|
2019-09-09 23:48:52 +00:00
|
|
|
$this->access_code = $data["access_code"];
|
|
|
|
$this->year = $data["year"];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$this->name = $name;
|
|
|
|
$DB->prepare("UPDATE `teams` SET `name` = ? WHERE `id` = ?;")->execute([$name, $this->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getTrigram()
|
|
|
|
{
|
|
|
|
return $this->trigram;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTrigram($trigram)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$this->trigram = $trigram;
|
|
|
|
$DB->prepare("UPDATE `teams` SET `trigram` = ? WHERE `id` = ?;")->execute([$trigram, $this->id]);
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:17:05 +00:00
|
|
|
public function getProblem()
|
2019-09-09 23:48:52 +00:00
|
|
|
{
|
2019-09-10 23:17:05 +00:00
|
|
|
return $this->problem;
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 23:17:05 +00:00
|
|
|
public function setProblem($problem)
|
2019-09-09 23:48:52 +00:00
|
|
|
{
|
|
|
|
global $DB;
|
2019-09-10 23:17:05 +00:00
|
|
|
$this->problem = $problem;
|
|
|
|
$DB->prepare("UPDATE `teams` SET `problem` = ? WHERE `id` = ?;")->execute([$problem, $this->id]);
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 23:17:05 +00:00
|
|
|
public function getEncadrantId()
|
2019-09-09 23:48:52 +00:00
|
|
|
{
|
2019-09-10 23:17:05 +00:00
|
|
|
return $this->encadrant;
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
|
2019-09-10 23:17:05 +00:00
|
|
|
public function setEncadrant($encadrant)
|
2019-09-09 23:48:52 +00:00
|
|
|
{
|
|
|
|
global $DB;
|
2019-09-10 23:17:05 +00:00
|
|
|
$this->encadrant = $encadrant;
|
2019-09-09 23:48:52 +00:00
|
|
|
/** @noinspection SqlResolve */
|
2019-09-10 23:17:05 +00:00
|
|
|
$DB->prepare("UPDATE `teams` SET `encadrant` = ? WHERE `id` = ?;")->execute([$encadrant, $this->id]);
|
2019-09-09 23:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getParticipants()
|
|
|
|
{
|
|
|
|
return $this->participants;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setParticipant($i, $participant)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$this->participants[$i - 1] = $participant;
|
|
|
|
/** @noinspection SqlResolve */
|
|
|
|
$DB->prepare("UPDATE `teams` SET `participant_$i` = ? WHERE `id` = ?;")->execute([$participant, $this->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getInscriptionDate()
|
|
|
|
{
|
|
|
|
return $this->inscription_date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValidationStatus()
|
|
|
|
{
|
|
|
|
return $this->validation_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setValidationStatus($status)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
$this->validation_status = $status;
|
|
|
|
$DB->prepare("UPDATE `teams` SET `validation_status` = ? WHERE `id` = ?;")->execute([ValidationStatus::getName($status), $this->id]);
|
|
|
|
}
|
|
|
|
|
2019-09-19 22:02:01 +00:00
|
|
|
public function getVideoTeamIds()
|
|
|
|
{
|
|
|
|
return $this->video_team_ids;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVideoTeamIds($video_team_ids)
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
ensure(sizeof($video_team_ids) == 2, "Une équipe doit recevoir exactement deux vidéos.");
|
|
|
|
$this->video_team_ids = $video_team_ids;
|
|
|
|
$DB->prepare("UPDATE `teams` SET `video_team1` = ?, `video_team2` = ? WHERE `id` = ?;")->execute([$video_team_ids[0], $video_team_ids[1], $this->id]);
|
|
|
|
}
|
|
|
|
|
2019-09-09 23:48:52 +00:00
|
|
|
public function getAccessCode()
|
|
|
|
{
|
|
|
|
return $this->access_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getYear()
|
|
|
|
{
|
|
|
|
return $this->year;
|
|
|
|
}
|
|
|
|
}
|