1 43 package net.jforum.summary; 44 45 import java.util.Calendar ; 46 import java.util.Date ; 47 import java.util.List ; 48 49 import net.jforum.dao.DataAccessDriver; 50 import net.jforum.dao.SummaryDAO; 51 import net.jforum.util.mail.Spammer; 52 import net.jforum.util.preferences.ConfigKeys; 53 import net.jforum.util.preferences.SystemGlobals; 54 import net.jforum.view.forum.common.ViewCommon; 55 56 import org.apache.log4j.Logger; 57 58 import freemarker.template.SimpleHash; 59 60 69 public class SummaryModel extends Spammer 70 { 71 private SummaryDAO dao; 72 73 private static Logger logger = Logger.getLogger(SummaryModel.class); 74 75 public SummaryModel() 76 { 77 this.dao = DataAccessDriver.getInstance().newSummaryDAO(); 78 } 79 80 public void sendPostsSummary(List recipients) throws Exception 81 { 82 logger.info("Sending Weekly summary..."); 83 84 int daysBefore = Integer.parseInt(SystemGlobals.getValue(ConfigKeys.SUMMARY_DAYS_BEFORE)); 86 87 long dateBefore = Calendar.getInstance().getTimeInMillis() - (daysBefore * 1000 * 60 * 60 * 24); 89 90 List posts = listPosts(new Date (dateBefore), new Date ()); 91 92 String forumLink = ViewCommon.getForumLink(); 93 94 SimpleHash params = new SimpleHash(); 95 params.put("posts", posts); 96 params.put("url", forumLink); 97 98 String subject = SystemGlobals.getValue(ConfigKeys.MAIL_SUMMARY_SUBJECT); 99 100 this.prepareMessage(recipients, params, subject, SystemGlobals.getValue(ConfigKeys.MAIL_SUMMARY_FILE)); 101 super.dispatchMessages(); 102 } 103 104 110 public List listRecipients() throws Exception 111 { 112 return this.dao.listRecipients(); 113 } 114 115 123 public List listPosts(Date firstDate, Date lastDate) throws Exception 124 { 125 return this.dao.selectLastPosts(firstDate, lastDate); 126 } 127 } 128 | Popular Tags |