2014-08-10 21:17:06 +03:00
|
|
|
class Event < ActiveRecord::Base
|
|
|
|
validates :title, presence: true
|
|
|
|
validates :length, presence: true, numericality: {only_integer: true, greater_than: 0}
|
|
|
|
validates :abstract, presence: true
|
|
|
|
validates :description, presence: true
|
2014-09-07 00:02:00 +03:00
|
|
|
validates :track_id, inclusion: { in: (Conference.current.try(:tracks) || []).map(&:id) }
|
2014-09-04 00:39:54 +03:00
|
|
|
validates :agreement, acceptance: true
|
2014-08-10 21:17:06 +03:00
|
|
|
|
|
|
|
belongs_to :track
|
|
|
|
has_one :conference, through: :track
|
2014-09-30 13:34:09 +03:00
|
|
|
belongs_to :user # XXX: Transition to candidate_speaker
|
|
|
|
belongs_to :candidate_speaker, class_name: 'User', foreign_key: 'user_id'
|
2014-10-13 16:50:16 +03:00
|
|
|
has_and_belongs_to_many :speakers, class_name: 'SpeakerProfile'
|
2014-09-02 18:11:35 +03:00
|
|
|
|
|
|
|
after_create :send_new_event_notification
|
|
|
|
|
2014-10-10 20:25:41 +03:00
|
|
|
enum state: [:undecided, :approved, :rejected, :backup]
|
2014-10-10 19:10:34 +03:00
|
|
|
|
|
|
|
# XXX: this belongs in a decorator
|
2014-10-11 19:08:35 +03:00
|
|
|
STATE_TO_GLYPH = {undecided: 'question-sign', rejected: 'remove', approved: 'ok', backup: 'retweet'}
|
2014-10-10 20:25:41 +03:00
|
|
|
STATE_TO_CLASS = {undecided: 'warning', rejected: 'danger', approved: 'success', backup: 'info'}
|
2014-10-10 19:10:34 +03:00
|
|
|
|
2014-10-12 14:54:06 +03:00
|
|
|
def send_acceptance_notification!
|
|
|
|
EventMailer.acceptance_notification(self).deliver
|
|
|
|
touch :acceptance_notification_sent_at
|
|
|
|
end
|
|
|
|
|
2014-10-17 21:05:26 +03:00
|
|
|
def send_rejection_notification!
|
|
|
|
EventMailer.rejection_notification(self).deliver
|
|
|
|
end
|
|
|
|
|
2014-10-12 15:38:15 +03:00
|
|
|
def confirmed?
|
|
|
|
!!confirmed_at
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:11:35 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def send_new_event_notification
|
|
|
|
EventMailer.new_event_notification(self).deliver
|
|
|
|
end
|
2014-08-10 21:17:06 +03:00
|
|
|
end
|