Person.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using MediaBrowser.Controller.Providers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. using MediaBrowser.Common.Extensions;
  7. using MediaBrowser.Model.Entities;
  8. namespace MediaBrowser.Controller.Entities
  9. {
  10. /// <summary>
  11. /// This is the full Person object that can be retrieved with all of it's data.
  12. /// </summary>
  13. public class Person : BaseItem, IItemByName, IHasLookupInfo<PersonLookupInfo>
  14. {
  15. /// <summary>
  16. /// Gets or sets the place of birth.
  17. /// </summary>
  18. /// <value>The place of birth.</value>
  19. public string PlaceOfBirth { get; set; }
  20. public override List<string> GetUserDataKeys()
  21. {
  22. var list = base.GetUserDataKeys();
  23. list.Insert(0, GetType().Name + "-" + (Name ?? string.Empty).RemoveDiacritics());
  24. return list;
  25. }
  26. public override string PresentationUniqueKey
  27. {
  28. get
  29. {
  30. return GetUserDataKeys()[0];
  31. }
  32. }
  33. public PersonLookupInfo GetLookupInfo()
  34. {
  35. return GetItemLookupInfo<PersonLookupInfo>();
  36. }
  37. public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
  38. {
  39. query.Person = Name;
  40. return LibraryManager.GetItemList(query);
  41. }
  42. /// <summary>
  43. /// Returns the folder containing the item.
  44. /// If the item is a folder, it returns the folder itself
  45. /// </summary>
  46. /// <value>The containing folder path.</value>
  47. [IgnoreDataMember]
  48. public override string ContainingFolderPath
  49. {
  50. get
  51. {
  52. return Path;
  53. }
  54. }
  55. public override bool CanDelete()
  56. {
  57. return false;
  58. }
  59. public override bool IsSaveLocalMetadataEnabled()
  60. {
  61. return true;
  62. }
  63. [IgnoreDataMember]
  64. public override bool EnableAlphaNumericSorting
  65. {
  66. get
  67. {
  68. return false;
  69. }
  70. }
  71. /// <summary>
  72. /// Gets a value indicating whether this instance is owned item.
  73. /// </summary>
  74. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  75. [IgnoreDataMember]
  76. public override bool IsOwnedItem
  77. {
  78. get
  79. {
  80. return false;
  81. }
  82. }
  83. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  84. {
  85. var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
  86. {
  87. Person = Name
  88. });
  89. return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
  90. }
  91. public Func<BaseItem, bool> GetItemFilter()
  92. {
  93. return i => LibraryManager.GetPeople(i).Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase));
  94. }
  95. [IgnoreDataMember]
  96. public override bool SupportsPeople
  97. {
  98. get
  99. {
  100. return false;
  101. }
  102. }
  103. [IgnoreDataMember]
  104. public override bool SupportsAncestors
  105. {
  106. get
  107. {
  108. return false;
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// This is the small Person stub that is attached to BaseItems
  114. /// </summary>
  115. public class PersonInfo : IHasProviderIds
  116. {
  117. public PersonInfo()
  118. {
  119. ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  120. }
  121. public Guid ItemId { get; set; }
  122. /// <summary>
  123. /// Gets or sets the name.
  124. /// </summary>
  125. /// <value>The name.</value>
  126. public string Name { get; set; }
  127. /// <summary>
  128. /// Gets or sets the role.
  129. /// </summary>
  130. /// <value>The role.</value>
  131. public string Role { get; set; }
  132. /// <summary>
  133. /// Gets or sets the type.
  134. /// </summary>
  135. /// <value>The type.</value>
  136. public string Type { get; set; }
  137. /// <summary>
  138. /// Gets or sets the sort order - ascending
  139. /// </summary>
  140. /// <value>The sort order.</value>
  141. public int? SortOrder { get; set; }
  142. public string ImageUrl { get; set; }
  143. public Dictionary<string, string> ProviderIds { get; set; }
  144. /// <summary>
  145. /// Returns a <see cref="System.String" /> that represents this instance.
  146. /// </summary>
  147. /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
  148. public override string ToString()
  149. {
  150. return Name;
  151. }
  152. public bool IsType(string type)
  153. {
  154. return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(Role, type, StringComparison.OrdinalIgnoreCase);
  155. }
  156. }
  157. }