Search in sources :

Example 1 with KarmaStatus

use of net.jforum.entities.KarmaStatus in project jforum2 by rafaelsteil.

the class GenericKarmaDAO method getUserTotalKarma.

public void getUserTotalKarma(User user) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getUserTotalVotes"));
        p.setInt(1, user.getId());
        rs = p.executeQuery();
        user.setKarma(new KarmaStatus());
        if (rs.next()) {
            user.getKarma().setTotalPoints(rs.getInt("points"));
            user.getKarma().setVotesReceived(rs.getInt("votes"));
        }
        if (// prevetns division by
        user.getKarma().getVotesReceived() != 0)
            // zero.
            user.getKarma().setKarmaPoints(user.getKarma().getTotalPoints() / user.getKarma().getVotesReceived());
        this.getVotesGiven(user);
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 2 with KarmaStatus

use of net.jforum.entities.KarmaStatus in project jforum2 by rafaelsteil.

the class GenericUserDAO method processSelectAll.

protected List processSelectAll(ResultSet rs) throws SQLException {
    List list = new ArrayList();
    while (rs.next()) {
        User u = new User();
        u.setEmail(rs.getString("user_email"));
        u.setId(rs.getInt("user_id"));
        u.setTotalPosts(rs.getInt("user_posts"));
        u.setRegistrationDate(new Date(rs.getTimestamp("user_regdate").getTime()));
        u.setUsername(rs.getString("username"));
        u.setDeleted(rs.getInt("deleted"));
        KarmaStatus karma = new KarmaStatus();
        karma.setKarmaPoints(rs.getInt("user_karma"));
        u.setKarma(karma);
        u.setFrom(rs.getString("user_from"));
        u.setWebSite(rs.getString("user_website"));
        u.setViewEmailEnabled(rs.getInt("user_viewemail") == 1);
        list.add(u);
    }
    return list;
}
Also used : User(net.jforum.entities.User) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 3 with KarmaStatus

use of net.jforum.entities.KarmaStatus in project jforum2 by rafaelsteil.

the class GenericKarmaDAO method getPostKarma.

/**
	 * @see net.jforum.dao.KarmaDAO#getPostKarma(int)
	 */
public KarmaStatus getPostKarma(int postId) {
    KarmaStatus karma = new KarmaStatus();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getPostKarma"));
        p.setInt(1, postId);
        rs = p.executeQuery();
        if (rs.next()) {
            karma.setKarmaPoints(Math.round(rs.getDouble(1)));
        }
        return karma;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 4 with KarmaStatus

use of net.jforum.entities.KarmaStatus in project jforum2 by rafaelsteil.

the class GenericKarmaDAO method getUserKarma.

/**
	 * @see net.jforum.dao.KarmaDAO#selectKarmaStatus(int)
	 */
public KarmaStatus getUserKarma(int userId) {
    KarmaStatus status = new KarmaStatus();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("KarmaModel.getUserKarma"));
        p.setInt(1, userId);
        rs = p.executeQuery();
        if (rs.next()) {
            status.setKarmaPoints(Math.round(rs.getDouble("user_karma")));
        }
        return status;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 5 with KarmaStatus

use of net.jforum.entities.KarmaStatus in project jforum2 by rafaelsteil.

the class GenericTopicDAO method topicPosters.

/**
	 * @see net.jforum.model.UserModel#topicPosters(int)
	 */
public Map topicPosters(int topicId) {
    Map m = new HashMap();
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        StringBuffer sql = new StringBuffer(SystemGlobals.getSql("TopicModel.topicPosters"));
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.distinctPosters"));
        p.setInt(1, topicId);
        rs = p.executeQuery();
        StringBuffer sb = new StringBuffer();
        while (rs.next()) {
            sb.append(rs.getInt("user_id")).append(',');
        }
        rs.close();
        p.close();
        int index = sql.indexOf(":ids:");
        if (index > -1) {
            sql.replace(index, index + 5, sb.substring(0, sb.length() - 1));
        }
        p = JForumExecutionContext.getConnection().prepareStatement(sql.toString());
        rs = p.executeQuery();
        while (rs.next()) {
            User u = new User();
            u.setId(rs.getInt("user_id"));
            u.setUsername(rs.getString("username"));
            u.setKarma(new KarmaStatus(u.getId(), rs.getDouble("user_karma")));
            u.setAvatar(rs.getString("user_avatar"));
            u.setAvatarEnabled(rs.getInt("user_allowavatar") == 1);
            u.setRegistrationDate(new Date(rs.getTimestamp("user_regdate").getTime()));
            u.setTotalPosts(rs.getInt("user_posts"));
            u.setFrom(rs.getString("user_from"));
            u.setEmail(rs.getString("user_email"));
            u.setRankId(rs.getInt("rank_id"));
            u.setViewEmailEnabled(rs.getInt("user_viewemail") == 1);
            u.setIcq(rs.getString("user_icq"));
            u.setAttachSignatureEnabled(rs.getInt("user_attachsig") == 1);
            u.setMsnm(rs.getString("user_msnm"));
            u.setYim(rs.getString("user_yim"));
            u.setWebSite(rs.getString("user_website"));
            u.setAim(rs.getString("user_aim"));
            u.setSignature(rs.getString("user_sig"));
            m.put(new Integer(u.getId()), u);
        }
        return m;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : User(net.jforum.entities.User) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) HashMap(java.util.HashMap) Map(java.util.Map) DatabaseException(net.jforum.exceptions.DatabaseException) KarmaStatus(net.jforum.entities.KarmaStatus) Date(java.util.Date)

Aggregations

KarmaStatus (net.jforum.entities.KarmaStatus)8 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 DatabaseException (net.jforum.exceptions.DatabaseException)4 Date (java.util.Date)3 User (net.jforum.entities.User)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 KarmaDAO (net.jforum.dao.KarmaDAO)1 PostDAO (net.jforum.dao.PostDAO)1 Karma (net.jforum.entities.Karma)1 Post (net.jforum.entities.Post)1