Search in sources :

Example 16 with Forum

use of net.jforum.entities.Forum 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 17 with Forum

use of net.jforum.entities.Forum 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 18 with Forum

use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.

the class RecentTopicsAction method topics.

private List topics() {
    int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
    List topics = TopicRepository.getRecentTopics();
    this.forums = new ArrayList(postsPerPage);
    for (Iterator iter = topics.iterator(); iter.hasNext(); ) {
        Topic t = (Topic) iter.next();
        if (TopicsCommon.isTopicAccessible(t.getForumId())) {
            Forum f = ForumRepository.getForum(t.getForumId());
            forums.add(f);
        } else {
            iter.remove();
        }
    }
    JForumExecutionContext.getRequest().removeAttribute("template");
    return TopicsCommon.prepareTopics(topics);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Topic(net.jforum.entities.Topic) Forum(net.jforum.entities.Forum)

Example 19 with Forum

use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.

the class ForumRepository method loadForums.

/**
	 * Loads all forums.
     * @param fm ForumDAO
     */
private void loadForums(ForumDAO fm) {
    List l = fm.selectAll();
    Map m = (Map) cache.get(FQN, RELATION);
    if (m == null) {
        m = new HashMap();
    }
    int lastId = 0;
    Category c = null;
    String catId = null;
    for (Iterator iter = l.iterator(); iter.hasNext(); ) {
        Forum f = (Forum) iter.next();
        if (f.getCategoryId() != lastId) {
            if (c != null) {
                cache.add(FQN, catId, c);
            }
            lastId = f.getCategoryId();
            catId = Integer.toString(f.getCategoryId());
            c = (Category) cache.get(FQN, catId);
        }
        if (c == null) {
            throw new CategoryNotFoundException("Category for forum #" + f.getId() + " not found");
        }
        String forumId = Integer.toString(f.getId());
        c.addForum(f);
        m.put(forumId, catId);
    }
    if (c != null) {
        cache.add(FQN, catId, c);
    }
    cache.add(FQN, RELATION, m);
}
Also used : Category(net.jforum.entities.Category) HashMap(java.util.HashMap) Iterator(java.util.Iterator) CategoryNotFoundException(net.jforum.exceptions.CategoryNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Example 20 with Forum

use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.

the class ForumRepository method addCategory.

/**
	 * Adds a new category to the cache.
	 * @param c The category instance to insert in the cache.
	 */
public static synchronized void addCategory(Category c) {
    String categoryId = Integer.toString(c.getId());
    cache.add(FQN, categoryId, c);
    Set s = (Set) cache.get(FQN, CATEGORIES_SET);
    if (s == null) {
        s = new TreeSet(new CategoryOrderComparator());
    }
    s.add(c);
    cache.add(FQN, CATEGORIES_SET, s);
    Map relation = (Map) cache.get(FQN, RELATION);
    if (relation == null) {
        relation = new HashMap();
    }
    for (Iterator iter = c.getForums().iterator(); iter.hasNext(); ) {
        Forum f = (Forum) iter.next();
        relation.put(Integer.toString(f.getId()), categoryId);
    }
    cache.add(FQN, RELATION, relation);
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) CategoryOrderComparator(net.jforum.util.CategoryOrderComparator) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map) Forum(net.jforum.entities.Forum)

Aggregations

Forum (net.jforum.entities.Forum)28 List (java.util.List)14 Iterator (java.util.Iterator)13 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 Topic (net.jforum.entities.Topic)8 Category (net.jforum.entities.Category)7 ForumDAO (net.jforum.dao.ForumDAO)5 TopicDAO (net.jforum.dao.TopicDAO)5 User (net.jforum.entities.User)5 AttachmentCommon (net.jforum.view.forum.common.AttachmentCommon)4 PostDAO (net.jforum.dao.PostDAO)3 UserDAO (net.jforum.dao.UserDAO)3 UserSession (net.jforum.entities.UserSession)3 PermissionControl (net.jforum.security.PermissionControl)3 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Set (java.util.Set)2