/// <summary> /// Gets the media objects having the specified <paramref name="rating" /> and belonging to the /// <paramref name="galleryId" />. /// </summary> /// <param name="rating">Identifies the type of rating to retrieve. Valid values: "highest", "lowest", "none", or a number /// from 0 to 5 in half-step increments (eg. 0, 0.5, 1, 1.5, ... 4.5, 5).</param> /// <param name="top">The maximum number of results to return. Must be greater than zero.</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="filter">A filter that limits the types of gallery objects that are returned.</param> /// <returns>An instance of <see cref="IAlbum" />.</returns> /// <exception cref="ArgumentException">Thrown when <paramref name="top" /> is less than or equal to zero.</exception> public static IAlbum GetRatedMediaObjects(string rating, int top, int galleryId, GalleryObjectType filter) { if (top <= 0) throw new ArgumentException("The top parameter must contain a number greater than zero.", "top"); var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = VirtualAlbumType.Rated; tmpAlbum.Title = GetRatedAlbumTitle(rating); tmpAlbum.Caption = String.Empty; var ratingSortTrigger = new[] {"lowest", "highest"}; if (ratingSortTrigger.Contains(rating)) { // Sort on rating field for lowest or highest. All others use the default album sort setting. tmpAlbum.SortByMetaName = MetadataItemName.Rating; tmpAlbum.SortAscending = !rating.Equals("highest", StringComparison.OrdinalIgnoreCase); } var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions { SearchType = GalleryObjectSearchType.SearchByRating, SearchTerms = new [] { rating }, GalleryId = galleryId, Roles = RoleController.GetGalleryServerRolesForUser(), IsUserAuthenticated = Utils.IsAuthenticated, MaxNumberResults = top, Filter = filter }); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return tmpAlbum; }
//public static IQueryable<GalleryItem> GetGalleryItemsHavingTags(string[] tags, string[] people, int galleryId, MetadataItemName sortByMetaName, bool sortAscending, GalleryObjectType filter) //{ // IAlbum album = GetGalleryObjectsHavingTags(tags, people, filter, galleryId); // IList<IGalleryObject> galleryObjects; // if (MetadataItemNameEnumHelper.IsValidFormattedMetadataItemName(sortByMetaName)) // { // galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(sortByMetaName, sortAscending, album.GalleryId); // } // else // { // galleryObjects = album.GetChildGalleryObjects(GalleryObjectType.All, !Utils.IsAuthenticated).ToSortedList(); // } // return ToGalleryItems(galleryObjects).AsQueryable(); //} /// <summary> /// Return a virtual album containing gallery objects whose title or caption contain the specified search strings and /// for which the current user has authorization to view. Guaranteed to not return null. A gallery /// object is considered a match when all search terms are found in the relevant fields. /// </summary> /// <param name="searchStrings">The strings to search for.</param> /// <param name="filter">A filter that limits the types of gallery objects that are returned. /// Maps to the <see cref="GalleryObjectType" /> enumeration.</param> /// <param name="galleryId">The ID for the gallery containing the objects to search.</param> /// <returns> /// Returns an <see cref="IAlbum" /> containing the matching items. This may include albums and media /// objects from different albums. /// </returns> public static IAlbum GetGalleryObjectsHavingTitleOrCaption(string[] searchStrings, GalleryObjectType filter, int galleryId) { if (searchStrings == null) throw new ArgumentNullException(); var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = VirtualAlbumType.TitleOrCaption; tmpAlbum.Title = String.Concat(Resources.GalleryServerPro.Site_Search_Title, String.Join(Resources.GalleryServerPro.Site_Search_Concat, searchStrings)); tmpAlbum.Caption = String.Empty; var searchOptions = new GalleryObjectSearchOptions { GalleryId = galleryId, SearchType = GalleryObjectSearchType.SearchByTitleOrCaption, SearchTerms = searchStrings, IsUserAuthenticated = Utils.IsAuthenticated, Roles = RoleController.GetGalleryServerRolesForUser(), Filter = filter }; var searcher = new GalleryObjectSearcher(searchOptions); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return tmpAlbum; }
/// <summary> /// Gets the gallery objects most recently added to the gallery having <paramref name="galleryId" />. /// </summary> /// <param name="top">The maximum number of results to return. Must be greater than zero.</param> /// <param name="galleryId">The gallery ID.</param> /// <param name="filter">A filter that limits the types of gallery objects that are returned.</param> /// <returns>An instance of <see cref="IAlbum" />.</returns> /// <exception cref="ArgumentException">Thrown when <paramref name="top" /> is less than or equal to zero.</exception> public static IAlbum GetMostRecentlyAddedGalleryObjects(int top, int galleryId, GalleryObjectType filter) { if (top <= 0) throw new ArgumentException("The top parameter must contain a number greater than zero.", "top"); var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = VirtualAlbumType.MostRecentlyAdded; tmpAlbum.Title = Resources.GalleryServerPro.Site_Recently_Added_Title; tmpAlbum.Caption = String.Empty; tmpAlbum.SortByMetaName = MetadataItemName.DateAdded; tmpAlbum.SortAscending = false; var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions { SearchType = GalleryObjectSearchType.MostRecentlyAdded, GalleryId = galleryId, Roles = RoleController.GetGalleryServerRolesForUser(), IsUserAuthenticated = Utils.IsAuthenticated, MaxNumberResults = top, Filter = filter }); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return tmpAlbum; }
/// <summary> /// Gets a virtual album containing gallery objects that match the specified <paramref name="tags" /> or <paramref name="people" /> /// belonging to the specified <paramref name="galleryId" />. Guaranteed to not return null. The returned album /// is a virtual one (<see cref="IAlbum.IsVirtualAlbum" />=<c>true</c>) containing the collection of matching /// items the current user has permission to view. Returns an empty album when no matches are found or the /// query string does not contain the search terms. /// </summary> /// <param name="tags">The tags to search for. If specified, the <paramref name="people" /> parameter must be null.</param> /// <param name="people">The people to search for. If specified, the <paramref name="tags" /> parameter must be null.</param> /// <param name="filter">A filter that limits the types of gallery objects that are returned. /// Maps to the <see cref="GalleryObjectType" /> enumeration.</param> /// <param name="galleryId">The ID of the gallery. Only objects in this gallery are returned.</param> /// <returns>An instance of <see cref="IAlbum" />.</returns> /// <exception cref="System.ArgumentException">Throw when the tags and people parameters are both null or empty, or both /// have values.</exception> public static IAlbum GetGalleryObjectsHavingTags(string[] tags, string[] people, GalleryObjectType filter, int galleryId) { if (((tags == null) || (tags.Length == 0)) && ((people == null) || (people.Length == 0))) throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires the tags or people parameters to be specified, but they were both null or empty."); if ((tags != null) && (tags.Length > 0) && (people != null) && (people.Length > 0)) throw new ArgumentException("GalleryObjectController.GetGalleryObjectsHavingTags() requires EITHER the tags or people parameters to be specified, but not both. Instead, they were both populated."); var searchType = (tags != null && tags.Length > 0 ? GalleryObjectSearchType.SearchByTag : GalleryObjectSearchType.SearchByPeople); var searchTags = (searchType == GalleryObjectSearchType.SearchByTag ? tags : people); var tmpAlbum = Factory.CreateEmptyAlbumInstance(galleryId); tmpAlbum.IsVirtualAlbum = true; tmpAlbum.VirtualAlbumType = (searchType == GalleryObjectSearchType.SearchByTag ? VirtualAlbumType.Tag : VirtualAlbumType.People); tmpAlbum.Title = String.Concat(Resources.GalleryServerPro.Site_Tag_Title, String.Join(Resources.GalleryServerPro.Site_Search_Concat, searchTags)); tmpAlbum.Caption = String.Empty; var searcher = new GalleryObjectSearcher(new GalleryObjectSearchOptions { SearchType = searchType, Tags = searchTags, GalleryId = galleryId, Roles = RoleController.GetGalleryServerRolesForUser(), IsUserAuthenticated = Utils.IsAuthenticated, Filter = filter }); foreach (var galleryObject in searcher.Find()) { tmpAlbum.AddGalleryObject(galleryObject); } return tmpAlbum; }