Search in sources :

Example 6 with ForumDAO

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();
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) ModerationCommon(net.jforum.view.admin.common.ModerationCommon) Forum(net.jforum.entities.Forum)

Example 7 with ForumDAO

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();
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) TopicDAO(net.jforum.dao.TopicDAO) Forum(net.jforum.entities.Forum)

Example 8 with ForumDAO

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

Example 9 with ForumDAO

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

the class GenericTopicDAO method deleteTopics.

public void deleteTopics(List topics, boolean fromModeration) {
    // Topic
    PreparedStatement p = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("TopicModel.delete"));
        ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
        PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
        PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
        for (Iterator iter = topics.iterator(); iter.hasNext(); ) {
            Topic topic = (Topic) iter.next();
            // Remove watches
            this.removeSubscriptionByTopic(topic.getId());
            // Remove the messages
            postDao.deleteByTopic(topic.getId());
            // Remove the poll
            pollDao.deleteByTopicId(topic.getId());
            // Delete the topic itself
            p.setInt(1, topic.getId());
            p.executeUpdate();
            if (!fromModeration) {
                forumDao.decrementTotalTopics(topic.getForumId(), 1);
            }
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(p);
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) PollDAO(net.jforum.dao.PollDAO) PostDAO(net.jforum.dao.PostDAO) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) PreparedStatement(java.sql.PreparedStatement) Topic(net.jforum.entities.Topic) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 10 with ForumDAO

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

the class ForumStartup method startForumRepository.

/**
	 * Starts the cache control for forums and categories.
	 * @throws RepositoryStartupException is something were wrong.
	 */
public static void startForumRepository() {
    try {
        ForumDAO fm = DataAccessDriver.getInstance().newForumDAO();
        CategoryDAO cm = DataAccessDriver.getInstance().newCategoryDAO();
        ConfigDAO configModel = DataAccessDriver.getInstance().newConfigDAO();
        ForumRepository.start(fm, cm, configModel);
    } catch (Exception e) {
        log.error("Unable to bootstrap JForum repository.", e);
        throw new RepositoryStartupException("Error while trying to start ForumRepository: " + e, e);
    }
}
Also used : ForumDAO(net.jforum.dao.ForumDAO) CategoryDAO(net.jforum.dao.CategoryDAO) ConfigDAO(net.jforum.dao.ConfigDAO) DatabaseException(net.jforum.exceptions.DatabaseException) RepositoryStartupException(net.jforum.exceptions.RepositoryStartupException) RepositoryStartupException(net.jforum.exceptions.RepositoryStartupException)

Aggregations

ForumDAO (net.jforum.dao.ForumDAO)13 TopicDAO (net.jforum.dao.TopicDAO)5 Forum (net.jforum.entities.Forum)5 Topic (net.jforum.entities.Topic)5 List (java.util.List)4 PostDAO (net.jforum.dao.PostDAO)4 ArrayList (java.util.ArrayList)3 Post (net.jforum.entities.Post)3 Date (java.util.Date)2 Iterator (java.util.Iterator)2 CategoryDAO (net.jforum.dao.CategoryDAO)2 PollDAO (net.jforum.dao.PollDAO)2 ModerationLog (net.jforum.entities.ModerationLog)2 User (net.jforum.entities.User)2 UserSession (net.jforum.entities.UserSession)2 DatabaseException (net.jforum.exceptions.DatabaseException)2 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1