forked from facebookarchive/fbctf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |