use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class TopicsCommon method notifyUsers.
/**
* Sends a "new post" notification message to all users watching the topic.
*
* @param t The changed topic
* @param p The new message
*/
public static void notifyUsers(Topic t, Post p) {
if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_NOTIFY_ANSWERS)) {
TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO();
List usersToNotify = dao.notifyUsers(t);
// subscribed to the topic
if (usersToNotify != null && usersToNotify.size() > 0) {
Executor.execute(new EmailSenderTask(new TopicReplySpammer(t, p, usersToNotify)));
}
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class POPListenerTestCase method deleteTopic.
/**
* Deletes a topic
* @param topicId the topic's id to delete
*/
private void deleteTopic(int topicId) {
try {
TopicDAO dao = DataAccessDriver.getInstance().newTopicDAO();
Topic t = new Topic(topicId);
t.setForumId(2);
dao.delete(t, false);
JForumExecutionContext.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class ModerationAction method showActivityLog.
public void showActivityLog() {
if (!SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG)) {
this.denied();
return;
}
ModerationLogDAO dao = DataAccessDriver.getInstance().newModerationLogDAO();
int start = ViewCommon.getStartPage();
int recordsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
List list = dao.selectAll(start, recordsPerPage);
boolean canAccessFullModerationLog = SecurityRepository.canAccess(SecurityConstants.PERM_FULL_MODERATION_LOG);
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
ModerationLog log = (ModerationLog) iter.next();
if (log.getPostId() > 0) {
Post post = postDao.selectById(log.getPostId());
if (post.getId() > 0 && ForumRepository.getForum(post.getForumId()) == null) {
iter.remove();
continue;
}
} else if (log.getTopicId() > 0) {
Topic topic = topicDao.selectRaw(log.getTopicId());
if (topic.getId() > 0 && ForumRepository.getForum(topic.getForumId()) == null) {
iter.remove();
continue;
}
}
if (log.getOriginalMessage() != null && canAccessFullModerationLog) {
Post post = new Post();
post.setText(log.getOriginalMessage());
log.setOriginalMessage(PostCommon.preparePostForDisplay(post).getText());
}
}
this.setTemplateName(TemplateKeys.MODERATION_SHOW_ACTIVITY_LOG);
this.context.put("activityLog", list);
this.context.put("canAccessFullModerationLog", canAccessFullModerationLog);
int totalRecords = dao.totalRecords();
ViewCommon.contextToPagination(start, totalRecords, recordsPerPage);
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class ModerationHelper method removeTopics.
private void removeTopics() {
String[] topics = JForumExecutionContext.getRequest().getParameterValues("topic_id");
List forumsList = new ArrayList();
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
List topicsToDelete = new ArrayList();
if (topics != null && topics.length > 0) {
ModerationLog log = this.buildModerationLogFromRequest();
for (int i = 0; i < topics.length; i++) {
Topic t = tm.selectRaw(Integer.parseInt(topics[i]));
log.setTopicId(t.getId());
log.setPosterUser(t.getPostedBy());
this.saveModerationLog(log);
if (!forumsList.contains(new Integer(t.getForumId()))) {
forumsList.add(new Integer(t.getForumId()));
}
topicsToDelete.add(t);
PostRepository.clearCache(t.getId());
}
tm.deleteTopics(topicsToDelete, false);
ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
TopicRepository.loadMostRecentTopics();
// Reload changed forums
for (Iterator iter = forumsList.iterator(); iter.hasNext(); ) {
int forumId = ((Integer) iter.next()).intValue();
TopicRepository.clearCache(forumId);
int postId = fm.getMaxPostId(forumId);
if (postId > -1) {
fm.setLastPost(forumId, postId);
} else {
logger.warn("Could not find last post id for forum " + forumId);
}
ForumRepository.reloadForum(forumId);
}
}
}
use of net.jforum.dao.TopicDAO in project jforum2 by rafaelsteil.
the class PostAction method listByUser.
public void listByUser() {
PostDAO pm = DataAccessDriver.getInstance().newPostDAO();
UserDAO um = DataAccessDriver.getInstance().newUserDAO();
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
User u = um.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
int start = ViewCommon.getStartPage();
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
List posts = pm.selectByUserByLimit(u.getId(), start, postsPerPage);
int totalMessages = pm.countUserPosts(u.getId());
// get list of forums
Map topics = new HashMap();
Map forums = new HashMap();
for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
Post p = (Post) iter.next();
if (!topics.containsKey(new Integer(p.getTopicId()))) {
Topic t = TopicRepository.getTopic(new Topic(p.getTopicId()));
if (t == null) {
t = tm.selectRaw(p.getTopicId());
}
this.context.put("attachmentsEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(t.getForumId())));
this.context.put("am", new AttachmentCommon(this.request, t.getForumId()));
topics.put(new Integer(t.getId()), t);
}
if (!forums.containsKey(new Integer(p.getForumId()))) {
Forum f = ForumRepository.getForum(p.getForumId());
if (f == null) {
// Ok, probably the user does not have permission to see this forum
iter.remove();
totalMessages--;
continue;
}
forums.put(new Integer(f.getId()), f);
}
PostCommon.preparePostForDisplay(p);
}
this.setTemplateName(TemplateKeys.POSTS_USER_POSTS_LIST);
this.context.put("canDownloadAttachments", SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
this.context.put("posts", posts);
this.context.put("topics", topics);
this.context.put("forums", forums);
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("PostShow.userPosts") + " " + u.getUsername());
this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
ViewCommon.contextToPagination(start, totalMessages, count);
}
Aggregations