SHARE
TWEET

Untitled

a guest Oct 21st, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     def sendNewspostNotifications(Newspost newspost, attachmentURL, newspostURL, update = false) {
  2.  
  3.         def subscribers = []
  4.         //User welche die die Kategorie direkt (spezielle Kategorie) abonnieren
  5.         subscribers.addAll(newspost.category.subscribers)
  6.  
  7.         //User die alle Kategorien abbonieren
  8.         subscribers.addAll(User.findAllBySubscribe_all(true));
  9.  
  10.         //Nur aktive User berücksichtigen
  11.         subscribers.removeAll { it.status != User.STATUS_ACTIVE}
  12.  
  13.  
  14.         for (def user: subscribers) {
  15.  
  16.             if (user.newspostEmailNotification) {
  17.                 def betreff = "[Iwinews 2.0 - ${newspost.category.name}] ${StringEscapeUtils.unescapeHtml(newspost.title)} ${update ? " -Update-" : ""}"
  18.                 def text = StringEscapeUtils.unescapeHtml(newspost.text)
  19.                 text += "\n\nLink zum Beitrag: ${newspostURL}"
  20.                 def attachments = NewspostAttachment.findAllByNewsPost(newspost)
  21.                 if (attachments.size() > 0) {
  22.                     text += "\n\n_______________________________________________________________\n\nAnhänge:\n"
  23.                     for (def attachment: attachments) {
  24.                         text += "\n- ${attachment.filename} (Downloadlink: ${attachmentURL}/${attachment.id})"
  25.                     }
  26.                 }
  27.                 //Footer mit Kategorien
  28.                 emailService.setFooterToEmail(text)
  29.  
  30.                 //Absenderadresse bestimmen
  31.  
  32.                 def fromAdress, fromName
  33.  
  34.                 //interner User
  35.                 if (newspost.user) {
  36.                     fromAdress = newspost.user.email
  37.                     fromName = newspost.user.nickname
  38.                 }
  39.  
  40.                 //gesendet von extern
  41.                 else {
  42.                     fromAdress = newspost.emailExternal
  43.                     fromName = newspost.emailExternalPersonName
  44.                 }
  45.  
  46.                 emailService.sendMail(user.email, betreff, text, fromAdress, fromName)
  47.             }
  48.         }
  49.     }
RAW Paste Data
Top