59 lines
2.2 KiB
PHP
59 lines
2.2 KiB
PHP
<?php
|
|
namespace App\Controllers\Web;
|
|
|
|
use App\Core\WebBaseController;
|
|
use App\Core\GameFactory;
|
|
use App\Core\I18n;
|
|
use Db\Database;
|
|
|
|
class GameController extends WebBaseController {
|
|
|
|
public function play($code) {
|
|
$this->checkWebLogin();
|
|
I18n::init();
|
|
$db = new Database();
|
|
$userId = $this->getCurrentUserId();
|
|
$user = $db->get('users', ['id','username','balance','lang'], ['id' => $userId]);
|
|
$game = $db->get('games', '*', ['code' => $code, 'status' => 1]);
|
|
if (!$game) { header('Location: /'); return; }
|
|
$isAgent = !!$db->get('agents', 'id', ['user_id' => $userId, 'status' => 1]);
|
|
extract([
|
|
'user' => $user ?: ['id' => $userId, 'username' => $this->getCurrentUsername(), 'balance' => 0],
|
|
'game' => $game, 'isAgent' => $isAgent,
|
|
]);
|
|
$viewFile = __DIR__ . "/../../Views/Web/{$code}.php";
|
|
if (!file_exists($viewFile)) $viewFile = __DIR__ . "/../../Views/Web/game_generic.php";
|
|
include $viewFile;
|
|
}
|
|
|
|
public function stats($code) {
|
|
$this->checkWebLogin();
|
|
I18n::init();
|
|
$db = new Database();
|
|
$game = $db->get('games', '*', ['code' => $code, 'status' => 1]);
|
|
if (!$game) { header('Location: /'); return; }
|
|
$gameType = $game['type'] ?? $code;
|
|
$algoClass = GameFactory::getAlgorithm($gameType);
|
|
$resultTable = $algoClass::getResultTable();
|
|
$gameId = $game['id'];
|
|
|
|
$periods = $db->select('periods', ['id','period_number'], [
|
|
'game_id' => $gameId, 'status' => 'settled',
|
|
'ORDER' => ['id' => 'DESC'], 'LIMIT' => 100
|
|
]);
|
|
$results = [];
|
|
foreach ($periods as $p) {
|
|
if ($resultTable) {
|
|
$row = $db->get($resultTable, '*', ['period_id' => $p['id']]);
|
|
} else {
|
|
$row = $db->get('periods', '*', ['id' => $p['id']]);
|
|
}
|
|
if ($row) { $row['period_number'] = $p['period_number']; $results[] = $row; }
|
|
}
|
|
extract(compact('game', 'results'));
|
|
$viewFile = __DIR__ . "/../../Views/Web/{$code}_stats.php";
|
|
if (!file_exists($viewFile)) $viewFile = __DIR__ . "/../../Views/Web/game_stats_generic.php";
|
|
include $viewFile;
|
|
}
|
|
}
|