WIP: перед введенимем класса Fighter.php
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Model;
|
||||
|
||||
use Core\Db;
|
||||
use stdClass;
|
||||
|
||||
readonly class BattleModel
|
||||
{
|
||||
public stdClass $battle;
|
||||
public array $battleArray;
|
||||
private array $all;
|
||||
public function __construct(int $id) {
|
||||
$this->all = Db::getRows('select * from battle');
|
||||
if (empty($id)) {
|
||||
$this->battle = new stdClass();
|
||||
$this->battleArray = [];
|
||||
} else {
|
||||
foreach ($this->all as $b) {
|
||||
if ($b['id'] != $id) {
|
||||
continue;
|
||||
}
|
||||
$this->battle = (object)$b;
|
||||
$this->battleArray = get_object_vars($this->battle);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function countClanWars(int $clanid): array
|
||||
{
|
||||
$today = (new \DateTimeImmutable('now 00:00:00'))->getTimestamp();
|
||||
$sql = "select count(id) from battle where
|
||||
type = 250 and
|
||||
time_over > ? and
|
||||
(team_win = ? and clan1 = ?) or (team_win = ? and clan2 = ?)";
|
||||
$count1 = Db::getValue($sql, [$today, 1, $clanid, 2, $clanid]);
|
||||
$count2 = Db::getValue($sql, [$today, 2, $clanid, 1, $clanid]);
|
||||
return [
|
||||
$count1 ?? 0,
|
||||
$count2 ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user