// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   ContentManager.java

package com.keyshop.shop.content.manager;

import com.keyshop.pub.util.Pager;
import com.keyshop.pub.util.StringUtil;
import com.keyshop.shop.content.bo.*;
import com.keyshop.shop.content.model.*;
import java.util.*;

public class ContentManager
{

    public ContentManager()
    {
    }

    public static List getContentsByCategoryId(String categoryId)
    {
        return getContentsByCategoryId(categoryId, null);
    }

    public static List getContentsByCategoryId(String categoryId, Pager pager)
    {
        try
        {
            ContentBO bo = new ContentBO();
            String sql = "from Content as c where c.categoryId='" + categoryId + "'";
            sql = sql + " order by c.createTime desc";
            List list = null;
            if(pager != null)
                list = bo.list(pager, sql);
            else
                list = bo.list(sql);
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public List getAllAdLink()
    {
        try
        {
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list("from AdLink as adLink");
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public List getAdLinksByChannel(String channelId)
    {
        try
        {
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list("from AdLink as adLink where adLink.channelId='" + channelId + "'   order by adLink.index asc");
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static List getPhotoAdLinksByChannel(String channelId)
    {
        try
        {
            String sql = "from AdLink as adLink where adLink.navImage is not null and adLink.navImage != ''";
            if(!StringUtil.isEmpty(channelId))
                sql = sql + " and adLink.channelId='" + channelId + "'";
            sql = sql + " order by adLink.index asc";
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list(sql);
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static Inquisition getInquisitionObject(String id)
    {
        try
        {
            InquisitionBO bo = new InquisitionBO();
            Inquisition inq = (Inquisition)bo.get(id);
            return inq;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static ContentCategory getContentCategoryById(String id)
    {
        try
        {
            ContentCategoryBO bo = new ContentCategoryBO();
            ContentCategory category = (ContentCategory)bo.get(id);
            return category;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static List getInquisitionsByChannel(String channelId)
    {
        String sql = "from Inquisition as iq";
        if(!StringUtil.isEmpty(channelId))
            sql = sql + " where iq.channelId='" + channelId + "'";
        try
        {
            InquisitionBO bo = new InquisitionBO();
            List its = bo.list(sql);
            return its;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static void addInquisitionCount(String inId, String inResultId)
    {
        if(StringUtil.isEmpty(inId) || StringUtil.isEmpty(inResultId))
            return;
        try
        {
            InquisitionBO bo = new InquisitionBO();
            Inquisition inl = (Inquisition)bo.get(inId);
            Set childs = inl.getChildList();
            if(childs != null)
            {
                for(Iterator cis = childs.iterator(); cis.hasNext();)
                {
                    InquisitionResult ir = (InquisitionResult)cis.next();
                    if(ir.getId().equals(inResultId))
                        ir.setCount(ir.getCount() + 1);
                }

            }
            bo.updateBean(inl);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }

    public static List getTextAdLinksByChannel(String channelId)
    {
        try
        {
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list("from AdLink as adLink where (adLink.navImage is null or adLink.navImage = '') and adLink.channelId='" + channelId + "'   order by adLink.index asc");
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static List getAllTextAdLinks()
    {
        try
        {
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list("from AdLink as adLink where (adLink.navImage is null or adLink.navImage = '')  order by adLink.index asc");
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

    public static List getAllPhotoAdLinks()
    {
        try
        {
            AdLinkBO bo = new AdLinkBO();
            List list = bo.list("from AdLink as adLink where (adLink.navImage is not null and adLink.navImage != '')  order by adLink.index asc");
            return list;
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
}
