Person.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 CreatePresentationUniqueKey()
  27. {
  28. return GetUserDataKeys()[0];
  29. }
  30. public PersonLookupInfo GetLookupInfo()
  31. {
  32. return GetItemLookupInfo<PersonLookupInfo>();
  33. }
  34. public IEnumerable<BaseItem> GetTaggedItems(InternalItemsQuery query)
  35. {
  36. query.Person = Name;
  37. return LibraryManager.GetItemList(query);
  38. }
  39. /// <summary>
  40. /// Returns the folder containing the item.
  41. /// If the item is a folder, it returns the folder itself
  42. /// </summary>
  43. /// <value>The containing folder path.</value>
  44. [IgnoreDataMember]
  45. public override string ContainingFolderPath
  46. {
  47. get
  48. {
  49. return Path;
  50. }
  51. }
  52. public override bool CanDelete()
  53. {
  54. return false;
  55. }
  56. public override bool IsSaveLocalMetadataEnabled()
  57. {
  58. return true;
  59. }
  60. [IgnoreDataMember]
  61. public override bool EnableAlphaNumericSorting
  62. {
  63. get
  64. {
  65. return false;
  66. }
  67. }
  68. /// <summary>
  69. /// Gets a value indicating whether this instance is owned item.
  70. /// </summary>
  71. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  72. [IgnoreDataMember]
  73. public override bool IsOwnedItem
  74. {
  75. get
  76. {
  77. return false;
  78. }
  79. }
  80. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  81. {
  82. var itemsWithPerson = LibraryManager.GetItemIds(new InternalItemsQuery
  83. {
  84. Person = Name
  85. });
  86. return inputItems.Where(i => itemsWithPerson.Contains(i.Id));
  87. }
  88. public Func<BaseItem, bool> GetItemFilter()
  89. {
  90. return i => LibraryManager.GetPeople(i).Any(p => string.Equals(p.Name, Name, StringComparison.OrdinalIgnoreCase));
  91. }
  92. [IgnoreDataMember]
  93. public override bool SupportsPeople
  94. {
  95. get
  96. {
  97. return false;
  98. }
  99. }
  100. [IgnoreDataMember]
  101. public override bool SupportsAncestors
  102. {
  103. get
  104. {
  105. return false;
  106. }
  107. }
  108. }
  109. /// <summary>
  110. /// This is the small Person stub that is attached to BaseItems
  111. /// </summary>
  112. public class PersonInfo : IHasProviderIds
  113. {
  114. public PersonInfo()
  115. {
  116. ProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  117. }
  118. public Guid ItemId { get; set; }
  119. /// <summary>
  120. /// Gets or sets the name.
  121. /// </summary>
  122. /// <value>The name.</value>
  123. public string Name { get; set; }
  124. /// <summary>
  125. /// Gets or sets the role.
  126. /// </summary>
  127. /// <value>The role.</value>
  128. public string Role { get; set; }
  129. /// <summary>
  130. /// Gets or sets the type.
  131. /// </summary>
  132. /// <value>The type.</value>
  133. public string Type { get; set; }
  134. /// <summary>
  135. /// Gets or sets the sort order - ascending
  136. /// </summary>
  137. /// <value>The sort order.</value>
  138. public int? SortOrder { get; set; }
  139. public string ImageUrl { get; set; }
  140. public Dictionary<string, string> ProviderIds { get; set; }
  141. /// <summary>
  142. /// Returns a <see cref="System.String" /> that represents this instance.
  143. /// </summary>
  144. /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
  145. public override string ToString()
  146. {
  147. return Name;
  148. }
  149. public bool IsType(string type)
  150. {
  151. return string.Equals(Type, type, StringComparison.OrdinalIgnoreCase) || string.Equals(Role, type, StringComparison.OrdinalIgnoreCase);
  152. }
  153. }
  154. }