From 06298d489c5e1e9689b1ca4853fd27787057a1ca Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 10 Sep 2013 15:57:38 -0400 Subject: fixes #530 - Add ability to sort movie genres/studios/people by movie or trailer count --- .../Sorting/EpisodeCountComparer.cs | 76 ++++++++++++++++++++++ .../Sorting/SeriesCountComparer.cs | 76 ++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 MediaBrowser.Server.Implementations/Sorting/EpisodeCountComparer.cs create mode 100644 MediaBrowser.Server.Implementations/Sorting/SeriesCountComparer.cs (limited to 'MediaBrowser.Server.Implementations/Sorting') diff --git a/MediaBrowser.Server.Implementations/Sorting/EpisodeCountComparer.cs b/MediaBrowser.Server.Implementations/Sorting/EpisodeCountComparer.cs new file mode 100644 index 000000000..4296f3f3a --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/EpisodeCountComparer.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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 +{ + class EpisodeCountComparer : 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.EpisodeCount; + } + } + + return 0; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.EpisodeCount; } + } + } +} diff --git a/MediaBrowser.Server.Implementations/Sorting/SeriesCountComparer.cs b/MediaBrowser.Server.Implementations/Sorting/SeriesCountComparer.cs new file mode 100644 index 000000000..33da4cec3 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/SeriesCountComparer.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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 +{ + class SeriesCountComparer : 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.SeriesCount; + } + } + + return 0; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.SeriesCount; } + } + } +} -- cgit v1.2.3