Skip to content

Commit

Permalink
Return only tv and movie cats from related searches
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Dec 29, 2024
1 parent f5bd060 commit 1720930
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Blacklight/Releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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).')') : ''
Expand Down Expand Up @@ -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).')') : ''
Expand Down Expand Up @@ -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) : ''
);
Expand Down
19 changes: 14 additions & 5 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 1720930

Please sign in to comment.