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