/*
* DLOG_User_VelocityTool.java
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Author: Winter Lau (javayou@gmail.com)
* http://dlog4j.sourceforge.net
*/
package com.liusoft.dlog4j.velocity;
import java.util.List;
import org.hibernate.HibernateException;
import com.liusoft.dlog4j.SessionUserObject;
import com.liusoft.dlog4j.beans.MessageBean;
import com.liusoft.dlog4j.beans.SiteBean;
import com.liusoft.dlog4j.beans.UserBean;
import com.liusoft.dlog4j.dao.MessageDAO;
import com.liusoft.dlog4j.dao.UserDAO;
/**
* ���û���ص�Toolbox
* @author Winter Lau
*/
public class DLOG_User_VelocityTool {
/**
* �����û���Ż�ȡ�û�����ϸ��Ϣ(_global.vm)
*
* @param user_id
* @return
* @throws HibernateException
*/
public UserBean user(int user_id){
if (user_id <= 0)
return null;
UserBean user = UserDAO.getUserByID(user_id);
return user;
}
/**
* ��ȡע���û�����(users.vm)
* @param site
* @return
*/
public int user_count(SiteBean site){
if(site==null)
return -1;
return UserDAO.getUserCountFromSite(site.getId());
}
/**
* �г���ij����վ��ע����û�(_xxx_top_info.vm)
*
* @param site
* @param page
* @param count
* @return
*/
public List list_users(SiteBean site, int page, int count) {
if (site == null)
return null;
int fromidx = (page - 1) * count;
return UserDAO.listUsersFromSite(site.getId(), fromidx, count);
}
/**
* �г�ij����վע��������û�
* @param site
* @param page
* @param count
* @return
*/
public List online_users(SiteBean site, int page, int count){
if (site == null)
return null;
if(count<0)
count = 50;
int fromidx = (page - 1) * count;
if(fromidx < 0)
fromidx = 0;
return UserDAO.listOnlineUsers(site.getId(), fromidx, count);
}
/**
* ��ȡ�����û���
* @param site
* @return
*/
public int online_user_count(SiteBean site){
if (site == null)
return -1;
return UserDAO.getOnlineUserCount(site.getId());
}
/**
* ����ij�˵ĺ�����
* @param user_id
* @return
*/
public int friend_count(int user_id){
if (user_id <= 0)
return -1;
return UserDAO.getFriendCount(user_id);
}
/**
* �г�ij�˵ĺ���
* @param user_id
* @param page
* @param count
* @return
*/
public List friends(int user_id, int page, int count){
if (user_id <= 0)
return null;
int fromIdx = (page - 1) * count;
if(fromIdx < 0)
fromIdx = 0;
return UserDAO.listFriends(user_id, fromIdx, count);
}
/**
* �г�ij�˵ĺ������е������û�
* @param user_id
* @param page
* @param count
* @return
*/
public List black_users(int user_id, int page, int count){
if (user_id <= 0)
return null;
int fromIdx = (page - 1) * count;
if(fromIdx < 0)
fromIdx = 0;
return UserDAO.listBlackUsers(user_id, fromIdx, count);
}
/**
* ��ȡij�˵ĺ������û���
* @param user_id
* @return
*/
public int black_user_count(int user_id){
if (user_id <= 0)
return -1;
return UserDAO.getBlackUserCount(user_id);
}
/**
* ��ȡ����Ϣ����
* @param user
* @return
*/
public int msg_count(SessionUserObject user){
if(user == null)
return -1;
return MessageDAO.getMessageCount(user.getId());
}
/**
* �г�ij�˽��յ��Ķ���Ϣ
* @param user
* @param fromId
* @param count
* @return
*/
public List msgs(SessionUserObject user, int page, int count){
if(user == null)
return null;
int fromIdx = (page - 1) * count;
return MessageDAO.listMsgs(user.getId(), fromIdx, count);
}
/**
* �Ķ���������Ϣ
* @param msg
*/
public void read_msg(MessageBean msg){
if(msg != null)
MessageDAO.readMsg(msg);
}
}