1 43 package net.jforum.view.forum; 44 45 import java.util.ArrayList ; 46 import java.util.HashMap ; 47 import java.util.Iterator ; 48 import java.util.List ; 49 import java.util.Map ; 50 51 import net.jforum.Command; 52 import net.jforum.JForumExecutionContext; 53 import net.jforum.dao.DataAccessDriver; 54 import net.jforum.dao.UserDAO; 55 import net.jforum.entities.Forum; 56 import net.jforum.entities.Topic; 57 import net.jforum.entities.User; 58 import net.jforum.repository.ForumRepository; 59 import net.jforum.repository.TopicRepository; 60 import net.jforum.util.I18n; 61 import net.jforum.util.preferences.ConfigKeys; 62 import net.jforum.util.preferences.SystemGlobals; 63 import net.jforum.util.preferences.TemplateKeys; 64 import net.jforum.view.forum.common.TopicsCommon; 65 import net.jforum.view.forum.common.ViewCommon; 66 67 74 public class RecentTopicsAction extends Command 75 { 76 private List forums; 77 78 public void list() throws Exception 79 { 80 int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE); 81 82 this.setTemplateName(TemplateKeys.RECENT_LIST); 83 84 this.context.put("postsPerPage", new Integer (postsPerPage)); 85 this.context.put("topics", this.topics()); 86 this.context.put("forums", this.forums); 87 this.context.put("pageTitle", I18n.getMessage("ForumBase.recentTopics")); 88 89 TopicsCommon.topicListingBase(); 90 this.request.setAttribute("template", null); 91 } 92 93 List topics() throws Exception 94 { 95 int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE); 96 List tmpTopics = TopicRepository.getRecentTopics(); 97 98 this.forums = new ArrayList (postsPerPage); 99 100 for (Iterator iter = tmpTopics.iterator(); iter.hasNext(); ) { 101 Topic t = (Topic)iter.next(); 102 103 if (TopicsCommon.isTopicAccessible(t.getForumId())) { 104 Forum f = ForumRepository.getForum(t.getForumId()); 106 forums.add(f); 107 } 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() throws Exception 119 { 120 DataAccessDriver da = DataAccessDriver.getInstance(); 121 122 UserDAO udao = da.newUserDAO(); 123 User u = udao.selectById(this.request.getIntParameter("user_id")); 124 125 if (u.getId() == 0) { 126 this.context.put("message", I18n.getMessage("User.notFound")); 127 this.setTemplateName(TemplateKeys.USER_NOT_FOUND); 128 return; 129 } 130 131 TopicsCommon.topicListingBase(); 132 133 int start = ViewCommon.getStartPage(); 134 int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE); 135 int postsPerPage = SystemGlobals.getIntValue(ConfigKeys.POST_PER_PAGE); 136 137 this.setTemplateName(TemplateKeys.RECENT_USER_TOPICS_SHOW); 138 139 int totalTopics = da.newTopicDAO().countUserTopics(u.getId()); 140 141 this.context.put("u", u); 142 this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getUsername()); 143 144 this.context.put("postsPerPage", new Integer (postsPerPage)); 145 146 List topics = da.newTopicDAO().selectByUserByLimit(u.getId(),start,topicsPerPage); 147 148 List l = TopicsCommon.prepareTopics(topics); 149 Map forums = new HashMap (); 150 151 for (Iterator iter = l.iterator(); iter.hasNext(); ) { 152 Topic t = (Topic)iter.next(); 153 154 Forum f = ForumRepository.getForum(t.getForumId()); 155 156 if (f == null) { 157 iter.remove(); 158 totalTopics--; 159 continue; 160 } 161 162 forums.put(new Integer (t.getForumId()), f); 163 } 164 165 this.context.put("topics", l); 166 this.context.put("forums", forums); 167 168 ViewCommon.contextToPagination(start, totalTopics, topicsPerPage); 169 } 170 } 171 | Popular Tags |