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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations