Person.cs 4.5 KB

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