ignore generated data
[stouyapi.git] / bin / filters.php
1 <?php
2 function filterByGenre($origGames, $genre)
3 {
4     $filtered = [];
5     foreach ($origGames as $game) {
6         if (array_search($genre, $game->genres) !== false) {
7             $filtered[] = $game;
8         }
9     }
10     return $filtered;
11 }
12
13 function filterByPackageNames($origGames, $packageNames)
14 {
15     $names = array_flip($packageNames);
16     $filtered = [];
17     foreach ($origGames as $game) {
18         if (isset($names[$game->packageName])) {
19             $filtered[] = $game;
20         }
21     }
22     return $filtered;
23 }
24
25 function filterByPlayers($origGames, $numOfPlayers)
26 {
27     $filtered = [];
28     foreach ($origGames as $game) {
29         if (array_search($numOfPlayers, $game->players) !== false) {
30             $filtered[] = $game;
31         }
32     }
33     return $filtered;
34 }
35
36 function filterLastUpdated($origGames, $limit)
37 {
38     $games = array_values($origGames);
39     usort(
40         $games,
41         function ($gameA, $gameB) {
42             return strtotime($gameB->latestRelease->date) - strtotime($gameA->latestRelease->date);
43         }
44     );
45
46     return array_slice($games, 0, $limit);
47 }
48
49 function filterBestRated($origGames, $limit)
50 {
51     $games = array_values($origGames);
52     usort(
53         $games,
54         function ($gameA, $gameB) {
55             return $gameB->rating->average - $gameA->rating->average;
56         }
57     );
58
59     return array_slice($games, 0, $limit);
60 }
61 ?>