using System;
using System.Collections.Generic;
using System.Web;
using TABS.MailCarrier.WebSDK.Board;

/// <summary>
/// 전체 일반 게시판에서 검색된 게시글을 GridView에 출력하기 위한 DataSource 클래스
/// </summary>
public class SearchAllArticlesDataSource
{
    private int _totalCount;

    public SearchAllArticlesDataSource()
    {
    }

    public Article[] GetArticles(string category, string keyword, int maximumRows, int startRowIndex)
    {
        _totalCount = 0;
        Article[] articles = null;
        UserBoard userBoard = new UserBoard(WebUser.CurrentUser.DomainUserID);
        if (keyword == "")
        {
            articles = new Article[0];
        }
        else
        {
            string subject = "", author = "", content = "";
            switch (category)
            {
                case "subject": subject = keyword; break;
                case "author": author = keyword; break;
                case "content": subject = content = keyword; break;
            }
            articles = userBoard.GetAllSearchedArticles(startRowIndex / maximumRows, maximumRows, subject, author, content, AppSetting.UseFulltextSearch, out _totalCount);
        }
        
        return articles;
    }

    public int GetTotalCount(string category, string keyword)
    {
        return _totalCount;
    }
}