Class: ConsolidatedOpeningReminderMailer Private

Inherits:
ActivityMailer show all
Defined in:
app/mailers/consolidated_opening_reminder_mailer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The mailer for Consolidated Opening Reminders.

Instance Method Summary collapse

Instance Method Details

#email(recipient:, notification:, view_path:, layout_path: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Emails a recipient, informing him of the upcoming items which are starting for a particular course.

Parameters:

  • recipient (User)

    The recipient of the email.

  • notification (Course::Notification|UserNotification)

    The notification to be made available to the view, accessible using [email protected]+.

  • view_path (String)

    The path to the view which should be rendered.

  • layout_path (String)

    The filename in app/views/layouts which should be rendered. If not specified, the 'mailer' layout specified in ApplicationMailer is used.


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/mailers/consolidated_opening_reminder_mailer.rb', line 17

def email(recipient:, notification:, view_path:, layout_path: nil)
  ActsAsTenant.without_tenant do
    @recipient = recipient
    @notification = notification
    @course = notification.activity.object
    @layout = layout_path
    @items_hash = Course::LessonPlan::Item.upcoming_items_from_course_by_type(@course)
    # Lesson plan item start at times could have been changed between the time the mailer job
    # was enqueued and the time this function is called to render the email.
    # Return if there are no items so a consolidated email with no items doesn't get sent.
    return if @items_hash.empty?

    mail(to: recipient.email, template: view_path)
  end
end