2013-01-07 09:04:09 +01:00
|
|
|
class Venue < ActiveRecord::Base
|
2014-11-20 14:57:03 +01:00
|
|
|
belongs_to :conference
|
2016-04-03 19:25:41 +05:30
|
|
|
has_one :commercial, as: :commercialable, dependent: :destroy
|
2015-11-07 11:43:36 +02:00
|
|
|
has_many :rooms, dependent: :destroy
|
2013-01-07 09:04:09 +01:00
|
|
|
before_create :generate_guid
|
2014-11-20 14:57:03 +01:00
|
|
|
|
2016-04-03 22:08:46 +05:30
|
|
|
accepts_nested_attributes_for :commercial, allow_destroy: true
|
2014-11-20 14:57:03 +01:00
|
|
|
validates :name, :street, :city, :country, presence: true
|
2015-11-07 11:43:36 +02:00
|
|
|
validates :conference_id, presence: true, uniqueness: true
|
2014-11-20 14:57:03 +01:00
|
|
|
|
2014-06-14 18:33:39 +05:30
|
|
|
has_attached_file :photo,
|
|
|
|
|
styles: { thumb: '100x100>', large: '300x300>' }
|
|
|
|
|
validates_attachment_content_type :photo,
|
|
|
|
|
content_type: [/jpg/, /jpeg/, /png/, /gif/],
|
|
|
|
|
size: { in: 0..500.kilobytes }
|
2014-11-20 14:57:03 +01:00
|
|
|
|
2016-04-21 16:03:09 +02:00
|
|
|
before_save :send_mail_notification
|
2014-11-12 12:12:57 +01:00
|
|
|
|
2014-11-20 14:57:03 +01:00
|
|
|
def address
|
2014-12-05 16:04:34 +01:00
|
|
|
"#{street}, #{city}, #{country_name}"
|
2014-11-20 14:57:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def country_name
|
|
|
|
|
name = ISO3166::Country[country]
|
|
|
|
|
name.name if name
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-08 12:25:42 +01:00
|
|
|
def location?
|
|
|
|
|
!(latitude.blank? || longitude.blank?)
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-12 12:12:57 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def send_mail_notification
|
2016-04-21 16:03:09 +02:00
|
|
|
ConferenceVenueUpdateMailJob.perform_later(conference) if notify_on_venue_changed?
|
2014-11-12 12:12:57 +01:00
|
|
|
end
|
|
|
|
|
|
2016-03-31 16:51:16 +02:00
|
|
|
def notify_on_venue_changed?
|
|
|
|
|
return false unless conference.email_settings.send_on_venue_updated
|
|
|
|
|
# do not notify unless the address changed
|
|
|
|
|
return false unless self.name_changed? || self.street_changed? || self.city_changed? || self.country_changed?
|
|
|
|
|
# do not notify unless the mail content is set up
|
|
|
|
|
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
|
2014-08-12 16:04:24 +05:30
|
|
|
end
|
|
|
|
|
|
2014-07-21 14:27:32 +02:00
|
|
|
# TODO: create a module to be mixed into model to perform same operation
|
|
|
|
|
# event.rb has same functionality which can be shared
|
|
|
|
|
# TODO: rename guid to UUID as guid is specifically Microsoft term
|
2013-01-07 09:04:09 +01:00
|
|
|
def generate_guid
|
2014-07-21 14:27:32 +02:00
|
|
|
loop do
|
|
|
|
|
@guid = SecureRandom.urlsafe_base64
|
2014-07-21 14:49:05 +02:00
|
|
|
break if !Venue.where(guid: guid).any?
|
2014-07-21 14:27:32 +02:00
|
|
|
end
|
|
|
|
|
self.guid = @guid
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
end
|