Search in sources :

Example 1 with MostUsersEverOnline

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

the class ForumRepository method loadMostUsersEverOnline.

private MostUsersEverOnline loadMostUsersEverOnline(ConfigDAO cm) {
    Config config = cm.selectByName(ConfigKeys.MOST_USERS_EVER_ONLINE);
    MostUsersEverOnline mostUsersEverOnline = new MostUsersEverOnline();
    if (config != null) {
        mostUsersEverOnline.setTotal(Integer.parseInt(config.getValue()));
        // We're assuming that, if we have one key, the another one
        // will always exist
        config = cm.selectByName(ConfigKeys.MOST_USER_EVER_ONLINE_DATE);
        mostUsersEverOnline.setTimeInMillis(Long.parseLong(config.getValue()));
    }
    cache.add(FQN, MOST_USERS_ONLINE, mostUsersEverOnline);
    return mostUsersEverOnline;
}
Also used : Config(net.jforum.entities.Config) MostUsersEverOnline(net.jforum.entities.MostUsersEverOnline)

Example 2 with MostUsersEverOnline

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

the class ForumAction method list.

/**
	 * List all the forums (first page of forum index)?
	 */
public void list() {
    this.setTemplateName(TemplateKeys.FORUMS_LIST);
    this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(true));
    this.context.put("topicsPerPage", new Integer(SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE)));
    this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
    this.context.put("totalMessages", new Integer(ForumRepository.getTotalMessages()));
    this.context.put("totalRegisteredUsers", ForumRepository.totalUsers());
    this.context.put("lastUser", ForumRepository.lastRegisteredUser());
    SimpleDateFormat df = new SimpleDateFormat(SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    GregorianCalendar gc = new GregorianCalendar();
    this.context.put("now", df.format(gc.getTime()));
    this.context.put("lastVisit", df.format(SessionFacade.getUserSession().getLastVisit()));
    this.context.put("forumRepository", new ForumRepository());
    // Online Users
    this.context.put("totalOnlineUsers", new Integer(SessionFacade.size()));
    int aid = SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID);
    List onlineUsersList = SessionFacade.getLoggedSessions();
    // Check for an optional language parameter
    UserSession currentUser = SessionFacade.getUserSession();
    if (currentUser.getUserId() == aid) {
        String lang = this.request.getParameter("lang");
        if (lang != null && I18n.languageExists(lang)) {
            currentUser.setLang(lang);
        }
    }
    // show the "guest" username
    if (onlineUsersList.size() == 0) {
        UserSession us = new UserSession();
        us.setUserId(aid);
        us.setUsername(I18n.getMessage("Guest"));
        onlineUsersList.add(us);
    }
    int registeredSize = SessionFacade.registeredSize();
    int anonymousSize = SessionFacade.anonymousSize();
    int totalOnlineUsers = registeredSize + anonymousSize;
    this.context.put("userSessions", onlineUsersList);
    this.context.put("totalOnlineUsers", new Integer(totalOnlineUsers));
    this.context.put("totalRegisteredOnlineUsers", new Integer(registeredSize));
    this.context.put("totalAnonymousUsers", new Integer(anonymousSize));
    // Most users ever online
    MostUsersEverOnline mostUsersEverOnline = ForumRepository.getMostUsersEverOnline();
    if (totalOnlineUsers > mostUsersEverOnline.getTotal()) {
        mostUsersEverOnline.setTotal(totalOnlineUsers);
        mostUsersEverOnline.setTimeInMillis(System.currentTimeMillis());
        ForumRepository.updateMostUsersEverOnline(mostUsersEverOnline);
    }
    this.context.put("mostUsersEverOnline", mostUsersEverOnline);
}
Also used : ForumRepository(net.jforum.repository.ForumRepository) MostUsersEverOnline(net.jforum.entities.MostUsersEverOnline) UserSession(net.jforum.entities.UserSession) GregorianCalendar(java.util.GregorianCalendar) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

MostUsersEverOnline (net.jforum.entities.MostUsersEverOnline)2 SimpleDateFormat (java.text.SimpleDateFormat)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 Config (net.jforum.entities.Config)1 UserSession (net.jforum.entities.UserSession)1 ForumRepository (net.jforum.repository.ForumRepository)1