//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Collections;
using CommunityServer;
using CommunityServer.Components;

namespace CommunityServer.Files.Components
{
	/// <summary>
	/// Summary description for Moderate.
	/// </summary>
	public class Moderate
	{

		public static ArrayList GetGroups()
		{
			Hashtable groupsTable = CommonDataProvider.Instance().GetGroups(ApplicationType.FileGallery, true);
			ArrayList groups = new ArrayList();

			foreach(Group group in groupsTable.Values)
			{
				group.HideSections = false;
				groups.Add(group);
			}

			return groups;
		}

		public static void ApprovePost(int postID)
		{
			FileGalleryDataProvider.Instance().ApprovePost(postID, CSContext.Current.User.UserID);
		}

		public static void DeletePost(int postID)
		{
			FileGalleryDataProvider.Instance().DeletePost(postID, CSContext.Current.User.UserID);
		}

		#region Folders to Moderate
		public static ArrayList GetFoldersToModerate()
		{
			return GetFoldersToModerate(CSContext.Current.User.UserID);
		}

		public static ArrayList GetFoldersToModerate(int userID) 
		{
			CSContext cntx = CSContext.Current;
			string cacheKey = "FoldersToModerate-" + userID;

			ArrayList list = cntx.Items[cacheKey] as ArrayList;

			if (list == null)
			{
				list = FileGalleryDataProvider.Instance().GetFoldersToModerate(userID);
				cntx.Context.Items[cacheKey] = list;
			}

			return list;
		}
		#endregion

		public static PostSet GetPosts(int sectionID, int pageIndex, int pageSize, int sortBy, int sortOrder) 
		{
			return FileGalleryDataProvider.Instance().GetEntriesToModerate(sectionID, pageIndex, pageSize, sortBy, sortOrder, CSContext.Current.User.UserID, true);
		}


		public static ArrayList GetFoldersByGroupID(int groupID)
		{
			ArrayList unfilteredFolders = GetFoldersToModerate();
			ArrayList folders = new ArrayList();

			foreach(Folder folder in unfilteredFolders) 
				if((folder.GroupID == groupID) && (folder.PostsToModerate > 0))
					folders.Add(folder);

			return folders;
		}
	
	}
}
