OfficialRatingComparer.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Sorting;
  4. using MediaBrowser.Model.Globalization;
  5. using MediaBrowser.Model.Querying;
  6. namespace Emby.Server.Implementations.Sorting
  7. {
  8. public class OfficialRatingComparer : IBaseItemComparer
  9. {
  10. private readonly ILocalizationManager _localization;
  11. public OfficialRatingComparer(ILocalizationManager localization)
  12. {
  13. _localization = localization;
  14. }
  15. /// <summary>
  16. /// Compares the specified x.
  17. /// </summary>
  18. /// <param name="x">The x.</param>
  19. /// <param name="y">The y.</param>
  20. /// <returns>System.Int32.</returns>
  21. public int Compare(BaseItem x, BaseItem y)
  22. {
  23. if (x == null)
  24. throw new ArgumentNullException(nameof(x));
  25. if (y == null)
  26. throw new ArgumentNullException(nameof(y));
  27. var levelX = string.IsNullOrEmpty(x.OfficialRating) ? 0 : _localization.GetRatingLevel(x.OfficialRating) ?? 0;
  28. var levelY = string.IsNullOrEmpty(y.OfficialRating) ? 0 : _localization.GetRatingLevel(y.OfficialRating) ?? 0;
  29. return levelX.CompareTo(levelY);
  30. }
  31. /// <summary>
  32. /// Gets the name.
  33. /// </summary>
  34. /// <value>The name.</value>
  35. public string Name => ItemSortBy.OfficialRating;
  36. }
  37. }