From cc19ce0daf3edb46d1acffdf2af98787cc9f7f5a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 11 Nov 2015 09:56:31 -0500 Subject: added new parent methods --- .../Entities/Audio/MusicAlbum.cs | 4 +- MediaBrowser.Controller/Entities/BaseItem.cs | 59 +++++++++++----------- MediaBrowser.Controller/Entities/Book.cs | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 28 +++------- .../Entities/IHiddenFromDisplay.cs | 18 +++++++ MediaBrowser.Controller/Entities/Movies/Movie.cs | 2 +- MediaBrowser.Controller/Entities/Photo.cs | 2 +- MediaBrowser.Controller/Entities/TV/Episode.cs | 2 +- MediaBrowser.Controller/Entities/TV/Season.cs | 2 +- MediaBrowser.Controller/Entities/Trailer.cs | 2 +- MediaBrowser.Controller/Entities/UserView.cs | 12 ++++- .../Entities/UserViewBuilder.cs | 4 +- MediaBrowser.Controller/Entities/Video.cs | 2 +- MediaBrowser.Controller/Library/ILibraryManager.cs | 3 +- MediaBrowser.Controller/Library/ItemResolveArgs.cs | 2 +- .../MediaBrowser.Controller.csproj | 1 + 16 files changed, 77 insertions(+), 68 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index 59481f5df..9a38912ea 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -30,7 +30,7 @@ namespace MediaBrowser.Controller.Entities.Audio { get { - return Parents.OfType().FirstOrDefault(); + return GetParents().OfType().FirstOrDefault(); } } @@ -121,7 +121,7 @@ namespace MediaBrowser.Controller.Entities.Audio id.AlbumArtists = AlbumArtists; - var artist = Parents.OfType().FirstOrDefault(); + var artist = GetParents().OfType().FirstOrDefault(); if (artist != null) { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index d9b7b1ae7..d8bb51003 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -214,11 +214,6 @@ namespace MediaBrowser.Controller.Entities } } - public virtual bool IsHiddenFromUser(User user) - { - return false; - } - [IgnoreDataMember] public virtual bool IsOwnedItem { @@ -519,15 +514,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public Folder Parent { - get - { - if (ParentId != Guid.Empty) - { - return LibraryManager.GetItemById(ParentId) as Folder; - } - - return null; - } + get { return GetParent() as Folder; } set { @@ -542,16 +529,28 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] public IEnumerable Parents { - get + get { return GetParents().OfType(); } + } + + public BaseItem GetParent() + { + if (ParentId != Guid.Empty) { - var parent = Parent; + return LibraryManager.GetItemById(ParentId); + } - while (parent != null) - { - yield return parent; + return null; + } - parent = parent.Parent; - } + public IEnumerable GetParents() + { + var parent = GetParent(); + + while (parent != null) + { + yield return parent; + + parent = parent.GetParent(); } } @@ -563,13 +562,13 @@ namespace MediaBrowser.Controller.Entities public T FindParent() where T : Folder { - return Parents.OfType().FirstOrDefault(); + return GetParents().OfType().FirstOrDefault(); } [IgnoreDataMember] public virtual BaseItem DisplayParent { - get { return Parent; } + get { return GetParent(); } } /// @@ -869,7 +868,7 @@ namespace MediaBrowser.Controller.Entities [IgnoreDataMember] protected virtual bool SupportsOwnedItems { - get { return IsFolder || Parent != null; } + get { return IsFolder || GetParent() != null; } } [IgnoreDataMember] @@ -894,7 +893,7 @@ namespace MediaBrowser.Controller.Entities var localTrailersChanged = false; - if (LocationType == LocationType.FileSystem && Parent != null) + if (LocationType == LocationType.FileSystem && GetParent() != null) { var hasThemeMedia = this as IHasThemeMedia; if (hasThemeMedia != null) @@ -1056,7 +1055,7 @@ namespace MediaBrowser.Controller.Entities if (string.IsNullOrWhiteSpace(lang)) { - lang = Parents + lang = GetParents() .Select(i => i.PreferredMetadataLanguage) .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); } @@ -1086,7 +1085,7 @@ namespace MediaBrowser.Controller.Entities if (string.IsNullOrWhiteSpace(lang)) { - lang = Parents + lang = GetParents() .Select(i => i.PreferredMetadataCountryCode) .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); } @@ -1276,14 +1275,14 @@ namespace MediaBrowser.Controller.Entities return false; } - if (Parents.Any(i => !i.IsVisible(user))) + if (GetParents().Any(i => !i.IsVisible(user))) { return false; } if (checkFolders) { - var topParent = Parents.LastOrDefault() ?? this; + var topParent = GetParents().LastOrDefault() ?? this; if (string.IsNullOrWhiteSpace(topParent.Path)) { @@ -1937,7 +1936,7 @@ namespace MediaBrowser.Controller.Entities public virtual IEnumerable GetAncestorIds() { - return Parents.Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id)); + return GetParents().Select(i => i.Id).Concat(LibraryManager.GetCollectionFolders(this).Select(i => i.Id)); } [IgnoreDataMember] diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 1b4904509..f006fedd2 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Controller.Entities if (string.IsNullOrEmpty(SeriesName)) { - info.SeriesName = Parents.Select(i => i.Name).FirstOrDefault(); + info.SeriesName = GetParents().Select(i => i.Name).FirstOrDefault(); } else { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 97016baff..16413eeb4 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -825,19 +825,7 @@ namespace MediaBrowser.Controller.Entities return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager); } - /// - /// Gets allowed children of an item - /// - /// The user. - /// if set to true [include linked children]. - /// IEnumerable{BaseItem}. - /// public virtual IEnumerable GetChildren(User user, bool includeLinkedChildren) - { - return GetChildren(user, includeLinkedChildren, false); - } - - internal IEnumerable GetChildren(User user, bool includeLinkedChildren, bool includeHidden) { if (user == null) { @@ -849,7 +837,7 @@ namespace MediaBrowser.Controller.Entities var result = new Dictionary(); - AddChildren(user, includeLinkedChildren, result, includeHidden, false, null); + AddChildren(user, includeLinkedChildren, result, false, null); return result.Values; } @@ -865,29 +853,25 @@ namespace MediaBrowser.Controller.Entities /// The user. /// if set to true [include linked children]. /// The result. - /// if set to true [include hidden]. /// if set to true [recursive]. /// The filter. /// true if XXXX, false otherwise - private void AddChildren(User user, bool includeLinkedChildren, Dictionary result, bool includeHidden, bool recursive, Func filter) + private void AddChildren(User user, bool includeLinkedChildren, Dictionary result, bool recursive, Func filter) { foreach (var child in GetEligibleChildrenForRecursiveChildren(user)) { if (child.IsVisible(user)) { - if (includeHidden || !child.IsHiddenFromUser(user)) + if (filter == null || filter(child)) { - if (filter == null || filter(child)) - { - result[child.Id] = child; - } + result[child.Id] = child; } if (recursive && child.IsFolder) { var folder = (Folder)child; - folder.AddChildren(user, includeLinkedChildren, result, includeHidden, true, filter); + folder.AddChildren(user, includeLinkedChildren, result, true, filter); } } } @@ -928,7 +912,7 @@ namespace MediaBrowser.Controller.Entities var result = new Dictionary(); - AddChildren(user, true, result, false, true, filter); + AddChildren(user, true, result, true, filter); return result.Values; } diff --git a/MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs b/MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs new file mode 100644 index 000000000..82d581fcf --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHiddenFromDisplay.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Entities +{ + public interface IHiddenFromDisplay + { + /// + /// Determines whether the specified user is hidden. + /// + /// The user. + /// true if the specified user is hidden; otherwise, false. + bool IsHiddenFromUser(User user); + } +} diff --git a/MediaBrowser.Controller/Entities/Movies/Movie.cs b/MediaBrowser.Controller/Entities/Movies/Movie.cs index 60642543f..749d562ac 100644 --- a/MediaBrowser.Controller/Entities/Movies/Movie.cs +++ b/MediaBrowser.Controller/Entities/Movies/Movie.cs @@ -130,7 +130,7 @@ namespace MediaBrowser.Controller.Entities.Movies // Must have a parent to have special features // In other words, it must be part of the Parent/Child tree - if (LocationType == LocationType.FileSystem && Parent != null && !IsInMixedFolder) + if (LocationType == LocationType.FileSystem && GetParent() != null && !IsInMixedFolder) { var specialFeaturesChanged = await RefreshSpecialFeatures(options, fileSystemChildren, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Entities/Photo.cs b/MediaBrowser.Controller/Entities/Photo.cs index 859d327b3..308e61590 100644 --- a/MediaBrowser.Controller/Entities/Photo.cs +++ b/MediaBrowser.Controller/Entities/Photo.cs @@ -49,7 +49,7 @@ namespace MediaBrowser.Controller.Entities { get { - return Parents.OfType().FirstOrDefault(); + return GetParents().OfType().FirstOrDefault(); } } diff --git a/MediaBrowser.Controller/Entities/TV/Episode.cs b/MediaBrowser.Controller/Entities/TV/Episode.cs index 86893f6d4..d4f829917 100644 --- a/MediaBrowser.Controller/Entities/TV/Episode.cs +++ b/MediaBrowser.Controller/Entities/TV/Episode.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Controller.Entities.TV { get { - return Season ?? Parent; + return Season ?? GetParent(); } } diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index 44bf1c6cc..93eac058d 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.Entities.TV [IgnoreDataMember] public override BaseItem DisplayParent { - get { return Series ?? Parent; } + get { return Series ?? GetParent(); } } // Genre, Rating and Stuido will all be the same diff --git a/MediaBrowser.Controller/Entities/Trailer.cs b/MediaBrowser.Controller/Entities/Trailer.cs index d37e2be93..3c7d39e0d 100644 --- a/MediaBrowser.Controller/Entities/Trailer.cs +++ b/MediaBrowser.Controller/Entities/Trailer.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.Controller.Entities get { // Local trailers are not part of children - return Parent == null; + return GetParent() == null; } } diff --git a/MediaBrowser.Controller/Entities/UserView.cs b/MediaBrowser.Controller/Entities/UserView.cs index 940e99f12..f14ba568b 100644 --- a/MediaBrowser.Controller/Entities/UserView.cs +++ b/MediaBrowser.Controller/Entities/UserView.cs @@ -38,6 +38,10 @@ namespace MediaBrowser.Controller.Entities { list.Add(ParentId); } + else + { + list.Add(Id); + } return list; } @@ -125,10 +129,14 @@ namespace MediaBrowser.Controller.Entities { var standaloneTypes = new List { - CollectionType.Playlists, - CollectionType.BoxSets + CollectionType.Playlists }; + if (!ConfigurationManager.Configuration.EnableSharedCollectionViewImage) + { + standaloneTypes.Add(CollectionType.BoxSets); + } + var collectionFolder = folder as ICollectionFolder; if (collectionFolder == null) diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 87f45ec8e..7c588c910 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1073,7 +1073,7 @@ namespace MediaBrowser.Controller.Entities if (query.IsInBoxSet.HasValue) { var val = query.IsInBoxSet.Value; - if (item.Parents.OfType().Any() != val) + if (item.GetParents().OfType().Any() != val) { return false; } @@ -1511,7 +1511,7 @@ namespace MediaBrowser.Controller.Entities .Where(i => !UserView.IsExcludedFromGrouping(i)); } return user.RootFolder - .GetChildren(user, true, true) + .GetChildren(user, true) .OfType() .Where(i => user.IsFolderGrouped(i.Id) && !UserView.IsExcludedFromGrouping(i)); } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 62d1bc7a1..2a59dd7f7 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -352,7 +352,7 @@ namespace MediaBrowser.Controller.Entities // Must have a parent to have additional parts or alternate versions // In other words, it must be part of the Parent/Child tree // The additional parts won't have additional parts themselves - if (LocationType == LocationType.FileSystem && Parent != null) + if (LocationType == LocationType.FileSystem && GetParent() != null) { if (!IsStacked) { diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 4a9ee312f..75836f288 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -548,10 +548,9 @@ namespace MediaBrowser.Controller.Library /// Gets the items. /// /// The query. - /// The user. /// The parent ids. /// List<BaseItem>. - IEnumerable GetItems(InternalItemsQuery query, User user, IEnumerable parentIds); + IEnumerable GetItems(InternalItemsQuery query, IEnumerable parentIds); /// /// Gets the items result. diff --git a/MediaBrowser.Controller/Library/ItemResolveArgs.cs b/MediaBrowser.Controller/Library/ItemResolveArgs.cs index 90158942f..cd20da35a 100644 --- a/MediaBrowser.Controller/Library/ItemResolveArgs.cs +++ b/MediaBrowser.Controller/Library/ItemResolveArgs.cs @@ -155,7 +155,7 @@ namespace MediaBrowser.Controller.Library // Not officially supported but in some cases we can handle it. if (item == null) { - item = parent.Parents.OfType().FirstOrDefault(); + item = parent.GetParents().OfType().FirstOrDefault(); } return item != null; diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index bcf4de2a2..4dbeffb3d 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -162,6 +162,7 @@ + -- cgit v1.2.3