From 1720930f5e1d0614bd1944ff942ed9692033ebcc Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 29 Dec 2024 16:37:59 +0100 Subject: [PATCH] Return only tv and movie cats from related searches --- Blacklight/Releases.php | 7 ++++--- app/Models/Category.php | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Blacklight/Releases.php b/Blacklight/Releases.php index bd329c06d7..fc9b9ceb8f 100644 --- a/Blacklight/Releases.php +++ b/Blacklight/Releases.php @@ -629,6 +629,7 @@ public function apiSearch($searchName, $groupName, int $offset = 0, int $limit = */ public function tvSearch(array $siteIdArr = [], string $series = '', string $episode = '', string $airDate = '', int $offset = 0, int $limit = 100, string $name = '', array $cat = [-1], int $maxAge = -1, int $minSize = 0, array $excludedCategories = []): mixed { + dd(Category::getCategorySearch($cat, 'tv')); $siteSQL = []; $showSql = ''; foreach ($siteIdArr as $column => $Id) { @@ -712,7 +713,7 @@ public function tvSearch(array $siteIdArr = [], string $series = '', string $epi $this->showPasswords(), $showSql, (! empty($name) && ! empty($searchResult)) ? 'AND r.id IN ('.implode(',', $searchResult).')' : '', - Category::getCategorySearch($cat), + Category::getCategorySearch($cat, 'tv'), $maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : '', $minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : '', ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '' @@ -852,7 +853,7 @@ public function apiTvSearch(array $siteIdArr = [], string $series = '', string $ $this->showPasswords(), $showSql, (! empty($searchResult) ? 'AND r.id IN ('.implode(',', $searchResult).')' : ''), - Category::getCategorySearch($cat), + Category::getCategorySearch($cat, 'tv'), ($maxAge > 0 ? sprintf('AND r.postdate > NOW() - INTERVAL %d DAY', $maxAge) : ''), ($minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : ''), ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '' @@ -1002,7 +1003,7 @@ public function moviesSearch(int $imDbId = -1, int $tmDbId = -1, int $traktId = ($tmDbId !== -1 && is_numeric($tmDbId)) ? sprintf(' AND m.tmdbid = %d ', $tmDbId) : '', ($traktId !== -1 && is_numeric($traktId)) ? sprintf(' AND m.traktid = %d ', $traktId) : '', ! empty($excludedCategories) ? sprintf('AND r.categories_id NOT IN('.implode(',', $excludedCategories).')') : '', - Category::getCategorySearch($cat), + Category::getCategorySearch($cat, 'movies'), $maxAge > 0 ? sprintf(' AND r.postdate > NOW() - INTERVAL %d DAY ', $maxAge) : '', $minSize > 0 ? sprintf('AND r.size >= %d', $minSize) : '' ); diff --git a/app/Models/Category.php b/app/Models/Category.php index 072a61f48b..77d282b6ac 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -304,12 +304,22 @@ public static function getRecentlyAdded() return $result; } - public static function getCategorySearch(array $cat = []): string + public static function getCategorySearch(array $cat = [], ?string $searchType = null): string { $categories = []; + // if searchType is tv return TV categories + if ($searchType === 'tv') { + $cat = self::TV_GROUP; + } + + // is searchType is movies return MOVIES categories + if ($searchType === 'movies') { + $cat = self::MOVIES_GROUP; + } + // If multiple categories were sent in a single array position, slice and add them - if (strpos($cat[0], ',') !== false) { + if (str_contains($cat[0], ',')) { $tmpcats = explode(',', $cat[0]); // Reset the category to the first comma separated value in the string $cat[0] = $tmpcats[0]; @@ -329,13 +339,12 @@ public static function getCategorySearch(array $cat = []): string } $catCount = count($categories); - $catSearch = match ($catCount) { + + return 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; } /**