diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index c47993d38..003639f1d 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -31,6 +31,10 @@ namespace MediaBrowser.Model.Querying /// public const string DateCreated = "DateCreated"; /// + /// The official rating + /// + public const string OfficialRating = "OfficialRating"; + /// /// The date played /// public const string DatePlayed = "DatePlayed"; diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 8de458e5f..406830037 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -173,6 +173,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/OfficialRatingComparer.cs b/MediaBrowser.Server.Implementations/Sorting/OfficialRatingComparer.cs new file mode 100644 index 000000000..dd31109da --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/OfficialRatingComparer.cs @@ -0,0 +1,40 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.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; } + } + } +}