| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using MediaBrowser.Model.Entities; |
| | | 5 | | using MediaBrowser.Model.Querying; |
| | | 6 | | |
| | | 7 | | namespace MediaBrowser.Controller.Dto |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Options that control which fields and images are populated when building a <see cref="MediaBrowser.Model.Dto.Bas |
| | | 11 | | /// </summary> |
| | | 12 | | public class DtoOptions |
| | | 13 | | { |
| | 3 | 14 | | private static readonly ItemFields[] DefaultExcludedFields = |
| | 3 | 15 | | [ |
| | 3 | 16 | | ItemFields.SeasonUserData, |
| | 3 | 17 | | ItemFields.RefreshState |
| | 3 | 18 | | ]; |
| | | 19 | | |
| | 3 | 20 | | private static readonly ImageType[] AllImageTypes = Enum.GetValues<ImageType>(); |
| | | 21 | | |
| | 3 | 22 | | private static readonly ItemFields[] AllItemFields = Enum.GetValues<ItemFields>() |
| | 3 | 23 | | .Except(DefaultExcludedFields) |
| | 3 | 24 | | .ToArray(); |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Initializes a new instance of the <see cref="DtoOptions"/> class with all fields enabled. |
| | | 28 | | /// </summary> |
| | | 29 | | public DtoOptions() |
| | 692 | 30 | | : this(true) |
| | | 31 | | { |
| | 692 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Initializes a new instance of the <see cref="DtoOptions"/> class. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="allFields">Whether to populate all available fields.</param> |
| | | 38 | | public DtoOptions(bool allFields) |
| | | 39 | | { |
| | 959 | 40 | | ImageTypeLimit = int.MaxValue; |
| | 959 | 41 | | EnableImages = true; |
| | 959 | 42 | | EnableUserData = true; |
| | 959 | 43 | | AddCurrentProgram = true; |
| | | 44 | | |
| | 959 | 45 | | Fields = allFields ? AllItemFields : []; |
| | 959 | 46 | | ImageTypes = AllImageTypes; |
| | 959 | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// Gets or sets the fields to populate on the DTO. |
| | | 51 | | /// </summary> |
| | | 52 | | public IReadOnlyList<ItemFields> Fields { get; set; } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Gets or sets the image types to populate on the DTO. |
| | | 56 | | /// </summary> |
| | | 57 | | public IReadOnlyList<ImageType> ImageTypes { get; set; } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// Gets or sets the maximum number of images to return per image type. |
| | | 61 | | /// </summary> |
| | | 62 | | public int ImageTypeLimit { get; set; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets or sets a value indicating whether image information is populated. |
| | | 66 | | /// </summary> |
| | | 67 | | public bool EnableImages { get; set; } |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Gets or sets a value indicating whether program recording information is populated. |
| | | 71 | | /// </summary> |
| | | 72 | | public bool AddProgramRecordingInfo { get; set; } |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Gets or sets a value indicating whether user data is populated. |
| | | 76 | | /// </summary> |
| | | 77 | | public bool EnableUserData { get; set; } |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets or sets a value indicating whether the currently airing program is populated. |
| | | 81 | | /// </summary> |
| | | 82 | | public bool AddCurrentProgram { get; set; } |
| | | 83 | | |
| | | 84 | | /// <summary> |
| | | 85 | | /// Gets or sets a value indicating whether an episode's portrait poster (its season's primary |
| | | 86 | | /// image, falling back to the series') should replace the episode's own (16:9) primary image. |
| | | 87 | | /// Used by views that render episodes as poster cards, e.g. "Latest". |
| | | 88 | | /// </summary> |
| | | 89 | | public bool PreferEpisodeParentPoster { get; set; } |
| | | 90 | | |
| | | 91 | | /// <summary> |
| | | 92 | | /// Gets a value indicating whether the specified field is populated. |
| | | 93 | | /// </summary> |
| | | 94 | | /// <param name="field">The field to check.</param> |
| | | 95 | | /// <returns><c>true</c> if the field is populated; otherwise, <c>false</c>.</returns> |
| | | 96 | | public bool ContainsField(ItemFields field) |
| | 1351 | 97 | | => Fields.Contains(field); |
| | | 98 | | |
| | | 99 | | /// <summary> |
| | | 100 | | /// Gets the number of images to return for the specified image type. |
| | | 101 | | /// </summary> |
| | | 102 | | /// <param name="type">The image type.</param> |
| | | 103 | | /// <returns>The image limit for the type, or 0 if the type is not enabled.</returns> |
| | | 104 | | public int GetImageLimit(ImageType type) |
| | | 105 | | { |
| | 33 | 106 | | if (EnableImages && ImageTypes.Contains(type)) |
| | | 107 | | { |
| | 33 | 108 | | return ImageTypeLimit; |
| | | 109 | | } |
| | | 110 | | |
| | 0 | 111 | | return 0; |
| | | 112 | | } |
| | | 113 | | } |
| | | 114 | | } |