This commit is contained in:
DariusIII
2024-10-12 22:00:26 +02:00
parent d05a2ecfc7
commit 0af2a49aa8
2 changed files with 42 additions and 43 deletions
+15 -15
View File
@@ -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.
+27 -28
View File
@@ -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.
*/