Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Mailing
- class OnboardingTeacherService
- include Service
- def initialize(operation, teacher)
- @operation = operation
- @teacher = teacher
- end
- def call
- send(@operation, @teacher) if respond_to?(@operation)
- end
- private
- def send_teacher_how_to_add_students(teacher)
- return unless Feature.teacher_how_to_add_students?
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher.groups.any? && teacher.students.uniq.count < 2
- AzbookaMailer.send_mail(:teacher_how_to_add_students, email_teacher_how_to_add_students(teacher))
- end
- def email_teacher_how_to_add_students(teacher)
- class_book = teacher.class_book.first
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name
- }
- end
- def send_help_for_teacher_with_add_students(teacher)
- return unless Feature.help_for_teacher_with_add_students?
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
- return unless teacher.groups.any? && teacher.students.uniq.count < 3
- AzbookaMailer.send_mail(:help_for_teacher_with_add_students, email_help_for_teacher_with_add_students(teacher))
- end
- def email_help_for_teacher_with_add_students(teacher)
- class_book = teacher.class_books.order(created_at: :desc).first
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name,
- classid: class_book.id
- }
- end
- def send_teacher_how_to_add_parents(teacher)
- return unless Feature.teacher_how_to_add_parents?
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher.groups.present? && teacher.students.present? &&
- teacher.students.all? { |s| s.parent2_id.nil? }
- AzbookaMailer.send_mail(:teacher_how_to_add_parents, email_teacher_how_to_add_parent(teacher))
- end
- def email_teacher_how_to_add_parent(teacher)
- {
- email: teacher.email,
- tname: teacher.io,
- classid: teacher.group_with_most_students_without_parents.id
- }
- end
- def send_help_for_teacher_to_add_parents(teacher)
- return unless Feature.help_for_teacher_to_add_parents?
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers) == 'c'
- return unless teacher.groups.any? && teacher.students.uniq.count >= 3 && teacher.students.none?(&:parent2_id)
- AzbookaMailer.send_mail(:help_for_teacher_to_add_parents, email_help_for_teacher_to_add_parents(teacher))
- end
- def email_help_for_teacher_to_add_parents(teacher)
- class_book = teacher.group_with_most_students_without_parents.class_book
- {
- email: teacher.email,
- tname: teacher.io,
- addedclass: class_book.name,
- students: class_book.students.map(&:name_with_short_surname).join(', '),
- classid: class_book
- }
- end
- def send_activation_certificate_for_teacher_activity(teacher)
- return unless Feature.activation_certificate_for_teacher_activity?
- return if teacher.email.blank?
- return unless teacher.label_for(:email_teacher_onboarding_triggers).in?(%w[b c])
- return unless teacher&.class_books&.any? && (teacher.students.count == 5) &&
- teacher.students.all? { |s| s.parent2.present? }
- AzbookaMailer.send_mail(:activation_certificate_for_teacher_activity,
- email_activation_certificate_for_teacher_activity(teacher))
- end
- def email_activation_certificate_for_teacher_activity(teacher)
- {
- email: teacher.email,
- tname: teacher.io
- }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement