osem-fcy/app/models/email_settings.rb

72 lines
2.5 KiB
Ruby
Raw Normal View History

2013-01-14 08:49:49 +01:00
class EmailSettings < ActiveRecord::Base
belongs_to :conference
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,
'conference_start_date' => conference.start_date,
'conference_end_date' => conference.end_date,
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
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(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
2013-01-14 08:49:49 +01: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
if conference.registration_period
h['registration_start_date'] = conference.registration_period.start_date
h['registration_end_date'] = conference.registration_period.end_date
end
if event
2014-06-24 12:14:53 +03:00
h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposal_index_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
2013-01-14 08:49:49 +01:00
end
h
end
def generate_event_mail(event, event_template)
values = get_values(event.program.conference, event.submitter, event)
parse_template(event_template, values)
2013-01-14 08:49:49 +01:00
end
def generate_email_on_conf_updates(conference, user, conf_update_template)
values = get_values(conference, user)
parse_template(conf_update_template, values)
end
private
2013-01-14 08:49:49 +01:00
def parse_template(text, values)
values.each do |key, value|
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