Person.cs 4.5 KB

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