2 function filterByAge($origGames, $age)
5 foreach ($origGames as $game) {
6 if ($age == $game->contentRating) {
13 function filterByGenre($origGames, $genre, $remove = false)
16 foreach ($origGames as $game) {
18 if (array_search($genre, $game->genres) === false) {
22 if (array_search($genre, $game->genres) !== false) {
30 function filterByLetter($origGames, $letter)
33 foreach ($origGames as $game) {
34 $gameLetter = strtoupper($game->title[0]);
35 if (!preg_match('#^[A-Z]$#', $gameLetter)) {
36 $gameLetter = 'Other';
38 if ($letter == $gameLetter) {
45 function filterByPackageNames($origGames, $packageNames)
47 $names = array_flip($packageNames);
49 foreach ($origGames as $game) {
50 if (isset($names[$game->packageName])) {
51 $filtered[$names[$game->packageName]] = $game;
55 ksort($filtered, SORT_NUMERIC);
59 function filterByPlayers($origGames, $numOfPlayers)
62 foreach ($origGames as $game) {
63 if (array_search($numOfPlayers, $game->players) !== false) {
70 function filterBySearchWord($origGames, $searchWord)
73 foreach ($origGames as $game) {
74 if (stripos($game->title, $searchWord) !== false) {
81 function filterLastAdded($origGames, $limit)
83 $games = array_values($origGames);
86 function ($gameA, $gameB) {
87 return strtotime($gameB->firstRelease->date) - strtotime($gameA->firstRelease->date);
91 return array_slice($games, 0, $limit);
94 function filterLastUpdated($origGames, $limit)
96 $games = array_values($origGames);
99 function ($gameA, $gameB) {
100 return strtotime($gameB->latestRelease->date) - strtotime($gameA->latestRelease->date);
104 return array_slice($games, 0, $limit);
107 function filterBestRated($origGames, $limit)
109 $games = array_values($origGames);
112 function ($gameA, $gameB) {
113 return ($gameB->rating->rank - $gameA->rating->rank) * 100;
117 return array_slice($games, 0, $limit);
120 function filterBestRatedGames($origGames, $limit)
122 $noApps = filterByGenre($origGames, 'App', true);
123 $noAppsNoEmus = filterByGenre($noApps, 'Emulator', true);
125 return filterBestRated($noAppsNoEmus, $limit);
128 function filterMostDownloaded($origGames, $limit)
130 $games = array_values($origGames);
133 function ($gameA, $gameB) {
134 return $gameB->rating->count - $gameA->rating->count;
138 return array_slice($games, 0, $limit);
141 function filterRandom($origGames, $limit)
143 $randKeys = array_rand($origGames, min(count($origGames), $limit));
145 foreach ($randKeys as $key) {
146 $games[] = $origGames[$key];
151 function sortByTitle($games)
155 function ($gameA, $gameB) {
156 return strcasecmp($gameA->title, $gameB->title);