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/YearsHandler.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/YearsHandler.cs')
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/YearsHandler.cs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs index 801244b0d..071b980a7 100644 --- a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs @@ -17,7 +17,58 @@ namespace MediaBrowser.Api.HttpHandlers Guid userId = Guid.Parse(QueryString["userid"]);
User user = Kernel.Instance.Users.First(u => u.Id == userId);
- return Kernel.Instance.GetAllYears(parent, user);
+ return GetAllYears(parent, user);
+ }
+
+ /// <summary>
+ /// 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
+ /// </summary>
+ private IEnumerable<IBNItem<Year>> GetAllYears(Folder parent, User user)
+ {
+ Dictionary<int, int> data = new Dictionary<int, int>();
+
+ // Get all the allowed recursive children
+ IEnumerable<BaseItem> allItems = parent.GetParentalAllowedRecursiveChildren(user);
+
+ 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<IBNItem<Year>> list = new List<IBNItem<Year>>();
+
+ 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 IBNItem<Year>()
+ {
+ Item = entity,
+ BaseItemCount = data[key]
+ });
+ }
+ }
+
+ return list;
}
}
}
|
