Advertisement
Guest User

Untitled

a guest
Oct 9th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.91 KB | None | 0 0
  1. module Mailing
  2.   class OnboardingTeacherService
  3.     include Service
  4.  
  5.     def initialize(operation, teacher)
  6.       @operation = operation
  7.       @teacher = teacher
  8.     end
  9.  
  10.     def call
  11.       send(@operation, @teacher) if respond_to?(@operation)
  12.     end
  13.  
  14.     private
  15.  
  16.     def send_teacher_how_to_add_students(teacher)
  17.       return unless Feature.teacher_how_to_add_students?
  18.  
  19.       return if teacher.email.blank?
  20.       return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
  21.       return unless teacher.groups.any? && teacher.students.uniq.count < 2
  22.  
  23.       AzbookaMailer.send_mail(:teacher_how_to_add_students, email_teacher_how_to_add_students(teacher))
  24.     end
  25.  
  26.     def email_teacher_how_to_add_students(teacher)
  27.       class_book = teacher.class_book.first
  28.       {
  29.         email: teacher.email,
  30.         tname: teacher.io,
  31.         addedclass: class_book.name
  32.       }
  33.     end
  34.  
  35.     def send_help_for_teacher_with_add_students(teacher)
  36.       return unless Feature.help_for_teacher_with_add_students?
  37.  
  38.       return if teacher.email.blank?
  39.       return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
  40.       return unless teacher.groups.any? && teacher.students.uniq.count < 3
  41.  
  42.       AzbookaMailer.send_mail(:help_for_teacher_with_add_students, email_help_for_teacher_with_add_students(teacher))
  43.     end
  44.  
  45.     def email_help_for_teacher_with_add_students(teacher)
  46.       class_book = teacher.class_books.order(created_at: :desc).first
  47.       {
  48.         email: teacher.email,
  49.         tname: teacher.io,
  50.         addedclass: class_book.name,
  51.         classid: class_book.id
  52.       }
  53.     end
  54.  
  55.     def send_teacher_how_to_add_parents(teacher)
  56.       return unless Feature.teacher_how_to_add_parents?
  57.  
  58.       return if teacher.email.blank?
  59.       return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
  60.       return unless teacher.groups.present? && teacher.students.present? &&
  61.                     teacher.students.all? { |s| s.parent2_id.nil? }
  62.  
  63.       AzbookaMailer.send_mail(:teacher_how_to_add_parents, email_teacher_how_to_add_parent(teacher))
  64.     end
  65.  
  66.     def email_teacher_how_to_add_parent(teacher)
  67.       {
  68.         email: teacher.email,
  69.         tname: teacher.io,
  70.         classid: teacher.group_with_most_students_without_parents.id
  71.       }
  72.     end
  73.  
  74.     def send_help_for_teacher_to_add_parents(teacher)
  75.       return unless Feature.help_for_teacher_to_add_parents?
  76.  
  77.       return if teacher.email.blank?
  78.       return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
  79.       return unless teacher.groups.any? && teacher.students.uniq.count >= 3 && teacher.students.none?(&:parent2_id)
  80.  
  81.       AzbookaMailer.send_mail(:help_for_teacher_to_add_parents, email_help_for_teacher_to_add_parents(teacher))
  82.     end
  83.  
  84.     def email_help_for_teacher_to_add_parents(teacher)
  85.       class_book = teacher.group_with_most_students_without_parents.class_book
  86.       {
  87.         email: teacher.email,
  88.         tname: teacher.io,
  89.         addedclass: class_book.name,
  90.         students: class_book.students.map(&:name_with_short_surname).join(', '),
  91.         classid: class_book
  92.       }
  93.     end
  94.  
  95.     def send_activation_certificate_for_teacher_activity(teacher)
  96.       return unless Feature.activation_certificate_for_teacher_activity?
  97.  
  98.       return if teacher.email.blank?
  99.       return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
  100.       return unless teacher&.class_books&.any? && (teacher.students.count == 5) &&
  101.                     teacher.students.all? { |s| s.parent2.present? }
  102.  
  103.       AzbookaMailer.send_mail(:activation_certificate_for_teacher_activity,
  104.                               email_activation_certificate_for_teacher_activity(teacher))
  105.     end
  106.  
  107.     def email_activation_certificate_for_teacher_activity(teacher)
  108.       {
  109.         email: teacher.email,
  110.         tname: teacher.io
  111.       }
  112.     end
  113.   end
  114. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement