PlayCountComparer.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Sorting;
  3. using MediaBrowser.Model.Querying;
  4. namespace MediaBrowser.Server.Implementations.Sorting
  5. {
  6. /// <summary>
  7. /// Class PlayCountComparer
  8. /// </summary>
  9. public class PlayCountComparer : IUserBaseItemComparer
  10. {
  11. /// <summary>
  12. /// Gets or sets the user.
  13. /// </summary>
  14. /// <value>The user.</value>
  15. public User User { get; set; }
  16. /// <summary>
  17. /// Compares the specified x.
  18. /// </summary>
  19. /// <param name="x">The x.</param>
  20. /// <param name="y">The y.</param>
  21. /// <returns>System.Int32.</returns>
  22. public int Compare(BaseItem x, BaseItem y)
  23. {
  24. return GetValue(x).CompareTo(GetValue(y));
  25. }
  26. /// <summary>
  27. /// Gets the date.
  28. /// </summary>
  29. /// <param name="x">The x.</param>
  30. /// <returns>DateTime.</returns>
  31. private int GetValue(BaseItem x)
  32. {
  33. var userdata = x.GetUserData(User, false);
  34. return userdata == null ? 0 : userdata.PlayCount;
  35. }
  36. /// <summary>
  37. /// Gets the name.
  38. /// </summary>
  39. /// <value>The name.</value>
  40. public string Name
  41. {
  42. get { return ItemSortBy.PlayCount; }
  43. }
  44. }
  45. }