use of net.jforum.dao.ForumDAO in project jforum2 by rafaelsteil.
the class ForumAction method editSave.
public void editSave() {
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
Forum f = forumDao.selectById(this.request.getIntParameter("forum_id"));
boolean moderated = f.isModerated();
int categoryId = f.getCategoryId();
f.setDescription(this.request.getParameter("description"));
f.setIdCategories(this.request.getIntParameter("categories_id"));
f.setName(this.request.getParameter("forum_name"));
f.setModerated("1".equals(this.request.getParameter("moderate")));
forumDao.update(f);
if (moderated != f.isModerated()) {
new ModerationCommon().setTopicModerationStatus(f.getId(), f.isModerated());
}
if (categoryId != f.getCategoryId()) {
f.setIdCategories(categoryId);
ForumRepository.removeForum(f);
f.setIdCategories(this.request.getIntParameter("categories_id"));
ForumRepository.addForum(f);
} else {
ForumRepository.reloadForum(f.getId());
}
//this.handleMailIntegration();
this.list();
}
use of net.jforum.dao.ForumDAO in project jforum2 by rafaelsteil.
the class ForumAction method delete.
// Delete
public void delete() {
String[] ids = this.request.getParameterValues("forum_id");
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
int forumId = Integer.parseInt(ids[i]);
topicDao.deleteByForum(forumId);
forumDao.delete(forumId);
Forum f = new Forum(ForumRepository.getForum(forumId));
ForumRepository.removeForum(f);
}
SecurityRepository.clean();
RolesRepository.clear();
}
this.list();
}
use of net.jforum.dao.ForumDAO in project jforum2 by rafaelsteil.
the class ForumAction method processOrdering.
private void processOrdering(boolean up) {
Forum toChange = new Forum(ForumRepository.getForum(Integer.parseInt(this.request.getParameter("forum_id"))));
Category category = ForumRepository.getCategory(toChange.getCategoryId());
List forums = new ArrayList(category.getForums());
int index = forums.indexOf(toChange);
if (index == -1 || (up && index == 0) || (!up && index + 1 == forums.size())) {
this.list();
return;
}
ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
if (up) {
// Get the forum which comes *before* the forum we're changing
Forum otherForum = new Forum((Forum) forums.get(index - 1));
fm.setOrderUp(toChange, otherForum);
} else {
// Get the forum which comes *after* the forum we're changing
Forum otherForum = new Forum((Forum) forums.get(index + 1));
fm.setOrderDown(toChange, otherForum);
}
category.changeForumOrder(toChange);
ForumRepository.refreshCategory(category);
this.list();
}
use of net.jforum.dao.ForumDAO in project jforum2 by rafaelsteil.
the class ForumAction method show.
/**
* Display all topics in a forum
*/
public void show() {
int forumId = this.request.getIntParameter("forum_id");
ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
// The user can access this forum?
Forum forum = ForumRepository.getForum(forumId);
if (forum == null || !ForumRepository.isCategoryAccessible(forum.getCategoryId())) {
new ModerationHelper().denied(I18n.getMessage("ForumListing.denied"));
return;
}
int start = ViewCommon.getStartPage();
List tmpTopics = TopicsCommon.topicsByForum(forumId, start);
this.setTemplateName(TemplateKeys.FORUMS_SHOW);
// Moderation
UserSession userSession = SessionFacade.getUserSession();
boolean isLogged = SessionFacade.isLogged();
boolean isModerator = userSession.isModerator(forumId);
boolean canApproveMessages = (isLogged && isModerator && SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_APPROVE_MESSAGES));
Map topicsToApprove = new HashMap();
if (canApproveMessages) {
ModerationDAO mdao = DataAccessDriver.getInstance().newModerationDAO();
topicsToApprove = mdao.topicsByForum(forumId);
this.context.put("postFormatter", new PostCommon());
}
this.context.put("topicsToApprove", topicsToApprove);
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(forumId)) || SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
this.context.put("topics", TopicsCommon.prepareTopics(tmpTopics));
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
this.context.put("forum", forum);
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("pageTitle", forum.getName());
this.context.put("canApproveMessages", canApproveMessages);
this.context.put("replyOnly", !SecurityRepository.canAccess(SecurityConstants.PERM_REPLY_ONLY, Integer.toString(forum.getId())));
this.context.put("readonly", !SecurityRepository.canAccess(SecurityConstants.PERM_READ_ONLY_FORUMS, Integer.toString(forumId)));
this.context.put("watching", fm.isUserSubscribed(forumId, userSession.getUserId()));
// Pagination
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
int totalTopics = forum.getTotalTopics();
ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
this.context.put("postsPerPage", new Integer(postsPerPage));
TopicsCommon.topicListingBase();
this.context.put("moderator", isLogged && isModerator);
}
use of net.jforum.dao.ForumDAO in project jforum2 by rafaelsteil.
the class PostAction method delete.
public void delete() {
if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE)) {
this.setTemplateName(TemplateKeys.POSTS_CANNOT_DELETE);
this.context.put("message", I18n.getMessage("CannotRemovePost"));
return;
}
// Post
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
Post p = postDao.selectById(this.request.getIntParameter("post_id"));
if (p.getId() == 0) {
this.postNotFound();
return;
}
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
Topic t = topicDao.selectRaw(p.getTopicId());
if (!TopicsCommon.isTopicAccessible(t.getForumId())) {
return;
}
postDao.delete(p);
DataAccessDriver.getInstance().newUserDAO().decrementPosts(p.getUserId());
// Karma
KarmaDAO karmaDao = DataAccessDriver.getInstance().newKarmaDAO();
karmaDao.updateUserKarma(p.getUserId());
// Attachments
new AttachmentCommon(this.request, p.getForumId()).deleteAttachments(p.getId(), p.getForumId());
// It was the last remaining post in the topic?
int totalPosts = topicDao.getTotalPosts(p.getTopicId());
if (totalPosts > 0) {
// Topic
topicDao.decrementTotalReplies(p.getTopicId());
int maxPostId = topicDao.getMaxPostId(p.getTopicId());
if (maxPostId > -1) {
topicDao.setLastPostId(p.getTopicId(), maxPostId);
}
int minPostId = topicDao.getMinPostId(p.getTopicId());
if (minPostId > -1) {
topicDao.setFirstPostId(p.getTopicId(), minPostId);
}
// Forum
ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
maxPostId = fm.getMaxPostId(p.getForumId());
if (maxPostId > -1) {
fm.setLastPost(p.getForumId(), maxPostId);
}
String returnPath = this.request.getContextPath() + "/posts/list/";
int page = ViewCommon.getStartPage();
if (page > 0) {
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
if (totalPosts % postsPerPage == 0) {
page -= postsPerPage;
}
returnPath += page + "/";
}
JForumExecutionContext.setRedirect(returnPath + p.getTopicId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
// Update the cache
if (TopicRepository.isTopicCached(t)) {
t = topicDao.selectById(t.getId());
TopicRepository.updateTopic(t);
}
} else {
// Ok, all posts were removed. Time to say goodbye
TopicsCommon.deleteTopic(p.getTopicId(), p.getForumId(), false);
JForumExecutionContext.setRedirect(this.request.getContextPath() + "/forums/show/" + p.getForumId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
}
this.request.addOrReplaceParameter("log_original_message", p.getText());
ModerationHelper moderationHelper = new ModerationHelper();
ModerationLog moderationLog = moderationHelper.buildModerationLogFromRequest();
moderationLog.getPosterUser().setId(p.getUserId());
moderationHelper.saveModerationLog(moderationLog);
PostRepository.remove(t.getId(), p.getId());
TopicRepository.loadMostRecentTopics();
TopicRepository.loadHottestTopics();
ForumRepository.reloadForum(p.getForumId());
}
Aggregations