by-age and by-letter categories
[stouyapi.git] / bin / filters.php
index adad0d2..07a00bb 100644 (file)
@@ -1,4 +1,15 @@
 <?php
+function filterByAge($origGames, $age)
+{
+    $filtered = [];
+    foreach ($origGames as $game) {
+        if ($age == $game->contentRating) {
+            $filtered[] = $game;
+        }
+    }
+    return $filtered;
+}
+
 function filterByGenre($origGames, $genre)
 {
     $filtered = [];
@@ -10,6 +21,21 @@ function filterByGenre($origGames, $genre)
     return $filtered;
 }
 
+function filterByLetter($origGames, $letter)
+{
+    $filtered = [];
+    foreach ($origGames as $game) {
+        $gameLetter = strtoupper($game->title{0});
+        if (!preg_match('#^[A-Z]$#', $gameLetter)) {
+            $gameLetter = 'Other';
+        }
+        if ($letter == $gameLetter) {
+            $filtered[] = $game;
+        }
+    }
+    return $filtered;
+}
+
 function filterByPackageNames($origGames, $packageNames)
 {
     $names = array_flip($packageNames);