diff options
| author | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-17 15:07:21 -0400 |
|---|---|---|
| committer | LukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com> | 2012-08-17 15:07:21 -0400 |
| commit | f32f000298114231f114f41b7c7c4534a0300de2 (patch) | |
| tree | 2003655d230f2c9b1f40885663ec51ddf30ee89d /MediaBrowser.Api/HttpHandlers/GenresHandler.cs | |
| parent | ed018a8bea89f4a19dbfca2e21eb7207df2db332 (diff) | |
Removed more kernel methods and deprecated the Configuration and HtmlBrowser projects. They've both been replaced by the new WebDashboard project.
Diffstat (limited to 'MediaBrowser.Api/HttpHandlers/GenresHandler.cs')
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/GenresHandler.cs | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs index dd20d2e42..f7d259e45 100644 --- a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs @@ -17,7 +17,61 @@ namespace MediaBrowser.Api.HttpHandlers Guid userId = Guid.Parse(QueryString["userid"]);
User user = Kernel.Instance.Users.First(u => u.Id == userId);
- return Kernel.Instance.GetAllGenres(parent, user);
+ return GetAllGenres(parent, user);
+ }
+
+ /// <summary>
+ /// Gets all genres from all recursive children of a folder
+ /// The CategoryInfo class is used to keep track of the number of times each genres appears
+ /// </summary>
+ public IEnumerable<IBNItem<Genre>> GetAllGenres(Folder parent, User user)
+ {
+ Dictionary<string, int> data = new Dictionary<string, int>();
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
+
+ foreach (var item in allItems)
+ {
+ // Add each genre from the item to the data dictionary
+ // If the genre already exists, increment the count
+ if (item.Genres == null)
+ {
+ continue;
+ }
+
+ foreach (string val in item.Genres)
+ {
+ if (!data.ContainsKey(val))
+ {
+ data.Add(val, 1);
+ }
+ else
+ {
+ data[val]++;
+ }
+ }
+ }
+
+ // Now go through the dictionary and create a Category for each genre
+ List<IBNItem<Genre>> list = new List<IBNItem<Genre>>();
+
+ foreach (string key in data.Keys)
+ {
+ // Get the original entity so that we can also supply the PrimaryImagePath
+ Genre entity = Kernel.Instance.ItemController.GetGenre(key);
+
+ if (entity != null)
+ {
+ list.Add(new IBNItem<Genre>()
+ {
+ Item = entity,
+ BaseItemCount = data[key]
+ });
+ }
+ }
+
+ return list;
}
}
}
|
