From 9d7b3fdda66cb4607b0461b19bc42ce10bd00e6e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Sep 2013 15:30:56 -0400 Subject: add movie count sort order --- .../Sorting/MovieCountComparer.cs | 71 ++++++++++++++++++++++ .../Sorting/TrailerCountComparer.cs | 71 ++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 MediaBrowser.Server.Implementations/Sorting/MovieCountComparer.cs create mode 100644 MediaBrowser.Server.Implementations/Sorting/TrailerCountComparer.cs (limited to 'MediaBrowser.Server.Implementations/Sorting') diff --git a/MediaBrowser.Server.Implementations/Sorting/MovieCountComparer.cs b/MediaBrowser.Server.Implementations/Sorting/MovieCountComparer.cs new file mode 100644 index 000000000..9444a3321 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/MovieCountComparer.cs @@ -0,0 +1,71 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + public class MovieCountComparer : IUserBaseItemComparer + { + /// + /// Gets or sets the user. + /// + /// The user. + public User User { get; set; } + + /// + /// Gets or sets the user manager. + /// + /// The user manager. + public IUserManager UserManager { get; set; } + + /// + /// Gets or sets the user data repository. + /// + /// The user data repository. + public IUserDataRepository UserDataRepository { get; set; } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return GetValue(x).CompareTo(GetValue(y)); + } + + /// + /// Gets the date. + /// + /// The x. + /// DateTime. + private int GetValue(BaseItem x) + { + var itemByName = x as IItemByName; + + if (itemByName != null) + { + var counts = itemByName.GetItemByNameCounts(User); + + if (counts != null) + { + return counts.MovieCount; + } + } + + return 0; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.MovieCount; } + } + } +} diff --git a/MediaBrowser.Server.Implementations/Sorting/TrailerCountComparer.cs b/MediaBrowser.Server.Implementations/Sorting/TrailerCountComparer.cs new file mode 100644 index 000000000..2af2cdf9c --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/TrailerCountComparer.cs @@ -0,0 +1,71 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + public class TrailerCountComparer : IUserBaseItemComparer + { + /// + /// Gets or sets the user. + /// + /// The user. + public User User { get; set; } + + /// + /// Gets or sets the user manager. + /// + /// The user manager. + public IUserManager UserManager { get; set; } + + /// + /// Gets or sets the user data repository. + /// + /// The user data repository. + public IUserDataRepository UserDataRepository { get; set; } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return GetValue(x).CompareTo(GetValue(y)); + } + + /// + /// Gets the date. + /// + /// The x. + /// DateTime. + private int GetValue(BaseItem x) + { + var itemByName = x as IItemByName; + + if (itemByName != null) + { + var counts = itemByName.GetItemByNameCounts(User); + + if (counts != null) + { + return counts.TrailerCount; + } + } + + return 0; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.TrailerCount; } + } + } +} -- cgit v1.2.3