Hi,
I'll try to show you how to implement this by following few steps:
1. Place the
PhotoListView WebPart on the page where you want to show the photos from specific album
...
<%@ Register Src="/MonoX/ModuleGallery/SocialNetworking/PhotoGallery/PhotoListView.ascx" TagPrefix="MonoX" TagName="PhotoListView" %>
...
<
MonoX:PhotoListView
ID
=
"photoListView"
runat
=
"server"
>
</
MonoX:PhotoListView
>
...
2. Use
AlbumRepository to get the album(s) you need and to show the photos from that album
This will return the albums for specified user or group with certain privacy levels (Public, Private, etc.) and the result will be pages so no need to worry about the optimization.
...
MonoSoftware.MonoX.Repositories.AlbumRepository.GetInstance().GetAlbums(Guid? userId, Guid? groupId, List<Guid> privacyLevelIds,
bool
fullPrefetchPath,
int
pageIndex,
int
pageSize,
out
int
recordCount)
...
or you can get the new albums by calling the following method
...
MonoSoftware.MonoX.Repositories.AlbumRepository.GetInstance().GetNewAlbums(List<Guid> privacyLevels, AlbumSortCriteria sortBy,
bool
onlyWithCover,
int
pageIndex,
int
pageSize,
out
int
recordCount)
...
If you need to search for album with specific name you can use the code below to do so
...
/// <summary>
/// Retrieves a collection of album entities for the paging scenarios.
/// </summary>
/// <param name="searchPhrase">User ID.</param>
/// <param name="userId">User ID.</param>
/// <param name="groupId">Group ID.</param>
/// <param name="privacyLevelIds">Privacy level ids</param>
/// <param name="fullPrefetchPath">Include full prefetch path</param>
/// <param name="pageIndex">Page index.</param>
/// <param name="pageSize">Page size.</param>
/// <param name="recordCount">Record count.</param>
/// <returns>Collection of album entities that satisfy the criteria from the parameter list.</returns>
public
virtual
EntityCollection<SnAlbumEntity> GetAlbums(
string
searchPhrase, Guid? userId, Guid? groupId, List<Guid> privacyLevelIds,
bool
fullPrefetchPath,
int
pageIndex,
int
pageSize,
out
int
recordCount)
{
EntityCollection<SnAlbumEntity> albums =
new
EntityCollection<SnAlbumEntity>();
RelationPredicateBucket filter =
new
RelationPredicateBucket();
filter.PredicateExpression.Add(SnAlbumFields.ApplicationId == MembershipRepository.GetInstance().GetApplicationId());
filter.PredicateExpression.Add(SnAlbumFields.LanguageId == LocalizationUtility.GetCurrentLanguageId());
if
(groupId.HasValue)
{
filter.PredicateExpression.Add(SnAlbumFields.SnGroupId == groupId.GetValueOrDefault());
if
(userId.HasValue && !Guid.Empty.Equals(userId.GetValueOrDefault()))
filter.PredicateExpression.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
}
else
{
PredicateExpression peRoot =
new
PredicateExpression();
//Filter in user photo albums but exclude the group photo albums
PredicateExpression pe =
new
PredicateExpression();
pe.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
pe.Add(SnAlbumFields.SnGroupId == DBNull.Value);
peRoot.Add(pe);
if
(privacyLevelIds.Count > 0)
{
filter.Relations.Add(SnAlbumEntity.Relations.AspnetUsersEntityUsingUserId);
PredicateExpression pePrivacy =
new
PredicateExpression();
PredicateExpression peGroup =
new
PredicateExpression();
peGroup.Add(SnAlbumFields.SnGroupId == DBNull.Value);
if
(!(SecurityUtility.IsAdmin() || SecurityUtility.IsPhotoGalleryAdmin()))
{
PredicateExpression privacyFilter =
new
PredicateExpression();
PredicateExpression friendFilter =
new
PredicateExpression();
friendFilter.Add(SnAlbumFields.UserId == userId.GetValueOrDefault());
friendFilter.AddWithOr(FriendRepository.GetInstance().GetFriendshipFilter(userId.GetValueOrDefault()));
PredicateExpression friendPrivacyFilter = GetFriendPrivacyFilter();
friendFilter.Add(friendPrivacyFilter);
privacyFilter.AddWithOr(friendFilter);
pePrivacy.Add(privacyFilter);
}
pePrivacy.Add(peGroup);
peRoot.AddWithOr(pePrivacy);
}
filter.PredicateExpression.Add(peRoot);
}
AddPartialPhraseSearch(filter, SnAlbumFields.Name, searchPhrase);
AddWithOrPartialPhraseSearch(filter, SnAlbumFields.Description, searchPhrase);
ISortExpression sorter =
new
SortExpression(SnAlbumFields.DateCreated | SortOperator.Descending);
FetchEntityCollection(albums, filter, 0, sorter, GetPrefetchPath(fullPrefetchPath), pageIndex, pageSize);
InitAlbumCovers(albums);
recordCount = GetDbCount(albums, filter);
return
albums;
}
...
3. After you fetch the albums choose the album you want and set the
AlbumId of the
PhotoListView WebPart
if
(!AlbumId.Equals(Guid.Empty))
photoListView.AlbumId = AlbumId;
photoListView.ContentProviderTypeName = MonoSoftware.MonoX.FileSystem.FileContentManager.DefaultProviderTypeName;
photoListView.DataBind(isRebind);
BTW can you please open a separate topics for things like this - we are not talking about the Photo gallery and topic is related to File Gallery :)
Regards