use of net.jforum.repository.RankingRepository in project jforum2 by rafaelsteil.
the class PostAction method list.
public void list() {
PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
PollDAO pollDao = DataAccessDriver.getInstance().newPollDAO();
TopicDAO topicDao = DataAccessDriver.getInstance().newTopicDAO();
UserSession us = SessionFacade.getUserSession();
int anonymousUser = SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID);
boolean logged = SessionFacade.isLogged();
int topicId = this.request.getIntParameter("topic_id");
Topic topic = TopicRepository.getTopic(new Topic(topicId));
if (topic == null) {
topic = topicDao.selectById(topicId);
}
// The topic exists?
if (topic.getId() == 0) {
this.topicNotFound();
return;
}
// Shall we proceed?
Forum forum = ForumRepository.getForum(topic.getForumId());
if (!logged) {
if (forum == null || !ForumRepository.isCategoryAccessible(forum.getCategoryId())) {
this.setTemplateName(ViewCommon.contextToLogin());
return;
}
} else if (!TopicsCommon.isTopicAccessible(topic.getForumId())) {
return;
}
int count = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
int start = ViewCommon.getStartPage();
PermissionControl pc = SecurityRepository.get(us.getUserId());
boolean moderatorCanEdit = false;
if (pc.canAccess(SecurityConstants.PERM_MODERATION_POST_EDIT)) {
moderatorCanEdit = true;
}
List helperList = PostCommon.topicPosts(postDao, moderatorCanEdit, us.getUserId(), topic.getId(), start, count);
// Is moderation pending for the topic?
if (topic.isModerated() && helperList.size() == 0) {
this.notModeratedYet();
return;
}
// Set the topic status as read
if (logged) {
topicDao.updateReadStatus(topic.getId(), us.getUserId(), true);
}
boolean canVoteOnPoll = logged && SecurityRepository.canAccess(SecurityConstants.PERM_VOTE);
Poll poll = null;
if (topic.isVote()) {
// It has a poll associated with the topic
poll = pollDao.selectById(topic.getVoteId());
if (canVoteOnPoll) {
canVoteOnPoll = !pollDao.hasUserVotedOnPoll(topic.getVoteId(), us.getUserId());
}
}
topicDao.incrementTotalViews(topic.getId());
topic.setTotalViews(topic.getTotalViews() + 1);
if (us.getUserId() != anonymousUser) {
SessionFacade.getTopicsReadTime().put(new Integer(topic.getId()), new Long(System.currentTimeMillis()));
}
boolean karmaEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED);
Map userVotes = new HashMap();
if (logged && karmaEnabled) {
userVotes = DataAccessDriver.getInstance().newKarmaDAO().getUserVotes(topic.getId(), us.getUserId());
}
this.setTemplateName(TemplateKeys.POSTS_LIST);
this.context.put("attachmentsEnabled", pc.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(topic.getForumId())));
this.context.put("canDownloadAttachments", pc.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD));
this.context.put("thumbShowBox", SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_IMAGES_THUMB_BOX_SHOW));
this.context.put("am", new AttachmentCommon(this.request, topic.getForumId()));
this.context.put("karmaVotes", userVotes);
this.context.put("rssEnabled", SystemGlobals.getBoolValue(ConfigKeys.RSS_ENABLED));
this.context.put("canRemove", pc.canAccess(SecurityConstants.PERM_MODERATION_POST_REMOVE));
this.context.put("moderatorCanEdit", moderatorCanEdit);
this.context.put("allCategories", ForumCommon.getAllCategoriesAndForums(false));
this.context.put("topic", topic);
this.context.put("poll", poll);
this.context.put("canVoteOnPoll", canVoteOnPoll);
this.context.put("rank", new RankingRepository());
this.context.put("posts", helperList);
this.context.put("forum", forum);
this.context.put("karmaMin", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MIN_POINTS)));
this.context.put("karmaMax", new Integer(SystemGlobals.getValue(ConfigKeys.KARMA_MAX_POINTS)));
this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
this.context.put("moderationLoggingEnabled", SystemGlobals.getBoolValue(ConfigKeys.MODERATION_LOGGING_ENABLED));
this.context.put("needCaptcha", SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_POSTS));
Map topicPosters = topicDao.topicPosters(topic.getId());
for (Iterator iter = topicPosters.values().iterator(); iter.hasNext(); ) {
ViewCommon.prepareUserSignature((User) iter.next());
}
this.context.put("users", topicPosters);
this.context.put("anonymousPosts", pc.canAccess(SecurityConstants.PERM_ANONYMOUS_POST, Integer.toString(topic.getForumId())));
this.context.put("watching", topicDao.isUserSubscribed(topicId, SessionFacade.getUserSession().getUserId()));
this.context.put("pageTitle", topic.getTitle());
this.context.put("isAdmin", pc.canAccess(SecurityConstants.PERM_ADMINISTRATION));
this.context.put("readonly", !pc.canAccess(SecurityConstants.PERM_READ_ONLY_FORUMS, Integer.toString(topic.getForumId())));
this.context.put("replyOnly", !pc.canAccess(SecurityConstants.PERM_REPLY_ONLY, Integer.toString(topic.getForumId())));
this.context.put("isModerator", us.isModerator(topic.getForumId()));
ViewCommon.contextToPagination(start, topic.getTotalReplies() + 1, count);
TopicsCommon.topicListingBase();
TopicRepository.updateTopic(topic);
}
use of net.jforum.repository.RankingRepository in project jforum2 by rafaelsteil.
the class CacheAction method list.
/**
* @see net.jforum.Command#list()
*/
public void list() {
this.setTemplateName(TemplateKeys.CACHE_LIST);
this.context.put("bb", new BBCodeRepository());
this.context.put("modules", new ModulesRepository());
this.context.put("ranking", new RankingRepository());
this.context.put("smilies", new SmiliesRepository());
this.context.put("security", new SecurityRepository());
this.context.put("forum", new ForumRepository());
this.context.put("topic", new TopicRepository());
this.context.put("session", new SessionFacade());
this.context.put("posts", new PostRepository());
}
use of net.jforum.repository.RankingRepository in project jforum2 by rafaelsteil.
the class UserAction method profile.
public void profile() {
DataAccessDriver da = DataAccessDriver.getInstance();
UserDAO udao = da.newUserDAO();
User u = udao.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.userNotFound();
} else {
this.setTemplateName(TemplateKeys.USER_PROFILE);
this.context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
this.context.put("rank", new RankingRepository());
this.context.put("u", u);
this.context.put("avatarAllowExternalUrl", SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL));
int loggedId = SessionFacade.getUserSession().getUserId();
int count = 0;
List bookmarks = da.newBookmarkDAO().selectByUser(u.getId());
for (Iterator iter = bookmarks.iterator(); iter.hasNext(); ) {
Bookmark b = (Bookmark) iter.next();
if (b.isPublicVisible() || loggedId == u.getId()) {
count++;
}
}
this.context.put("pageTitle", I18n.getMessage("UserProfile.allAbout") + " " + u.getUsername());
this.context.put("nbookmarks", new Integer(count));
this.context.put("ntopics", new Integer(da.newTopicDAO().countUserTopics(u.getId())));
this.context.put("nposts", new Integer(da.newPostDAO().countUserPosts(u.getId())));
}
}
Aggregations