Search in sources :

Example 16 with TopicDAO

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)));
        }
    }
}
Also used : EmailSenderTask(net.jforum.util.mail.EmailSenderTask) TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) TopicReplySpammer(net.jforum.util.mail.TopicReplySpammer)

Example 17 with TopicDAO

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();
    }
}
Also used : TopicDAO(net.jforum.dao.TopicDAO) Topic(net.jforum.entities.Topic) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 18 with TopicDAO

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);
}
Also used : PostDAO(net.jforum.dao.PostDAO) Post(net.jforum.entities.Post) ModerationLog(net.jforum.entities.ModerationLog) Iterator(java.util.Iterator) TopicDAO(net.jforum.dao.TopicDAO) List(java.util.List) ModerationLogDAO(net.jforum.dao.ModerationLogDAO) Topic(net.jforum.entities.Topic)

Example 19 with TopicDAO

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);
        }
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) ModerationLog(net.jforum.entities.ModerationLog) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) TopicDAO(net.jforum.dao.TopicDAO) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic)

Example 20 with TopicDAO

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);
}
Also used : User(net.jforum.entities.User) HashMap(java.util.HashMap) Post(net.jforum.entities.Post) TopicDAO(net.jforum.dao.TopicDAO) Forum(net.jforum.entities.Forum) PostDAO(net.jforum.dao.PostDAO) UserDAO(net.jforum.dao.UserDAO) Iterator(java.util.Iterator) List(java.util.List) Topic(net.jforum.entities.Topic) Map(java.util.Map) HashMap(java.util.HashMap) AttachmentCommon(net.jforum.view.forum.common.AttachmentCommon)

Aggregations

TopicDAO (net.jforum.dao.TopicDAO)21 Topic (net.jforum.entities.Topic)14 List (java.util.List)10 PostDAO (net.jforum.dao.PostDAO)10 Post (net.jforum.entities.Post)7 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)6 ArrayList (java.util.ArrayList)5 ForumDAO (net.jforum.dao.ForumDAO)5 Forum (net.jforum.entities.Forum)5 Iterator (java.util.Iterator)4 ModerationLog (net.jforum.entities.ModerationLog)4 User (net.jforum.entities.User)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PollDAO (net.jforum.dao.PollDAO)3 Poll (net.jforum.entities.Poll)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2