Search in sources :

Example 1 with Category

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

the class GenericCategoryDAO method selectById.

/**
	 * @see net.jforum.dao.CategoryDAO#selectById(int)
	 */
public Category selectById(int categoryId) {
    PreparedStatement p = null;
    ResultSet rs = null;
    try {
        p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("CategoryModel.selectById"));
        p.setInt(1, categoryId);
        rs = p.executeQuery();
        Category c = new Category();
        if (rs.next()) {
            c = this.getCategory(rs);
        }
        return c;
    } catch (SQLException e) {
        throw new DatabaseException(e);
    } finally {
        DbUtils.close(rs, p);
    }
}
Also used : Category(net.jforum.entities.Category) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseException(net.jforum.exceptions.DatabaseException)

Example 2 with Category

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

the class CategoryAction method processOrdering.

private void processOrdering(boolean up) {
    Category toChange = new Category(ForumRepository.getCategory(Integer.parseInt(this.request.getParameter("category_id"))));
    List categories = ForumRepository.getAllCategories();
    int index = categories.indexOf(toChange);
    if (index == -1 || (up && index == 0) || (!up && index + 1 == categories.size())) {
        this.list();
        return;
    }
    if (up) {
        // Get the category which comes *before* the category we want to change
        Category otherCategory = new Category((Category) categories.get(index - 1));
        this.cm.setOrderUp(toChange, otherCategory);
    } else {
        // Get the category which comes *after* the category we want to change
        Category otherCategory = new Category((Category) categories.get(index + 1));
        this.cm.setOrderDown(toChange, otherCategory);
    }
    ForumRepository.reloadCategory(toChange);
    this.list();
}
Also used : Category(net.jforum.entities.Category) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Category

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

the class CategoryAction method editSave.

//  Save information
public void editSave() {
    Category c = new Category(ForumRepository.getCategory(this.request.getIntParameter("categories_id")));
    c.setName(this.request.getParameter("category_name"));
    c.setModerated("1".equals(this.request.getParameter("moderate")));
    this.cm.update(c);
    ForumRepository.reloadCategory(c);
    new ModerationCommon().setForumsModerationStatus(c, c.isModerated());
    this.list();
}
Also used : Category(net.jforum.entities.Category) ModerationCommon(net.jforum.view.admin.common.ModerationCommon)

Example 4 with Category

use of net.jforum.entities.Category 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 5 with Category

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

the class ForumRepository method updateForumStats.

public static synchronized void updateForumStats(Topic t, User u, Post p) {
    String f = Integer.toString(t.getForumId());
    if (((Map) cache.get(FQN, RELATION)).containsKey(f)) {
        Forum forum = getForum(t.getForumId());
        SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
        LastPostInfo lpi = forum.getLastPostInfo();
        if (lpi == null) {
            lpi = new LastPostInfo();
        }
        lpi.setPostId(p.getId());
        lpi.setPostDate(df.format(p.getTime()));
        lpi.setPostTimeMillis(p.getTime().getTime());
        lpi.setTopicId(t.getId());
        lpi.setTopicReplies(t.getTotalReplies());
        lpi.setUserId(u.getId());
        lpi.setUsername(u.getUsername());
        forum.setLastPostInfo(lpi);
        if (t.getTotalReplies() == 0) {
            forum.setTotalTopics(forum.getTotalTopics() + 1);
        }
        forum.setTotalPosts(forum.getTotalPosts() + 1);
        Category c = retrieveCategory(forum.getCategoryId());
        c.reloadForum(forum);
        refreshCategory(c);
    }
}
Also used : Category(net.jforum.entities.Category) HashMap(java.util.HashMap) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat) LastPostInfo(net.jforum.entities.LastPostInfo) Forum(net.jforum.entities.Forum)

Aggregations

Category (net.jforum.entities.Category)20 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Forum (net.jforum.entities.Forum)7 Iterator (java.util.Iterator)6 Map (java.util.Map)6 Set (java.util.Set)6 TreeSet (java.util.TreeSet)6 HashMap (java.util.HashMap)5 CategoryNotFoundException (net.jforum.exceptions.CategoryNotFoundException)2 DatabaseException (net.jforum.exceptions.DatabaseException)2 PermissionControl (net.jforum.security.PermissionControl)2 CategoryOrderComparator (net.jforum.util.CategoryOrderComparator)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 ForumDAO (net.jforum.dao.ForumDAO)1 GroupSecurityDAO (net.jforum.dao.GroupSecurityDAO)1