af1152b001
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
59 lines
2.0 KiB
C#
59 lines
2.0 KiB
C#
// <copyright file="OfficialRatingComparer.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace Emby.Server.Implementations.Sorting;
|
|
|
|
using System;
|
|
using Jellyfin.Data.Enums;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Sorting;
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
/// <summary>
|
|
/// Class providing comparison for official ratings.
|
|
/// </summary>
|
|
public class OfficialRatingComparer : IBaseItemComparer
|
|
{
|
|
private readonly ILocalizationManager _localizationManager;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="OfficialRatingComparer"/> class.
|
|
/// </summary>
|
|
/// <param name="localizationManager">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
|
public OfficialRatingComparer(ILocalizationManager localizationManager)
|
|
{
|
|
_localizationManager = localizationManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the name.
|
|
/// </summary>
|
|
/// <value>The name.</value>
|
|
public ItemSortBy Type => ItemSortBy.OfficialRating;
|
|
|
|
/// <summary>
|
|
/// Compares the specified x.
|
|
/// </summary>
|
|
/// <param name="x">The x.</param>
|
|
/// <param name="y">The y.</param>
|
|
/// <returns>System.Int32.</returns>
|
|
public int Compare(BaseItem? x, BaseItem? y)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(x);
|
|
ArgumentNullException.ThrowIfNull(y);
|
|
var zeroRating = new ParentalRatingScore(0, 0);
|
|
|
|
var ratingX = string.IsNullOrEmpty(x.OfficialRating) ? zeroRating : _localizationManager.GetRatingScore(x.OfficialRating) ?? zeroRating;
|
|
var ratingY = string.IsNullOrEmpty(y.OfficialRating) ? zeroRating : _localizationManager.GetRatingScore(y.OfficialRating) ?? zeroRating;
|
|
var scoreCompare = ratingX.Score.CompareTo(ratingY.Score);
|
|
if (scoreCompare is 0)
|
|
{
|
|
return (ratingX.SubScore ?? 0).CompareTo(ratingY.SubScore ?? 0);
|
|
}
|
|
|
|
return scoreCompare;
|
|
}
|
|
}
|