use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.
the class GenericForumDAO method fillForum.
protected Forum fillForum(ResultSet rs) throws SQLException {
Forum f = new Forum();
f.setId(rs.getInt("forum_id"));
f.setIdCategories(rs.getInt("categories_id"));
f.setName(rs.getString("forum_name"));
f.setDescription(rs.getString("forum_desc"));
f.setOrder(rs.getInt("forum_order"));
f.setTotalTopics(rs.getInt("forum_topics"));
f.setLastPostId(rs.getInt("forum_last_post_id"));
f.setModerated(rs.getInt("moderated") > 0);
f.setTotalPosts(this.countForumPosts(f.getId()));
return f;
}
use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.
the class GenericForumDAO method moveTopics.
/**
* @see net.jforum.dao.ForumDAO#moveTopics(java.lang.String[], int, int)
*/
public void moveTopics(String[] topics, int fromForumId, int toForumId) {
PreparedStatement p = null;
PreparedStatement t = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.moveTopics"));
t = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("PostModel.setForumByTopic"));
p.setInt(1, toForumId);
p.setInt(2, fromForumId);
t.setInt(1, toForumId);
TopicDAO tdao = DataAccessDriver.getInstance().newTopicDAO();
Forum f = this.selectById(toForumId);
for (int i = 0; i < topics.length; i++) {
int topicId = Integer.parseInt(topics[i]);
p.setInt(3, topicId);
t.setInt(2, topicId);
p.executeUpdate();
t.executeUpdate();
tdao.setModerationStatusByTopic(topicId, f.isModerated());
}
this.decrementTotalTopics(fromForumId, topics.length);
this.incrementTotalTopics(toForumId, topics.length);
this.setLastPost(fromForumId, this.getMaxPostId(fromForumId));
this.setLastPost(toForumId, this.getMaxPostId(toForumId));
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
DbUtils.close(p);
DbUtils.close(t);
}
}
use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.
the class SearchOperation method filterResults.
public final List filterResults(List results) {
List l = new ArrayList();
Map forums = new HashMap();
for (Iterator iter = results.iterator(); iter.hasNext(); ) {
Object currentObject = iter.next();
Integer forumId = new Integer(this.extractForumId(currentObject));
ForumFilterResult status = (ForumFilterResult) forums.get(forumId);
if (status == null) {
Forum f = ForumRepository.getForum(forumId.intValue());
status = new ForumFilterResult(f);
forums.put(forumId, status);
}
if (status.isValid()) {
// TODO: decouple
if (currentObject instanceof SearchPost) {
((SearchPost) currentObject).setForum(status.getForum());
}
l.add(currentObject);
}
}
return l;
}
use of net.jforum.entities.Forum in project jforum2 by rafaelsteil.
the class HottestTopicsAction method showTopicsByUser.
public void showTopicsByUser() {
DataAccessDriver da = DataAccessDriver.getInstance();
UserDAO udao = da.newUserDAO();
User u = udao.selectById(this.request.getIntParameter("user_id"));
if (u.getId() == 0) {
this.context.put("message", I18n.getMessage("User.notFound"));
this.setTemplateName(TemplateKeys.USER_NOT_FOUND);
return;
}
TopicsCommon.topicListingBase();
int start = ViewCommon.getStartPage();
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POSTS_PER_PAGE);
this.setTemplateName(TemplateKeys.HOTTEST_USER_TOPICS_SHOW);
int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
this.context.put("u", u);
this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername());
this.context.put("postsPerPage", new Integer(postsPerPage));
List topics = da.newTopicDAO().selectByUserByLimit(u.getId(), start, topicsPerPage);
List l = TopicsCommon.prepareTopics(topics);
Map forums = new HashMap();
for (Iterator iter = l.iterator(); iter.hasNext(); ) {
Topic t = (Topic) iter.next();
Forum f = ForumRepository.getForum(t.getForumId());
if (f == null) {
iter.remove();
totalTopics--;
continue;
}
forums.put(new Integer(t.getForumId()), f);
}
this.context.put("topics", l);
this.context.put("forums", forums);
ViewCommon.contextToPagination(start, totalTopics, topicsPerPage);
}
use of net.jforum.entities.Forum 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);
}
Aggregations