| | 1 | | #pragma warning disable CS1591 |
| | 2 | |
|
| | 3 | | using System; |
| | 4 | | using Jellyfin.Data.Enums; |
| | 5 | | using MediaBrowser.Controller.Entities; |
| | 6 | | using MediaBrowser.Controller.Sorting; |
| | 7 | | using MediaBrowser.Model.Globalization; |
| | 8 | | using MediaBrowser.Model.Querying; |
| | 9 | |
|
| | 10 | | namespace Emby.Server.Implementations.Sorting |
| | 11 | | { |
| | 12 | | public class OfficialRatingComparer : IBaseItemComparer |
| | 13 | | { |
| | 14 | | private readonly ILocalizationManager _localization; |
| | 15 | |
|
| | 16 | | public OfficialRatingComparer(ILocalizationManager localization) |
| | 17 | | { |
| 22 | 18 | | _localization = localization; |
| 22 | 19 | | } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Gets the name. |
| | 23 | | /// </summary> |
| | 24 | | /// <value>The name.</value> |
| 1 | 25 | | public ItemSortBy Type => ItemSortBy.OfficialRating; |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Compares the specified x. |
| | 29 | | /// </summary> |
| | 30 | | /// <param name="x">The x.</param> |
| | 31 | | /// <param name="y">The y.</param> |
| | 32 | | /// <returns>System.Int32.</returns> |
| | 33 | | public int Compare(BaseItem? x, BaseItem? y) |
| | 34 | | { |
| 0 | 35 | | ArgumentNullException.ThrowIfNull(x); |
| | 36 | |
|
| 0 | 37 | | ArgumentNullException.ThrowIfNull(y); |
| | 38 | |
|
| 0 | 39 | | var levelX = string.IsNullOrEmpty(x.OfficialRating) ? 0 : _localization.GetRatingLevel(x.OfficialRating) ?? |
| 0 | 40 | | var levelY = string.IsNullOrEmpty(y.OfficialRating) ? 0 : _localization.GetRatingLevel(y.OfficialRating) ?? |
| | 41 | |
|
| 0 | 42 | | return levelX.CompareTo(levelY); |
| | 43 | | } |
| | 44 | | } |
| | 45 | | } |