Search in sources :

Example 6 with KarmaStatus

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

the class KarmaAction method insert.

public void insert() {
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED)) {
        this.error("Karma.featureDisabled", null);
        return;
    }
    int postId = this.request.getIntParameter("post_id");
    int fromUserId = SessionFacade.getUserSession().getUserId();
    PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
    Post p = pm.selectById(postId);
    if (fromUserId == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
        this.error("Karma.anonymousIsDenied", p);
        return;
    }
    if (p.getUserId() == fromUserId) {
        this.error("Karma.cannotSelfVote", p);
        return;
    }
    KarmaDAO km = DataAccessDriver.getInstance().newKarmaDAO();
    if (!km.userCanAddKarma(fromUserId, postId)) {
        this.error("Karma.alreadyVoted", p);
        return;
    }
    // Check range
    int points = this.request.getIntParameter("points");
    if (points < SystemGlobals.getIntValue(ConfigKeys.KARMA_MIN_POINTS) || points > SystemGlobals.getIntValue(ConfigKeys.KARMA_MAX_POINTS)) {
        this.error("Karma.invalidRange", p);
        return;
    }
    Karma karma = new Karma();
    karma.setFromUserId(fromUserId);
    karma.setPostUserId(p.getUserId());
    karma.setPostId(postId);
    karma.setTopicId(p.getTopicId());
    karma.setPoints(points);
    km.addKarma(karma);
    p.setKarma(new KarmaStatus(p.getId(), points));
    if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
        PostRepository.update(p.getTopicId(), PostCommon.preparePostForDisplay(p));
    }
    JForumExecutionContext.setRedirect(this.urlToTopic(p));
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) KarmaDAO(net.jforum.dao.KarmaDAO) Karma(net.jforum.entities.Karma) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 7 with KarmaStatus

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

the class GenericUserDAO method fillUserFromResultSet.

protected void fillUserFromResultSet(User u, ResultSet rs) throws SQLException {
    u.setAim(rs.getString("user_aim"));
    u.setAvatar(rs.getString("user_avatar"));
    u.setGender(rs.getString("gender"));
    u.setRankId(rs.getInt("rank_id"));
    u.setThemeId(rs.getInt("themes_id"));
    u.setPrivateMessagesEnabled(rs.getInt("user_allow_pm") == 1);
    u.setNotifyOnMessagesEnabled(rs.getInt("user_notify") == 1);
    u.setViewOnlineEnabled(rs.getInt("user_viewonline") == 1);
    u.setPassword(rs.getString("user_password"));
    u.setViewEmailEnabled(rs.getInt("user_viewemail") == 1);
    u.setViewOnlineEnabled(rs.getInt("user_viewonline") == 1);
    u.setAvatarEnabled(rs.getInt("user_allowavatar") == 1);
    u.setBbCodeEnabled(rs.getInt("user_allowbbcode") == 1);
    u.setHtmlEnabled(rs.getInt("user_allowhtml") == 1);
    u.setSmiliesEnabled(rs.getInt("user_allowsmilies") == 1);
    u.setEmail(rs.getString("user_email"));
    u.setFrom(rs.getString("user_from"));
    u.setIcq(rs.getString("user_icq"));
    u.setId(rs.getInt("user_id"));
    u.setInterests(rs.getString("user_interests"));
    u.setBiography(rs.getString("user_biography"));
    u.setLastVisit(rs.getTimestamp("user_lastvisit"));
    u.setOccupation(rs.getString("user_occ"));
    u.setTotalPosts(rs.getInt("user_posts"));
    u.setRegistrationDate(new Date(rs.getTimestamp("user_regdate").getTime()));
    u.setSignature(rs.getString("user_sig"));
    u.setWebSite(rs.getString("user_website"));
    u.setYim(rs.getString("user_yim"));
    u.setUsername(rs.getString("username"));
    u.setAttachSignatureEnabled(rs.getInt("user_attachsig") == 1);
    u.setMsnm(rs.getString("user_msnm"));
    u.setLang(rs.getString("user_lang"));
    u.setActive(rs.getInt("user_active"));
    u.setKarma(new KarmaStatus(u.getId(), rs.getDouble("user_karma")));
    u.setNotifyPrivateMessagesEnabled(rs.getInt("user_notify_pm") == 1);
    u.setDeleted(rs.getInt("deleted"));
    u.setNotifyAlways(rs.getInt("user_notify_always") == 1);
    u.setNotifyText(rs.getInt("user_notify_text") == 1);
    String actkey = rs.getString("user_actkey");
    u.setActivationKey(actkey == null || "".equals(actkey) ? null : actkey);
}
Also used : Date(java.util.Date) KarmaStatus(net.jforum.entities.KarmaStatus)

Example 8 with KarmaStatus

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

the class GenericKarmaDAO method fillUser.

protected List fillUser(ResultSet rs) throws SQLException {
    List usersAndPoints = new ArrayList();
    KarmaStatus karma = null;
    while (rs.next()) {
        User user = new User();
        karma = new KarmaStatus();
        karma.setTotalPoints(rs.getInt("total"));
        karma.setVotesReceived(rs.getInt("votes_received"));
        karma.setKarmaPoints(rs.getDouble("user_karma"));
        karma.setVotesGiven(rs.getInt("votes_given"));
        user.setUsername(rs.getString("username"));
        user.setId(rs.getInt("user_id"));
        user.setKarma(karma);
        usersAndPoints.add(user);
    }
    return usersAndPoints;
}
Also used : User(net.jforum.entities.User) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) KarmaStatus(net.jforum.entities.KarmaStatus)

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