Person.cs 4.7 KB

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