<?php
+function filterByAge($origGames, $age)
+{
+ $filtered = [];
+ foreach ($origGames as $game) {
+ if ($age == $game->contentRating) {
+ $filtered[] = $game;
+ }
+ }
+ return $filtered;
+}
+
function filterByGenre($origGames, $genre)
{
$filtered = [];
return $filtered;
}
+function filterByLetter($origGames, $letter)
+{
+ $filtered = [];
+ foreach ($origGames as $game) {
+ $gameLetter = strtoupper($game->title{0});
+ if (!preg_match('#^[A-Z]$#', $gameLetter)) {
+ $gameLetter = 'Other';
+ }
+ if ($letter == $gameLetter) {
+ $filtered[] = $game;
+ }
+ }
+ return $filtered;
+}
+
function filterByPackageNames($origGames, $packageNames)
{
$names = array_flip($packageNames);
);
$players = [
- 1 => '1 player',
+ //1 => '1 player',
2 => '2 players',
3 => '3 players',
4 => '4 players',
);
}
- $genres = getAllGenres($games);
- sort($genres);
- $genreChunks = array_chunk($genres, 4);
- $first = true;
- foreach ($genreChunks as $chunk) {
- addDiscoverRow(
- $data, $first ? 'Genres' : '',
- $chunk
+ $ages = getAllAges($games);
+ natsort($ages);
+ addDiscoverRow($data, 'Content rating', $ages);
+ foreach ($ages as $num => $title) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($title) . '.json',
+ buildDiscoverCategory($title, filterByAge($games, $title))
);
- $first = false;
}
+ $genres = getAllGenres($games);
+ sort($genres);
+ addChunkedDiscoverRows($data, $genres, 'Genres');
+
foreach ($genres as $genre) {
writeJson(
'api/v1/discover-data/' . categoryPath($genre) . '.json',
);
}
+ $abc = array_merge(range('A', 'Z'), ['Other']);
+ addChunkedDiscoverRows($data, $abc, 'Alphabetical');
+ foreach ($abc as $letter) {
+ writeJson(
+ 'api/v1/discover-data/' . categoryPath($letter) . '.json',
+ buildDiscoverCategory($letter, filterByLetter($games, $letter))
+ );
+ }
+
return $data;
}
];
}
+function addChunkedDiscoverRows(&$data, $games, $title)
+{
+ $chunks = array_chunk($games, 4);
+ $first = true;
+ foreach ($chunks as $chunk) {
+ addDiscoverRow(
+ $data, $first ? $title : '',
+ $chunk
+ );
+ $first = false;
+ }
+}
+
function addDiscoverRow(&$data, $title, $games)
{
$row = [
function categoryPath($title)
{
- return str_replace(['/', '\\', ' '], '_', $title);
+ return str_replace(['/', '\\', ' ', '+'], '_', $title);
+}
+
+function getAllAges($games)
+{
+ $ages = [];
+ foreach ($games as $game) {
+ $ages[] = $game->contentRating;
+ }
+ return array_unique($ages);
}
function getAllGenres($games)