61 lines
2.5 KiB
Haskell
61 lines
2.5 KiB
Haskell
{-# OPTIONS_GHC -fno-warn-unused-do-bind #-} -- ihamletFile discards do results
|
|
|
|
module Jobs.Handler.SendNotification.SheetInactive
|
|
( dispatchNotificationSheetSoonInactive
|
|
, dispatchNotificationSheetInactive
|
|
) where
|
|
|
|
import Import
|
|
|
|
import Handler.Utils.Mail
|
|
|
|
import Text.Hamlet
|
|
import qualified Data.CaseInsensitive as CI
|
|
|
|
import qualified Database.Esqueleto as E
|
|
|
|
dispatchNotificationSheetSoonInactive :: SheetId -> UserId -> Handler ()
|
|
dispatchNotificationSheetSoonInactive nSheet jRecipient = userMailT jRecipient $ do
|
|
(Course{..}, Sheet{..}) <- liftHandlerT . runDB $ do
|
|
sheet <- getJust nSheet
|
|
course <- belongsToJust sheetCourse sheet
|
|
return (course, sheet)
|
|
setSubjectI $ MsgMailSubjectSheetSoonInactive courseShorthand sheetName
|
|
|
|
MsgRenderer mr <- getMailMsgRenderer
|
|
let termDesc = mr . ShortTermIdentifier $ unTermKey courseTerm
|
|
tid = courseTerm
|
|
ssh = courseSchool
|
|
csh = courseShorthand
|
|
shn = sheetName
|
|
|
|
addAlternatives $ do
|
|
let editNotifications = $(ihamletFile "templates/mail/editNotifications.hamlet")
|
|
providePreferredAlternative ($(ihamletFile "templates/mail/sheetSoonInactive.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX))
|
|
|
|
dispatchNotificationSheetInactive :: SheetId -> UserId -> Handler ()
|
|
dispatchNotificationSheetInactive nSheet jRecipient = userMailT jRecipient $ do
|
|
(Course{..}, Sheet{..}, nrSubs, nrSubmitters) <- liftHandlerT . runDB $ do
|
|
sheet <- getJust nSheet
|
|
course <- belongsToJust sheetCourse sheet
|
|
nrSubs <- count [SubmissionSheet ==. nSheet]
|
|
(E.Value nrSubmitters:_) <- E.select . E.from $ \(subUser `E.InnerJoin` submission) -> do
|
|
E.on $ subUser E.^. SubmissionUserSubmission E.==. submission E.^. SubmissionId
|
|
E.where_ $ submission E.^. SubmissionSheet E.==. E.val nSheet
|
|
-- E.distinctOn [E.don (subUser E.^. SubmissionUserUser)] -- Not necessary due to UniqueSubmisionUser
|
|
return (E.countRows :: E.SqlExpr (E.Value Int64))
|
|
return (course, sheet, nrSubs, nrSubmitters)
|
|
setSubjectI $ MsgMailSubjectSheetInactive courseShorthand sheetName
|
|
|
|
MsgRenderer mr <- getMailMsgRenderer
|
|
let termDesc = mr . ShortTermIdentifier $ unTermKey courseTerm
|
|
tid = courseTerm
|
|
ssh = courseSchool
|
|
csh = courseShorthand
|
|
shn = sheetName
|
|
|
|
addAlternatives $ do
|
|
let editNotifications = $(ihamletFile "templates/mail/editNotifications.hamlet")
|
|
providePreferredAlternative ($(ihamletFile "templates/mail/sheetInactive.hamlet") :: HtmlUrlI18n UniWorXMessage (Route UniWorX))
|
|
|