From 3eb4091808735858b01855d298226d239be464af Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Nov 2016 02:37:52 -0400 Subject: move additional classes to new server lib --- .../Sorting/OfficialRatingComparer.cs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs (limited to 'Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs') diff --git a/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs b/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs new file mode 100644 index 0000000000..3eab4fccc9 --- /dev/null +++ b/Emby.Server.Implementations/Sorting/OfficialRatingComparer.cs @@ -0,0 +1,40 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.Querying; + +namespace Emby.Server.Implementations.Sorting +{ + public class OfficialRatingComparer : IBaseItemComparer + { + private readonly ILocalizationManager _localization; + + public OfficialRatingComparer(ILocalizationManager localization) + { + _localization = localization; + } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + var levelX = string.IsNullOrEmpty(x.OfficialRating) ? 0 : _localization.GetRatingLevel(x.OfficialRating) ?? 0; + var levelY = string.IsNullOrEmpty(y.OfficialRating) ? 0 : _localization.GetRatingLevel(y.OfficialRating) ?? 0; + + return levelX.CompareTo(levelY); + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.OfficialRating; } + } + } +} -- cgit v1.2.3