1 43 package net.jforum.dao.generic; 44 45 import java.sql.PreparedStatement ; 46 import java.sql.ResultSet ; 47 import java.sql.Statement ; 48 import java.sql.Timestamp ; 49 import java.util.ArrayList ; 50 import java.util.HashMap ; 51 import java.util.List ; 52 import java.util.Map ; 53 54 import net.jforum.JForumExecutionContext; 55 import net.jforum.dao.ModerationDAO; 56 import net.jforum.entities.ModerationPendingInfo; 57 import net.jforum.entities.Post; 58 import net.jforum.entities.TopicModerationInfo; 59 import net.jforum.util.preferences.SystemGlobals; 60 61 65 public class GenericModerationDAO implements ModerationDAO 66 { 67 70 public void aprovePost(int postId) throws Exception 71 { 72 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement( 73 SystemGlobals.getSql("ModerationModel.aprovePost")); 74 p.setTimestamp(1, new Timestamp (System.currentTimeMillis())); 75 p.setInt(2, postId); 76 p.executeUpdate(); 77 p.close(); 78 } 79 80 83 public Map topicsByForum(int forumId) throws Exception 84 { 85 Map m = new HashMap (); 86 87 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement( 88 SystemGlobals.getSql("ModerationModel.topicsByForum")); 89 p.setInt(1, forumId); 90 91 int lastId = 0; 92 TopicModerationInfo info = null; 93 94 ResultSet rs = p.executeQuery(); 95 while (rs.next()) { 96 int id = rs.getInt("topic_id"); 97 if (id != lastId) { 98 lastId = id; 99 100 if (info != null) { 101 m.put(new Integer (info.getTopicId()), info); 102 } 103 104 info = new TopicModerationInfo(); 105 info.setTopicId(id); 106 info.setTopicReplies(rs.getInt("topic_replies")); 107 info.setTopicTitle(rs.getString("topic_title")); 108 } 109 110 info.addPost(this.getPost(rs)); 111 } 112 113 if (info != null) { 114 m.put(new Integer (info.getTopicId()), info); 115 } 116 117 rs.close(); 118 p.close(); 119 120 return m; 121 } 122 123 protected Post getPost(ResultSet rs) throws Exception 124 { 125 Post p = new Post(); 126 p.setPostUsername(rs.getString("username")); 127 p.setId(rs.getInt("post_id")); 128 p.setUserId(rs.getInt("user_id")); 129 p.setBbCodeEnabled(rs.getInt("enable_bbcode") == 1); 130 p.setHtmlEnabled(rs.getInt("enable_html") == 1); 131 p.setSmiliesEnabled(rs.getInt("enable_smilies") == 1); 132 p.setSubject(rs.getString("post_subject")); 133 p.setText(this.getPostTextFromResultSet(rs)); 134 135 return p; 136 } 137 138 protected String getPostTextFromResultSet(ResultSet rs) throws Exception 139 { 140 return rs.getString("post_text"); 141 } 142 143 146 public List categoryPendingModeration() throws Exception 147 { 148 List l = new ArrayList (); 149 int lastId = 0; 150 ModerationPendingInfo info = null; 151 Statement s = JForumExecutionContext.getConnection().createStatement(); 152 153 ResultSet rs = s.executeQuery(SystemGlobals.getSql("ModerationModel.categoryPendingModeration")); 154 while (rs.next()) { 155 int id = rs.getInt("categories_id"); 156 if (id != lastId) { 157 lastId = id; 158 159 if (info != null) { 160 l.add(info); 161 } 162 163 info = new ModerationPendingInfo(); 164 info.setCategoryName(rs.getString("title")); 165 info.setCategoryId(id); 166 } 167 168 info.addInfo(rs.getString("forum_name"), 169 rs.getInt("forum_id"), 170 rs.getInt("total")); 171 } 172 173 if (info != null) { 174 l.add(info); 175 } 176 177 rs.close(); 178 s.close(); 179 180 return l; 181 } 182 183 } 184 | Popular Tags |