cweiske's pick: skyriders
[stouyapi.git] / bin / filters.php
index 703114a2410fa9e65f88aec8d3c2e499379fa9a8..628936a899e2057499f56a1ad7d5e3a14e0174e7 100644 (file)
@@ -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;
+}
 ?>