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