X-Git-Url: https://git.cweiske.de/stouyapi.git/blobdiff_plain/a2ab16cfec3ac79d5b293c135e5430b07d617e3f..ad9f3cf5a07338134a29fee4b6215c50cb8142c8:/bin/filters.php diff --git a/bin/filters.php b/bin/filters.php index 703114a..628936a 100644 --- a/bin/filters.php +++ b/bin/filters.php @@ -65,6 +65,17 @@ function filterByPlayers($origGames, $numOfPlayers) return $filtered; } +function filterBySearchWord($origGames, $searchWord) +{ + $filtered = []; + foreach ($origGames as $game) { + if (stripos($game->title, $searchWord) !== false) { + $filtered[] = $game; + } + } + return $filtered; +} + function filterLastUpdated($origGames, $limit) { $games = array_values($origGames); @@ -84,10 +95,21 @@ function filterBestRated($origGames, $limit) usort( $games, function ($gameA, $gameB) { - return $gameB->rating->average - $gameA->rating->average; + return ($gameB->rating->rank - $gameA->rating->rank) * 100; } ); return array_slice($games, 0, $limit); } + +function sortByTitle($games) +{ + usort( + $games, + function ($gameA, $gameB) { + return strcasecmp($gameA->title, $gameB->title); + } + ); + return $games; +} ?>