use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method getListAllowedForums.
public static String getListAllowedForums() {
int n = 0;
StringBuffer buf = new StringBuffer();
List allCategories = ForumRepository.getAllCategories();
for (Iterator iter = allCategories.iterator(); iter.hasNext(); ) {
Collection forums = ((Category) iter.next()).getForums();
for (Iterator tmpIterator = forums.iterator(); tmpIterator.hasNext(); ) {
Forum f = (Forum) tmpIterator.next();
if (ForumRepository.isForumAccessible(f.getId())) {
if (n++ > 0) {
buf.append(',');
}
buf.append(f.getId());
}
}
}
if (n <= 0) {
return "-1";
}
return buf.toString();
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method removeForum.
/**
* Removes a forum from the cache.
*
* @param forum The forum instance to remove.
*/
public static synchronized void removeForum(Forum forum) {
String id = Integer.toString(forum.getId());
Map m = (Map) cache.get(FQN, RELATION);
m.remove(id);
cache.add(FQN, RELATION, m);
id = Integer.toString(forum.getCategoryId());
Category c = (Category) cache.get(FQN, id);
c.removeForum(forum.getId());
cache.add(FQN, id, c);
Set s = (Set) cache.get(FQN, CATEGORIES_SET);
cache.add(FQN, CATEGORIES_SET, s);
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method reloadCategory.
/**
* Updates some category.
* This method only updated the "name" and "order" fields.
*
* @param c The category to update. The method will search for a category
* with the same id and update its data.
*/
public static synchronized void reloadCategory(Category c) {
Category current = (Category) cache.get(FQN, Integer.toString(c.getId()));
Category currentAtOrder = findCategoryByOrder(c.getOrder());
Set tmpSet = new TreeSet(new CategoryOrderComparator());
tmpSet.addAll((Set) cache.get(FQN, CATEGORIES_SET));
if (currentAtOrder != null) {
tmpSet.remove(currentAtOrder);
cache.remove(FQN, Integer.toString(currentAtOrder.getId()));
}
tmpSet.add(c);
cache.add(FQN, Integer.toString(c.getId()), c);
if (currentAtOrder != null && c.getId() != currentAtOrder.getId()) {
tmpSet.remove(current);
currentAtOrder.setOrder(current.getOrder());
tmpSet.add(currentAtOrder);
cache.add(FQN, Integer.toString(currentAtOrder.getId()), currentAtOrder);
}
cache.add(FQN, CATEGORIES_SET, tmpSet);
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumCommon method getAllCategoriesAndForums.
/**
* Gets all forums available to the user.
*
* @param us An <code>UserSession</code> instance with user information
* @param anonymousUserId The id which represents the anonymous user
* @param tracking <code>Map</code> instance with information
* about the topics read by the user
* @param checkUnreadPosts <code>true</code> if is to search for unread topics inside the forums,
* or <code>false</code> if this action is not needed.
* @return A <code>List</code> instance where each record is an instance of a <code>Category</code>
* object
*/
public static List getAllCategoriesAndForums(UserSession us, int anonymousUserId, Map tracking, boolean checkUnreadPosts) {
long lastVisit = 0;
int userId = anonymousUserId;
if (us != null) {
lastVisit = us.getLastVisit().getTime();
userId = us.getUserId();
}
// Do not check for unread posts if the user is not logged in
checkUnreadPosts = checkUnreadPosts && (userId != anonymousUserId);
List categories = ForumRepository.getAllCategories(userId);
if (!checkUnreadPosts) {
return categories;
}
List returnCategories = new ArrayList();
for (Iterator iter = categories.iterator(); iter.hasNext(); ) {
Category c = new Category((Category) iter.next());
for (Iterator tmpIterator = c.getForums().iterator(); tmpIterator.hasNext(); ) {
Forum f = (Forum) tmpIterator.next();
ForumCommon.checkUnreadPosts(f, tracking, lastVisit);
}
returnCategories.add(c);
}
return returnCategories;
}
use of net.jforum.entities.Category in project jforum2 by rafaelsteil.
the class ForumRepository method addForum.
/**
* Adds a new forum to the cache repository.
*
* @param forum The forum to add
*/
public static synchronized void addForum(Forum forum) {
String categoryId = Integer.toString(forum.getCategoryId());
Category c = (Category) cache.get(FQN, categoryId);
c.addForum(forum);
cache.add(FQN, categoryId, c);
Map m = (Map) cache.get(FQN, RELATION);
m.put(Integer.toString(forum.getId()), categoryId);
cache.add(FQN, RELATION, m);
Set s = (Set) cache.get(FQN, CATEGORIES_SET);
cache.add(FQN, CATEGORIES_SET, s);
}
Aggregations