Search in sources :

Example 1 with PostDAO

use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.

the class ModerationAction method doSave.

public void doSave() {
    String[] posts = this.request.getParameterValues("post_id");
    if (posts != null) {
        TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
        for (int i = 0; i < posts.length; i++) {
            int postId = Integer.parseInt(posts[i]);
            String status = this.request.getParameter("status_" + postId);
            if ("defer".startsWith(status)) {
                continue;
            }
            if ("aprove".startsWith(status)) {
                Post p = DataAccessDriver.getInstance().newPostDAO().selectById(postId);
                // Check is the post is in fact waiting for moderation
                if (!p.isModerationNeeded()) {
                    continue;
                }
                UserDAO userDao = DataAccessDriver.getInstance().newUserDAO();
                User u = userDao.selectById(p.getUserId());
                boolean first = false;
                Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
                if (t == null) {
                    t = topicDao.selectById(p.getTopicId());
                    if (t.getId() == 0) {
                        first = true;
                        t = topicDao.selectRaw(p.getTopicId());
                    }
                }
                DataAccessDriver.getInstance().newModerationDAO().aprovePost(postId);
                boolean firstPost = (t.getFirstPostId() == postId);
                if (!firstPost) {
                    t.setTotalReplies(t.getTotalReplies() + 1);
                }
                t.setLastPostId(postId);
                t.setLastPostBy(u);
                t.setLastPostDate(p.getTime());
                t.setLastPostTime(p.getFormatedTime());
                topicDao.update(t);
                if (first) {
                    t = topicDao.selectById(t.getId());
                }
                TopicsCommon.updateBoardStatus(t, postId, firstPost, topicDao, DataAccessDriver.getInstance().newForumDAO());
                ForumRepository.updateForumStats(t, u, p);
                TopicsCommon.notifyUsers(t, p);
                userDao.incrementPosts(p.getUserId());
                if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
                    PostRepository.append(p.getTopicId(), PostCommon.preparePostForDisplay(p));
                }
            } else {
                PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
                Post post = pm.selectById(postId);
                if (post == null || !post.isModerationNeeded()) {
                    continue;
                }
                pm.delete(post);
                new AttachmentCommon(this.request, post.getForumId()).deleteAttachments(postId, post.getForumId());
                int totalPosts = topicDao.getTotalPosts(post.getTopicId());
                if (totalPosts == 0) {
                    TopicsCommon.deleteTopic(post.getTopicId(), post.getForumId(), true);
                }
            }
        }
    }
}
Also used : User(net.jforum.entities.User) UserDAO(net.jforum.dao.UserDAO) PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Example 2 with PostDAO

use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.

the class PostRepository method selectAllByTopicByLimit.

public static List selectAllByTopicByLimit(int topicId, int start, int count) {
    String tid = Integer.toString(topicId);
    List posts = (List) cache.get(FQN, tid);
    if (posts == null || posts.size() == 0) {
        PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
        posts = pm.selectAllByTopic(topicId);
        for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
            PostCommon.preparePostForDisplay((Post) iter.next());
        }
        Map topics = (Map) cache.get(FQN);
        if (topics == null || topics.size() == 0 || topics.size() < CACHE_SIZE) {
            cache.add(FQN, tid, posts);
        } else {
            if (!(topics instanceof LinkedHashMap)) {
                topics = new LinkedHashMap(topics) {

                    protected boolean removeEldestEntry(java.util.Map.Entry eldest) {
                        return this.size() > CACHE_SIZE;
                    }
                };
            }
            topics.put(tid, posts);
            cache.add(FQN, topics);
        }
    }
    int size = posts.size();
    return posts.subList(start, (size < start + count) ? size : start + count);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with PostDAO

use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.

the class AjaxAction method loadPostContents.

public void loadPostContents() {
    int postId = this.request.getIntParameter("id");
    PostDAO dao = DataAccessDriver.getInstance().newPostDAO();
    Post post = dao.selectById(postId);
    this.setTemplateName(TemplateKeys.AJAX_LOAD_POST);
    this.context.put("post", post);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post)

Example 4 with PostDAO

use of net.jforum.dao.PostDAO in project jforum2 by rafaelsteil.

the class AjaxAction method savePost.

public void savePost() {
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(this.request.getIntParameter("id"));
    String originalMessage = post.getText();
    if (!PostCommon.canEditPost(post)) {
        post = PostCommon.preparePostForDisplay(post);
    } else {
        post.setText(this.request.getParameter("value"));
        postDao.update(post);
        SearchFacade.update(post);
        post = PostCommon.preparePostForDisplay(post);
    }
    boolean isModerator = SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT);
    if (SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED) && isModerator && post.getUserId() != SessionFacade.getUserSession().getUserId()) {
        ModerationHelper helper = new ModerationHelper();
        this.request.addParameter("log_original_message", originalMessage);
        this.request.addParameter("post_id", String.valueOf(post.getId()));
        this.request.addParameter("topic_id", String.valueOf(post.getTopicId()));
        ModerationLog log = helper.buildModerationLogFromRequest();
        log.getPosterUser().setId(post.getUserId());
        helper.saveModerationLog(log);
    }
    if (SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
        PostRepository.update(post.getTopicId(), PostCommon.preparePostForDisplay(post));
    }
    this.setTemplateName(TemplateKeys.AJAX_LOAD_POST);
    this.context.put("post", post);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog)

Example 5 with PostDAO

use of net.jforum.dao.PostDAO 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)

Aggregations

PostDAO (net.jforum.dao.PostDAO)21 Post (net.jforum.entities.Post)15 Topic (net.jforum.entities.Topic)13 TopicDAO (net.jforum.dao.TopicDAO)10 List (java.util.List)8 User (net.jforum.entities.User)8 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)8 Iterator (java.util.Iterator)5 PollDAO (net.jforum.dao.PollDAO)5 Map (java.util.Map)4 ForumDAO (net.jforum.dao.ForumDAO)4 UserDAO (net.jforum.dao.UserDAO)4 ModerationLog (net.jforum.entities.ModerationLog)4 Poll (net.jforum.entities.Poll)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Forum (net.jforum.entities.Forum)3 AttachmentException (net.jforum.exceptions.AttachmentException)3 KarmaDAO (net.jforum.dao.KarmaDAO)2 QuotaLimit (net.jforum.entities.QuotaLimit)2