Skip to content

Commit

Permalink
Gamelog timeline ready
Browse files Browse the repository at this point in the history
  • Loading branch information
javuto committed May 10, 2016
1 parent c61e290 commit 3ae6e59
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,7 @@ public function renderControlsContent(): :xhp {
<div class="post-avatar has-avatar">
<svg class="icon icon--badge">
<use href="#icon--badge-"/>
</svg>
</div>
</div>
Expand Down Expand Up @@ -1896,6 +1897,7 @@ public function renderControlsContent(): :xhp {
<div class="post-avatar has-avatar">
<svg class="icon icon--badge">
<use href={$xlink_href} />
</svg>
</div>
</div>
Expand Down Expand Up @@ -2104,7 +2106,46 @@ public function renderControlsContent(): :xhp {
</div>;
}

public function renderLogsContent(): :xhp {
public async function genRenderLogsContent(): Awaitable<:xhp> {
$logs_tbody = <tbody></tbody>;
$gamelogs = await GameLog::genGameLog();
foreach ($gamelogs as $gamelog) {
if ($gamelog->getEntry() === 'score') {
$log_entry = <span class="highlighted--green">{$gamelog->getEntry()}</span>;
} else {
$log_entry = <span class="highlighted--red">{$gamelog->getEntry()}</span>;
}
$team = await Team::genTeam($gamelog->getTeamId());
$level = await Level::gen($gamelog->getLevelId());
$country = await Country::gen($level->getEntityId());
$level_str = $country->getName() . ' - ' . $level->getTitle() . ' - ' . $level->getType();
$logs_tbody->appendChild(
<tr>
<td>{time_ago($gamelog->getTs())}</td>
<td>{$log_entry}</td>
<td>{$level_str}</td>
<td>{strval($gamelog->getPoints())}</td>
<td>{$team->getName()}</td>
<td>{$gamelog->getFlag()}</td>
</tr>
);
}

$logs_table =
<table>
<thead>
<tr>
<th>time_</th>
<th>entry_</th>
<th>level_</th>
<th>pts_</th>
<th>team_</th>
<th>flag_</th>
</tr>
</thead>
{$logs_tbody}
</table>;

return
<div>
<header class="admin-page-header">
Expand All @@ -2113,6 +2154,12 @@ public function renderLogsContent(): :xhp {
</header>
<div class="admin-sections">
<section class="admin-box">
<header class="admin-box-header">
<h3>Game Logs Timeline</h3>
</header>
<div class="fb-column-container">
{$logs_table}
</div>
</section>
</div>
</div>;
Expand Down Expand Up @@ -2208,7 +2255,7 @@ public function renderMainContent(): :xhp {
return await $this->genRenderSessionsContent();
break;
case 'logs':
return $this->renderLogsContent();
return await $this->genRenderLogsContent();
break;
default:
return $this->renderMainContent();
Expand Down
74 changes: 74 additions & 0 deletions src/models/GameLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?hh // strict

class GameLog extends Model {
private function __construct(
private string $ts,
private string $entry,
private int $team_id,
private int $level_id,
private int $points,
private string $type,
private string $flag
) {
}

public function getTs(): string {
return $this->ts;
}

public function getEntry(): string {
return $this->entry;
}

public function getTeamId(): int {
return $this->team_id;
}

public function getLevelId(): int {
return $this->level_id;
}

public function getPoints(): int {
return $this->points;
}

public function getType(): string {
return $this->type;
}

public function getFlag(): string {
return $this->flag;
}

private static function gamelogFromRow(Map<string, string> $row): GameLog {
return new GameLog(
must_have_idx($row, 'ts'),
must_have_idx($row, 'entry'),
intval(must_have_idx($row, 'team_id')),
intval(must_have_idx($row, 'level_id')),
intval(must_have_idx($row, 'points')),
must_have_idx($row, 'type'),
must_have_idx($row, 'flag'),
);
}

// Get all game scores.
public static async function genGameLog(
): Awaitable<array<GameLog>> {
$db = await self::genDb();
$result = await $db->queryf(
'SELECT ts, %s AS entry, team_id, level_id, points, type, %s AS flag FROM scores_log UNION SELECT ts, %s AS entry, team_id, level_id, 0 AS points, %s AS type, flag FROM failures_log ORDER BY ts DESC',
'score',
'',
'failure',
'',
);

$gamelog = array();
foreach ($result->mapRows() as $row) {
$gamelog[] = self::gamelogFromRow($row);
}

return $gamelog;
}
}

0 comments on commit 3ae6e59

Please sign in to comment.