From 0af2a49aa825fc692ac3d57ca66239a5141c486b Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sat, 12 Oct 2024 22:00:26 +0200 Subject: [PATCH] CS fix --- Blacklight/Movie.php | 30 +++++++++++----------- app/Models/Category.php | 55 ++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Blacklight/Movie.php b/Blacklight/Movie.php index 59ddc8297..b88485630 100755 --- a/Blacklight/Movie.php +++ b/Blacklight/Movie.php @@ -187,8 +187,8 @@ class Movie ->where('movieinfo.imdbid', '!=', '0000000') ->when($maxAge > 0, fn ($query) => $query->whereRaw('r.postdate > NOW() - INTERVAL ? DAY', [$maxAge])) ->when(! empty($excludedCats), fn ($query) => $query->whereNotIn('r.categories_id', $excludedCats)) - ->when(!empty($categorySearch), fn ($query) => $query->whereRaw( - // Check if $categorySearch starts with AND or OR and clean it up + ->when(! empty($categorySearch), fn ($query) => $query->whereRaw( + // Check if $categorySearch starts with AND or OR and clean it up preg_match('/^\s*(AND|OR)\s+/i', $categorySearch) ? preg_replace('/^\s*(AND|OR)\s+/i', '', $categorySearch) : $categorySearch )) ->groupBy('movieinfo.imdbid') @@ -261,20 +261,20 @@ class Movie } /** - * Get the order type the user requested on the movies page. - */ -protected function getMovieOrder($orderBy): array -{ - $orderArr = explode('_', (($orderBy === '') ? 'MAX(r.postdate)' : $orderBy)); - $orderField = match ($orderArr[0]) { - 'title' => 'm.title', - 'year' => 'm.year', - 'rating' => 'm.rating', - default => DB::raw('MAX(r.postdate)'), - }; + * Get the order type the user requested on the movies page. + */ + protected function getMovieOrder($orderBy): array + { + $orderArr = explode('_', (($orderBy === '') ? 'MAX(r.postdate)' : $orderBy)); + $orderField = match ($orderArr[0]) { + 'title' => 'm.title', + 'year' => 'm.year', + 'rating' => 'm.rating', + default => DB::raw('MAX(r.postdate)'), + }; - return [$orderField, isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1]) ? $orderArr[1] : 'desc']; -} + return [$orderField, isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1]) ? $orderArr[1] : 'desc']; + } /** * Order types for movies page. diff --git a/app/Models/Category.php b/app/Models/Category.php index b6ebb5a1a..072a61f48 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -305,40 +305,39 @@ class Category extends Model } public static function getCategorySearch(array $cat = []): string -{ - $categories = []; + { + $categories = []; - // If multiple categories were sent in a single array position, slice and add them - if (strpos($cat[0], ',') !== false) { - $tmpcats = explode(',', $cat[0]); - // Reset the category to the first comma separated value in the string - $cat[0] = $tmpcats[0]; - // Add the remaining categories in the string to the original array - foreach (array_slice($tmpcats, 1) as $tmpcat) { - $cat[] = $tmpcat; + // If multiple categories were sent in a single array position, slice and add them + if (strpos($cat[0], ',') !== false) { + $tmpcats = explode(',', $cat[0]); + // Reset the category to the first comma separated value in the string + $cat[0] = $tmpcats[0]; + // Add the remaining categories in the string to the original array + foreach (array_slice($tmpcats, 1) as $tmpcat) { + $cat[] = $tmpcat; + } } - } - foreach ($cat as $category) { - if (is_numeric($category) && $category !== -1 && self::isParent($category)) { - $children = RootCategory::find($category)->categories->pluck('id')->toArray(); - $categories = array_merge($categories, $children); - } elseif (is_numeric($category) && $category > 0) { - $categories[] = $category; + foreach ($cat as $category) { + if (is_numeric($category) && $category !== -1 && self::isParent($category)) { + $children = RootCategory::find($category)->categories->pluck('id')->toArray(); + $categories = array_merge($categories, $children); + } elseif (is_numeric($category) && $category > 0) { + $categories[] = $category; + } } + + $catCount = count($categories); + $catSearch = match ($catCount) { + 0 => 'AND 1=1', + 1 => $categories[0] !== -1 ? ' AND r.categories_id = '.$categories[0] : '', + default => ' AND r.categories_id IN ('.implode(', ', $categories).') ', + }; + + return $catSearch; } - $catCount = count($categories); - $catSearch = match ($catCount) { - 0 => 'AND 1=1', - 1 => $categories[0] !== -1 ? ' AND r.categories_id = ' . $categories[0] : '', - default => ' AND r.categories_id IN (' . implode(', ', $categories) . ') ', - }; - - - return $catSearch; -} - /** * Returns a concatenated list of other categories. */