mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
Properly build where clause for rating checks
This commit is contained in:
parent
a6cfe75d6e
commit
2e315b7f08
@ -4020,9 +4020,13 @@ namespace Emby.Server.Implementations.Data
|
||||
whereClauses.Add(clause);
|
||||
}
|
||||
|
||||
var ratingClause = "(";
|
||||
if (query.HasParentalRating.HasValue && query.HasParentalRating.Value)
|
||||
{
|
||||
ratingClause += "InheritedParentalRatingValue not null";
|
||||
if (query.MinParentalRating.HasValue)
|
||||
{
|
||||
whereClauses.Add("InheritedParentalRatingValue>=@MinParentalRating");
|
||||
ratingClause += " AND InheritedParentalRatingValue >= @MinParentalRating";
|
||||
if (statement is not null)
|
||||
{
|
||||
statement.TryBind("@MinParentalRating", query.MinParentalRating.Value);
|
||||
@ -4031,23 +4035,101 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
if (query.MaxParentalRating.HasValue)
|
||||
{
|
||||
whereClauses.Add("InheritedParentalRatingValue<=@MaxParentalRating");
|
||||
ratingClause += " AND InheritedParentalRatingValue <= @MaxParentalRating";
|
||||
if (statement is not null)
|
||||
{
|
||||
statement.TryBind("@MaxParentalRating", query.MaxParentalRating.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (query.BlockUnratedItems.Length > 0)
|
||||
{
|
||||
var paramName = "@UnratedType";
|
||||
var index = 0;
|
||||
string blockedUnratedItems = string.Join(',', query.BlockUnratedItems.Select(_ => paramName + index++));
|
||||
ratingClause += "(InheritedParentalRatingValue is null AND UnratedType not in (" + blockedUnratedItems + "))";
|
||||
|
||||
if (query.HasParentalRating.HasValue)
|
||||
if (statement != null)
|
||||
{
|
||||
if (query.HasParentalRating.Value)
|
||||
for (var ind = 0; ind < query.BlockUnratedItems.Length; ind++)
|
||||
{
|
||||
whereClauses.Add("InheritedParentalRatingValue > 0");
|
||||
statement.TryBind(paramName + ind, query.BlockUnratedItems[ind].ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("InheritedParentalRatingValue = 0");
|
||||
}
|
||||
|
||||
if (query.MinParentalRating.HasValue || query.MaxParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += " OR (";
|
||||
}
|
||||
|
||||
if (query.MinParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += "InheritedParentalRatingValue >= @MinParentalRating";
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@MinParentalRating", query.MinParentalRating.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.MaxParentalRating.HasValue)
|
||||
{
|
||||
if (query.MinParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += " AND ";
|
||||
}
|
||||
|
||||
ratingClause += "InheritedParentalRatingValue <= @MaxParentalRating";
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@MaxParentalRating", query.MaxParentalRating.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.MinParentalRating.HasValue || query.MaxParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += ")";
|
||||
}
|
||||
|
||||
if (!(query.MinParentalRating.HasValue || query.MaxParentalRating.HasValue))
|
||||
{
|
||||
ratingClause += " OR InheritedParentalRatingValue not null";
|
||||
}
|
||||
}
|
||||
else if (query.MinParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += "InheritedParentalRatingValue is null OR (InheritedParentalRatingValue >= @MinParentalRating";
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@MinParentalRating", query.MinParentalRating.Value);
|
||||
}
|
||||
|
||||
if (query.MaxParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += " AND InheritedParentalRatingValue <= @MaxParentalRating";
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@MaxParentalRating", query.MaxParentalRating.Value);
|
||||
}
|
||||
}
|
||||
|
||||
ratingClause += ")";
|
||||
}
|
||||
else if (query.MaxParentalRating.HasValue)
|
||||
{
|
||||
ratingClause += "InheritedParentalRatingValue is null OR InheritedParentalRatingValue <= @MaxParentalRating";
|
||||
if (statement != null)
|
||||
{
|
||||
statement.TryBind("@MaxParentalRating", query.MaxParentalRating.Value);
|
||||
}
|
||||
}
|
||||
else if (query.HasParentalRating.HasValue && !query.HasParentalRating.Value)
|
||||
{
|
||||
ratingClause += "InheritedParentalRatingValue is null";
|
||||
}
|
||||
|
||||
if (!string.Equals(ratingClause, "(", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
whereClauses.Add(ratingClause + ")");
|
||||
}
|
||||
|
||||
if (query.HasOfficialRating.HasValue)
|
||||
@ -4312,7 +4394,7 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
|
||||
// TODO this seems to be an idea for a better schema where ProviderIds are their own table
|
||||
// buut this is not implemented
|
||||
// but this is not implemented
|
||||
// hasProviderIds.Add("(COALESCE((select value from ProviderIds where ItemId=Guid and Name = '" + pair.Key + "'), '') <> " + paramName + ")");
|
||||
|
||||
// TODO this is a really BAD way to do it since the pair:
|
||||
@ -4440,25 +4522,6 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
}
|
||||
|
||||
if (query.BlockUnratedItems.Length == 1)
|
||||
{
|
||||
whereClauses.Add("(InheritedParentalRatingValue > 0 or UnratedType <> @UnratedType)");
|
||||
if (statement is not null)
|
||||
{
|
||||
statement.TryBind("@UnratedType", query.BlockUnratedItems[0].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
if (query.BlockUnratedItems.Length > 1)
|
||||
{
|
||||
var inClause = string.Join(',', query.BlockUnratedItems.Select(i => "'" + i.ToString() + "'"));
|
||||
whereClauses.Add(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"(InheritedParentalRatingValue > 0 or UnratedType not in ({0}))",
|
||||
inClause));
|
||||
}
|
||||
|
||||
if (query.ExcludeInheritedTags.Length > 0)
|
||||
{
|
||||
var paramName = "@ExcludeInheritedTags";
|
||||
|
@ -273,7 +273,7 @@ namespace Emby.Server.Implementations.Localization
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Further improve by normalizing out all spaces and dashes
|
||||
// TODO: Further improve when necessary
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ public class ItemUpdateController : BaseJellyfinApiController
|
||||
|
||||
var info = new MetadataEditorInfo
|
||||
{
|
||||
ParentalRatingOptions = _localizationManager.GetParentalRatings().ToArray(),
|
||||
ParentalRatingOptions = _localizationManager.GetParentalRatings().ToList(),
|
||||
ExternalIdInfos = _providerManager.GetExternalIdInfos(item).ToArray(),
|
||||
Countries = _localizationManager.GetCountries().ToArray(),
|
||||
Cultures = _localizationManager.GetCultures().ToArray()
|
||||
|
@ -411,6 +411,13 @@ public class ItemsController : BaseJellyfinApiController
|
||||
query.SeriesStatuses = seriesStatus;
|
||||
}
|
||||
|
||||
// Exclude Blocked Unrated Items
|
||||
var blockedUnratedItems = user?.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems);
|
||||
if (blockedUnratedItems is not null)
|
||||
{
|
||||
query.BlockUnratedItems = blockedUnratedItems;
|
||||
}
|
||||
|
||||
// ExcludeLocationTypes
|
||||
if (excludeLocationTypes.Any(t => t == LocationType.Virtual))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user