2013-01-14 08:49:49 +01:00
|
|
|
class EmailSettings < ActiveRecord::Base
|
2015-10-06 11:32:40 +02:00
|
|
|
attr_accessible :send_on_registration, :registration_subject, :registration_body,
|
|
|
|
|
:send_on_accepted, :accepted_subject, :accepted_body,
|
|
|
|
|
:send_on_rejected, :rejected_subject, :rejected_body,
|
|
|
|
|
:send_on_confirmed_without_registration, :confirmed_without_registration_subject, :confirmed_without_registration_body,
|
2015-10-14 15:34:23 +02:00
|
|
|
:send_on_conference_dates_updated, :conference_dates_updated_subject, :conference_dates_updated_body,
|
|
|
|
|
:send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body,
|
|
|
|
|
:send_on_venue_updated, :venue_updated_subject, :venue_updated_body,
|
|
|
|
|
:send_on_call_for_papers_dates_updated, :call_for_papers_dates_updated_subject, :call_for_papers_dates_updated_body,
|
2015-10-06 11:32:40 +02:00
|
|
|
:send_on_call_for_papers_schedule_public, :call_for_papers_schedule_public_subject, :call_for_papers_schedule_public_body
|
2013-01-14 08:49:49 +01:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
def get_values(conference, user, event = nil)
|
2013-01-14 08:49:49 +01:00
|
|
|
h = {
|
2014-06-26 15:43:24 +03:00
|
|
|
'email' => user.email,
|
|
|
|
|
'name' => user.name,
|
|
|
|
|
'conference' => conference.title,
|
2014-07-23 13:42:03 +02:00
|
|
|
'conference_start_date' => conference.start_date,
|
|
|
|
|
'conference_end_date' => conference.end_date,
|
2015-02-27 13:37:40 +01:00
|
|
|
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registrations_url(
|
2014-07-24 10:11:38 +05:30
|
|
|
conference.short_title, host: CONFIG['url_for_emails']),
|
|
|
|
|
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
|
|
|
|
|
conference.short_title, host: CONFIG['url_for_emails']),
|
2014-12-17 14:28:31 +01:00
|
|
|
|
2014-11-27 14:31:44 +01:00
|
|
|
'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url(
|
2014-07-24 10:11:38 +05:30
|
|
|
conference.short_title, host: CONFIG['url_for_emails'])
|
2013-01-14 08:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
2014-12-17 14:28:31 +01:00
|
|
|
if conference.call_for_paper
|
|
|
|
|
h['cfp_start_date'] = conference.call_for_paper.start_date
|
|
|
|
|
h['cfp_end_date'] = conference.call_for_paper.end_date
|
|
|
|
|
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
|
2015-02-27 13:37:40 +01:00
|
|
|
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_index_url(
|
|
|
|
|
conference.short_title, host: CONFIG['url_for_emails'])
|
2013-01-14 08:49:49 +01:00
|
|
|
end
|
|
|
|
|
h
|
|
|
|
|
end
|
|
|
|
|
|
2014-07-25 13:13:35 +05:30
|
|
|
def generate_event_mail(event, event_template)
|
2013-01-17 13:56:05 +01:00
|
|
|
values = get_values(event.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
|
|
|
|
|
|
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
|