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();
}
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();
}
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);
}
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);
}
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);
}
Aggregations