t = Db::getRows('select * from tournaments') ?? [];
}
public function getAllStarted(): array
{
$tidList = [];
foreach ($this->t as $row) {
if ($row['start_time'] === -1) {
$tidList[] = $row['tid'];
}
}
return $tidList;
}
public function isStarted(int $tid): bool
{
foreach ($this->t as $row) {
if ($row['start_time'] === -1 && $row['tid'] === $tid) {
return true;
}
}
return false;
}
public function getList(): string
{
$list = '';
$tournamentMembersId = new User();
foreach ($this->t as $row) {
$time = $row['start_time'] === -1 ? 'Турнир уже начался!' : date('G:i', $row['start_time']);
$members = [];
foreach ($tournamentMembersId->getAlive($row['tid']) as $member) {
$members[] = (new GameConnector())->setUser($member)->uidToLogin();
}
$list .= sprintf(
"
Турнир для %d уровней.
Время подачи заявки: %s
Участники: %s",
$row['tid'],
$time,
implode(', ', $members)
);
}
return $list ? "" : '';
}
public function getOne(int $tid): string
{
$str = '';
$tournamentMembersId = new User();
foreach ($this->t as $row) {
if ($this->t['tid'] === $tid) {
$time = $row['start_time'] === -1 ? 'Турнир уже начался!' : date('G:i', $row['start_time']);
$members = [];
foreach ($tournamentMembersId->getAlive($row['tid']) as $member) {
$members[] = (new GameConnector())->setUser($member)->uidToLogin();
}
$str = sprintf(
"Турнир для %d уровней.
Время подачи заявки: %s
Участники: %s
",
$row['tid'],
$time,
implode(', ', $members)
);
}
}
return $str;
}
/**
* Создание нового турнира.
*
* @param int $tid
*
* @return void
*/
public static function create(int $tid)
{
Db::sql('insert into tournaments (tid) values (?)', [$tid]);
}
/**
* Старт турнира.
*
* @param int $tid
*
* @return void
*/
public static function start(int $tid)
{
Db::sql('update tournaments set start_time = -1 where tid = ?', [$tid]);
}
/**
* Чистим базы от прошедшего турнира.
*
* @param int $tid
*
* @return void
*/
public static function destroy(int $tid)
{
Db::sql('delete from tournaments where tid = ?', [$tid]);
}
}