Moving notifications to models

This commit is contained in:
Gopesh Tulsyan 2014-08-12 16:04:24 +05:30
parent a39f4cf0dd
commit ebdf0df410
6 changed files with 86 additions and 18 deletions

View file

@ -33,4 +33,31 @@ class CallForPapers < ActiveRecord::Base
def end_week
end_date.strftime('%W').to_i
end
##
# Checks whether cfp dates is updated
#
# ====Returns
# * +True+ -> If cfp dates is updated and all other parameters are set
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
def notify_on_cfp_date_update?
!self.end_date.blank? && !self.start_date.blank?\
&& (self.start_date_changed? || self.end_date_changed?)\
&& self.conference.email_settings.send_on_call_for_papers_dates_updates\
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
end
##
# Checks whether cfp dates is updated
#
# ====Returns
# * +True+ -> If cfp dates is updated and all other parameters are set
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
def notify_on_schedule_public?
!self.end_date.blank? && !self.start_date.blank?\
&& (self.start_date_changed? || self.end_date_changed?)\
&& self.conference.email_settings.send_on_call_for_papers_dates_updates\
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
end
end

View file

@ -929,4 +929,30 @@ class Conference < ActiveRecord::Base
result
end
##
# Checks if conference is updated for email notifications.
#
# ====Returns
# * +True+ -> If conference is updated and all other parameters are set
# * +False+ -> Either conference is not updated or one or more parameter is not set
def notify_on_conf_dates_updates?
(self.start_date_changed? || self.end_date_changed?)\
&& self.email_settings.send_on_updated_conference_dates\
&& !self.email_settings.updated_conference_dates_subject.blank?\
&& self.email_settings.updated_conference_dates_template
end
##
# Checks if registration dates are updated for email notifications.
#
# ====Returns
# * +True+ -> If registration dates is updated and all other parameters are set
# * +False+ -> Either registration date is not updated or one or more parameter is not set
def notify_on_reg_dates?
(self.registration_start_date_changed? || self.registration_end_date_changed?)\
&& self.email_settings.send_on_updated_conference_registration_dates\
&& !self.email_settings.updated_conference_registration_dates_subject.blank?\
&& self.email_settings.updated_conference_registration_dates_template
end
end

View file

@ -12,6 +12,14 @@ class Venue < ActiveRecord::Base
size: { in: 0..500.kilobytes }
accepts_nested_attributes_for :lodgings, allow_destroy: true
def venue_notify?(conference)
(self.name_changed? || self.address_changed?) &&
(!self.name.blank? && !self.address.blank?) &&
(conference.email_settings.send_on_venue_update &&
!conference.email_settings.venue_update_subject.blank? &&
conference.email_settings.venue_update_template)
end
private
# TODO: create a module to be mixed into model to perform same operation