Person.cs 4.1 KB

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