115 lines
3.0 KiB
PHP
115 lines
3.0 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace Insallah\Tournaments\Model;
|
|||
|
|
|||
|
use Insallah\Db;
|
|||
|
|
|||
|
class Tournament
|
|||
|
{
|
|||
|
private array $t;
|
|||
|
|
|||
|
public function __construct()
|
|||
|
{
|
|||
|
$this->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 ? '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!' : date('G:i', $row['start_time']);
|
|||
|
$members = [];
|
|||
|
foreach ($tournamentMembersId->getAlive($row['tid']) as $member) {
|
|||
|
$members[] = (new GameConnector())->setUser($member)->uidToLogin();
|
|||
|
}
|
|||
|
$list .= sprintf(
|
|||
|
"<li><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br><3E><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s<br><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s</li>",
|
|||
|
$row['tid'],
|
|||
|
$time,
|
|||
|
implode(', ', $members)
|
|||
|
);
|
|||
|
}
|
|||
|
return $list ? "<div><strong><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.</strong><br><ul>$list</ul></div>" : '';
|
|||
|
}
|
|||
|
|
|||
|
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 ? '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!' : date('G:i', $row['start_time']);
|
|||
|
$members = [];
|
|||
|
foreach ($tournamentMembersId->getAlive($row['tid']) as $member) {
|
|||
|
$members[] = (new GameConnector())->setUser($member)->uidToLogin();
|
|||
|
}
|
|||
|
$str = sprintf(
|
|||
|
"<div><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.<br><3E><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s<br><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: %s</div>",
|
|||
|
$row['tid'],
|
|||
|
$time,
|
|||
|
implode(', ', $members)
|
|||
|
);
|
|||
|
}
|
|||
|
}
|
|||
|
return $str;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* @param int $tid
|
|||
|
*
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public static function create(int $tid)
|
|||
|
{
|
|||
|
Db::sql('insert into tournaments (tid) values (?)', [$tid]);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* @param int $tid
|
|||
|
*
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public static function start(int $tid)
|
|||
|
{
|
|||
|
Db::sql('update tournaments set start_time = -1 where tid = ?', [$tid]);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* @param int $tid
|
|||
|
*
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public static function destroy(int $tid)
|
|||
|
{
|
|||
|
Db::sql('delete from tournaments where tid = ?', [$tid]);
|
|||
|
}
|
|||
|
}
|