2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2021-02-20 09:57:27 -08:00
|
|
|
# == Schema Information
|
|
|
|
|
#
|
|
|
|
|
# Table name: email_settings
|
|
|
|
|
#
|
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
|
# accepted_body :text
|
|
|
|
|
# accepted_subject :string
|
|
|
|
|
# booths_acceptance_body :text
|
|
|
|
|
# booths_acceptance_subject :string
|
|
|
|
|
# booths_rejection_body :text
|
|
|
|
|
# booths_rejection_subject :string
|
|
|
|
|
# cfp_dates_updated_body :text
|
|
|
|
|
# cfp_dates_updated_subject :string
|
|
|
|
|
# conference_dates_updated_body :text
|
|
|
|
|
# conference_dates_updated_subject :string
|
|
|
|
|
# conference_registration_dates_updated_body :text
|
|
|
|
|
# conference_registration_dates_updated_subject :string
|
|
|
|
|
# confirmed_without_registration_body :text
|
|
|
|
|
# confirmed_without_registration_subject :string
|
|
|
|
|
# program_schedule_public_body :text
|
|
|
|
|
# program_schedule_public_subject :string
|
|
|
|
|
# registration_body :text
|
|
|
|
|
# registration_subject :string
|
|
|
|
|
# rejected_body :text
|
|
|
|
|
# rejected_subject :string
|
|
|
|
|
# send_on_accepted :boolean default(FALSE)
|
|
|
|
|
# send_on_booths_acceptance :boolean default(FALSE)
|
|
|
|
|
# send_on_booths_rejection :boolean default(FALSE)
|
|
|
|
|
# send_on_cfp_dates_updated :boolean default(FALSE)
|
|
|
|
|
# send_on_conference_dates_updated :boolean default(FALSE)
|
|
|
|
|
# send_on_conference_registration_dates_updated :boolean default(FALSE)
|
|
|
|
|
# send_on_confirmed_without_registration :boolean default(FALSE)
|
|
|
|
|
# send_on_program_schedule_public :boolean default(FALSE)
|
|
|
|
|
# send_on_registration :boolean default(FALSE)
|
|
|
|
|
# send_on_rejected :boolean default(FALSE)
|
|
|
|
|
# send_on_submitted_proposal :boolean default(FALSE)
|
|
|
|
|
# send_on_venue_updated :boolean default(FALSE)
|
|
|
|
|
# submitted_proposal_body :text
|
|
|
|
|
# submitted_proposal_subject :string
|
|
|
|
|
# venue_updated_body :text
|
|
|
|
|
# venue_updated_subject :string
|
|
|
|
|
# created_at :datetime
|
|
|
|
|
# updated_at :datetime
|
|
|
|
|
# conference_id :integer
|
|
|
|
|
#
|
2017-09-05 22:23:34 +03:00
|
|
|
class EmailSettings < ApplicationRecord
|
2016-03-29 23:22:32 +05:30
|
|
|
belongs_to :conference
|
|
|
|
|
|
2016-05-24 23:54:46 +05:30
|
|
|
has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id }
|
|
|
|
|
|
2017-08-02 20:10:47 +03:00
|
|
|
def get_values(conference, user, event = nil, booth = nil)
|
2013-01-14 08:49:49 +01:00
|
|
|
h = {
|
2018-11-13 18:01:49 -08:00
|
|
|
'email' => user.email,
|
|
|
|
|
'name' => user.name,
|
|
|
|
|
'conference' => conference.title,
|
|
|
|
|
'conference_start_date' => conference.start_date,
|
|
|
|
|
'conference_end_date' => conference.end_date,
|
|
|
|
|
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url(
|
2016-03-22 18:14:40 +01:00
|
|
|
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
|
2014-07-24 10:11:38 +05:30
|
|
|
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
|
2016-03-22 18:14:40 +01:00
|
|
|
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
|
2014-12-17 14:28:31 +01:00
|
|
|
|
2018-11-13 18:01:49 -08:00
|
|
|
'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url(
|
2016-03-22 18:14:40 +01:00
|
|
|
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
|
2013-01-14 08:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-25 13:29:02 +02:00
|
|
|
if conference.program.cfp
|
|
|
|
|
h['cfp_start_date'] = conference.program.cfp.start_date
|
|
|
|
|
h['cfp_end_date'] = conference.program.cfp.end_date
|
2014-12-17 14:28:31 +01:00
|
|
|
else
|
|
|
|
|
h['cfp_start_date'] = 'Unknown'
|
|
|
|
|
h['cfp_end_date'] = 'Unknown'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if conference.venue
|
|
|
|
|
h['venue'] = conference.venue.name
|
|
|
|
|
h['venue_address'] = conference.venue.address
|
|
|
|
|
else
|
|
|
|
|
h['venue'] = 'Unknown'
|
|
|
|
|
h['venue_address'] = 'Unknown'
|
|
|
|
|
end
|
|
|
|
|
|
2014-08-18 14:33:02 +02:00
|
|
|
if conference.registration_period
|
|
|
|
|
h['registration_start_date'] = conference.registration_period.start_date
|
|
|
|
|
h['registration_end_date'] = conference.registration_period.end_date
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-17 18:55:47 +02:00
|
|
|
if event
|
2014-06-24 12:14:53 +03:00
|
|
|
h['eventtitle'] = event.title
|
2016-09-14 22:42:04 -04:00
|
|
|
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url(
|
2016-03-22 18:14:40 +01:00
|
|
|
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
|
2021-04-16 01:08:28 -07:00
|
|
|
h['committee_review'] = event.committee_review
|
|
|
|
|
h['committee_review_html'] = ApplicationController.helpers.markdown(event.committee_review)
|
2013-01-14 08:49:49 +01:00
|
|
|
end
|
2017-08-02 20:10:47 +03:00
|
|
|
|
|
|
|
|
if booth
|
|
|
|
|
h['booth_title'] = booth.title
|
|
|
|
|
end
|
2013-01-14 08:49:49 +01:00
|
|
|
h
|
|
|
|
|
end
|
|
|
|
|
|
2014-07-25 13:13:35 +05:30
|
|
|
def generate_event_mail(event, event_template)
|
2016-03-06 00:19:55 +01:00
|
|
|
values = get_values(event.program.conference, event.submitter, event)
|
2014-07-25 13:13:35 +05:30
|
|
|
parse_template(event_template, values)
|
2013-01-14 08:49:49 +01:00
|
|
|
end
|
|
|
|
|
|
2014-07-17 15:59:44 +05:30
|
|
|
def generate_email_on_conf_updates(conference, user, conf_update_template)
|
2014-07-23 13:42:03 +02:00
|
|
|
values = get_values(conference, user)
|
2014-07-25 13:13:35 +05:30
|
|
|
parse_template(conf_update_template, values)
|
2014-07-23 13:42:03 +02:00
|
|
|
end
|
|
|
|
|
|
2017-08-02 20:10:47 +03:00
|
|
|
def generate_booth_mail(booth, booth_template)
|
|
|
|
|
values = get_values(booth.conference, booth.submitter, nil, booth)
|
|
|
|
|
parse_template(booth_template, values)
|
|
|
|
|
end
|
|
|
|
|
|
2015-07-17 18:55:47 +02:00
|
|
|
private
|
|
|
|
|
|
2013-01-14 08:49:49 +01:00
|
|
|
def parse_template(text, values)
|
|
|
|
|
values.each do |key, value|
|
2014-07-23 13:42:03 +02:00
|
|
|
if value.kind_of?(Date)
|
|
|
|
|
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') unless text.blank?
|
|
|
|
|
else
|
|
|
|
|
text = text.gsub "{#{key}}", value unless text.blank? || value.blank?
|
|
|
|
|
end
|
2013-01-14 08:49:49 +01:00
|
|
|
end
|
|
|
|
|
text
|
|
|
|
|
end
|
2013-02-18 20:36:21 +01:00
|
|
|
end
|