Hide vimeo videos since they cause ssl errors
[stouyapi.git] / bin / filters.php
index 07a00bb3a778482e09b1a72f3acf5db6635d19b1..a10777a03ed65bcec36ed507da65c6dc93a30e2b 100644 (file)
@@ -10,12 +10,18 @@ function filterByAge($origGames, $age)
     return $filtered;
 }
 
-function filterByGenre($origGames, $genre)
+function filterByGenre($origGames, $genre, $remove = false)
 {
     $filtered = [];
     foreach ($origGames as $game) {
-        if (array_search($genre, $game->genres) !== false) {
-            $filtered[] = $game;
+        if ($remove) {
+            if (array_search($genre, $game->genres) === false) {
+                $filtered[] = $game;
+            }
+        } else {
+            if (array_search($genre, $game->genres) !== false) {
+                $filtered[] = $game;
+            }
         }
     }
     return $filtered;
@@ -59,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);
@@ -78,10 +95,44 @@ 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 filterMostDownloaded($origGames, $limit)
+{
+    $games = array_values($origGames);
+    usort(
+        $games,
+        function ($gameA, $gameB) {
+            return $gameB->rating->count - $gameA->rating->count;
+        }
+    );
+
+    return array_slice($games, 0, $limit);
+}
+
+function filterRandom($origGames, $limit)
+{
+    $randKeys = array_rand($origGames, $limit);
+    $games = [];
+    foreach ($randKeys as $key) {
+        $games[] = $origGames[$key];
+    }
+    return $games;
+}
+
+function sortByTitle($games)
+{
+    usort(
+        $games,
+        function ($gameA, $gameB) {
+            return strcasecmp($gameA->title, $gameB->title);
+        }
+    );
+    return $games;
+}
 ?>