From ee1fa6e816f0bf836c21a5901bf3d282f6e45dfa Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 14 Aug 2012 12:06:46 -0400 Subject: Implemented some IBN functionality - GetPerson, GetYear, GetStudio, GetGenre --- MediaBrowser.Controller/Kernel.cs | 61 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'MediaBrowser.Controller/Kernel.cs') diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 8eed678ba..a8baec835 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -314,6 +314,14 @@ namespace MediaBrowser.Controller return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.Genres != null && f.Genres.Any(s => s.Equals(genre, StringComparison.OrdinalIgnoreCase))); } + /// + /// Finds all recursive items within a top-level parent that contain the given year and are allowed for the current user + /// + public IEnumerable GetItemsWithYear(Folder parent, int year, Guid userId) + { + return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.ProductionYear.HasValue && f.ProductionYear == year); + } + /// /// Finds all recursive items within a top-level parent that contain the given person and are allowed for the current user /// @@ -322,6 +330,57 @@ namespace MediaBrowser.Controller return GetParentalAllowedRecursiveChildren(parent, userId).Where(f => f.People != null && f.People.Any(s => s.Name.Equals(personName, StringComparison.OrdinalIgnoreCase))); } + /// + /// Gets all years from all recursive children of a folder + /// The CategoryInfo class is used to keep track of the number of times each year appears + /// + public IEnumerable> GetAllYears(Folder parent, Guid userId) + { + Dictionary data = new Dictionary(); + + // Get all the allowed recursive children + IEnumerable allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId); + + foreach (var item in allItems) + { + // Add the year from the item to the data dictionary + // If the year already exists, increment the count + if (item.ProductionYear == null) + { + continue; + } + + if (!data.ContainsKey(item.ProductionYear.Value)) + { + data.Add(item.ProductionYear.Value, 1); + } + else + { + data[item.ProductionYear.Value]++; + } + } + + // Now go through the dictionary and create a Category for each studio + List> list = new List>(); + + foreach (int key in data.Keys) + { + // Get the original entity so that we can also supply the PrimaryImagePath + Year entity = Kernel.Instance.ItemController.GetYear(key); + + if (entity != null) + { + list.Add(new CategoryInfo() + { + Item = entity, + ItemCount = data[key] + }); + } + } + + return list; + } + /// /// Gets all studios from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each studio appears @@ -441,7 +500,7 @@ namespace MediaBrowser.Controller User user = new User(); user.Name = "Default User"; - user.Id = Guid.NewGuid(); + user.Id = Guid.Parse("5d1cf7fce25943b790d140095457a42b"); list.Add(user); -- cgit v1.2.3