001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on Mar 02, 2007
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.forum;
044:
045: import java.util.ArrayList;
046: import java.util.HashMap;
047: import java.util.Iterator;
048: import java.util.List;
049: import java.util.Map;
050:
051: import net.jforum.Command;
052: import net.jforum.JForumExecutionContext;
053: import net.jforum.dao.DataAccessDriver;
054: import net.jforum.dao.UserDAO;
055: import net.jforum.entities.Forum;
056: import net.jforum.entities.Topic;
057: import net.jforum.entities.User;
058: import net.jforum.repository.ForumRepository;
059: import net.jforum.repository.TopicRepository;
060: import net.jforum.util.I18n;
061: import net.jforum.util.preferences.ConfigKeys;
062: import net.jforum.util.preferences.SystemGlobals;
063: import net.jforum.util.preferences.TemplateKeys;
064: import net.jforum.view.forum.common.TopicsCommon;
065: import net.jforum.view.forum.common.ViewCommon;
066:
067: /**
068: * Display a list of hottest Topics
069: *
070: * @author James Yong
071: * @author Rafael Steil
072: * @author Andowson Chang
073: * @version $Id: HottestTopicsAction.java,v 1.2 2007/08/20 19:35:52 rafaelsteil Exp $
074: */
075: public class HottestTopicsAction extends Command {
076: private List forums;
077:
078: public void list() {
079: int postsPerPage = SystemGlobals
080: .getIntValue(ConfigKeys.POSTS_PER_PAGE);
081:
082: this .setTemplateName(TemplateKeys.HOTTEST_LIST);
083:
084: this .context.put("postsPerPage", new Integer(postsPerPage));
085: this .context.put("topics", this .topics());
086: this .context.put("forums", this .forums);
087: this .context.put("pageTitle", I18n
088: .getMessage("ForumBase.hottestTopics"));
089:
090: TopicsCommon.topicListingBase();
091: this .request.setAttribute("template", null);
092: }
093:
094: List topics() {
095: int postsPerPage = SystemGlobals
096: .getIntValue(ConfigKeys.POSTS_PER_PAGE);
097: List tmpTopics = TopicRepository.getHottestTopics();
098:
099: this .forums = new ArrayList(postsPerPage);
100:
101: for (Iterator iter = tmpTopics.iterator(); iter.hasNext();) {
102: Topic t = (Topic) iter.next();
103:
104: if (TopicsCommon.isTopicAccessible(t.getForumId())) {
105: // Get name of forum that the topic refers to
106: Forum f = ForumRepository.getForum(t.getForumId());
107: forums.add(f);
108: } else {
109: iter.remove();
110: }
111: }
112:
113: JForumExecutionContext.getRequest().removeAttribute("template");
114:
115: return TopicsCommon.prepareTopics(tmpTopics);
116: }
117:
118: public void showTopicsByUser() {
119: DataAccessDriver da = DataAccessDriver.getInstance();
120:
121: UserDAO udao = da.newUserDAO();
122: User u = udao.selectById(this .request
123: .getIntParameter("user_id"));
124:
125: if (u.getId() == 0) {
126: this .context.put("message", I18n
127: .getMessage("User.notFound"));
128: this .setTemplateName(TemplateKeys.USER_NOT_FOUND);
129: return;
130: }
131:
132: TopicsCommon.topicListingBase();
133:
134: int start = ViewCommon.getStartPage();
135: int topicsPerPage = SystemGlobals
136: .getIntValue(ConfigKeys.TOPICS_PER_PAGE);
137: int postsPerPage = SystemGlobals
138: .getIntValue(ConfigKeys.POSTS_PER_PAGE);
139:
140: this .setTemplateName(TemplateKeys.HOTTEST_USER_TOPICS_SHOW);
141:
142: int totalTopics = da.newTopicDAO().countUserTopics(u.getId());
143:
144: this .context.put("u", u);
145: this .context.put("pageTitle", I18n
146: .getMessage("ForumListing.userTopics")
147: + " " + u.getUsername());
148:
149: this .context.put("postsPerPage", new Integer(postsPerPage));
150:
151: List topics = da.newTopicDAO().selectByUserByLimit(u.getId(),
152: start, topicsPerPage);
153:
154: List l = TopicsCommon.prepareTopics(topics);
155: Map forums = new HashMap();
156:
157: for (Iterator iter = l.iterator(); iter.hasNext();) {
158: Topic t = (Topic) iter.next();
159:
160: Forum f = ForumRepository.getForum(t.getForumId());
161:
162: if (f == null) {
163: iter.remove();
164: totalTopics--;
165: continue;
166: }
167:
168: forums.put(new Integer(t.getForumId()), f);
169: }
170:
171: this .context.put("topics", l);
172: this .context.put("forums", forums);
173:
174: ViewCommon.contextToPagination(start, totalTopics,
175: topicsPerPage);
176: }
177: }
|