2014-08-10 19:57:46 +03:00
|
|
|
class Conference < ActiveRecord::Base
|
|
|
|
validates :title, presence: true, uniqueness: true
|
|
|
|
validates :email, presence: true, format: {with: /\A[^@]+@[^@]+\z/}
|
|
|
|
validates :description, presence: true
|
|
|
|
validates :start_date, presence: true
|
|
|
|
validates :end_date, presence: true
|
|
|
|
validate :end_date_is_before_start_date
|
|
|
|
|
2014-09-01 13:44:41 +03:00
|
|
|
translates :title, :description
|
|
|
|
|
2014-10-14 23:55:17 +03:00
|
|
|
has_many :tracks, -> { order('id asc') }, dependent: :destroy
|
2014-08-10 21:17:06 +03:00
|
|
|
has_many :events, through: :tracks
|
2014-09-30 13:34:09 +03:00
|
|
|
has_many :candidate_speakers, through: :events
|
2014-10-14 23:55:17 +03:00
|
|
|
has_many :halls, dependent: :destroy
|
2014-08-10 20:30:37 +03:00
|
|
|
|
2014-10-14 23:55:17 +03:00
|
|
|
accepts_nested_attributes_for :tracks, :halls, reject_if: :all_blank, allow_destroy: true
|
2014-10-14 18:27:28 +03:00
|
|
|
|
2014-08-30 16:58:42 +03:00
|
|
|
scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') }
|
|
|
|
|
2014-10-14 21:58:13 +03:00
|
|
|
before_save :close_all_other_calls_for_papers
|
|
|
|
|
2014-08-30 16:58:42 +03:00
|
|
|
def self.current
|
|
|
|
future.first || last
|
|
|
|
end
|
2014-08-10 22:05:25 +03:00
|
|
|
|
2014-10-15 12:58:00 +03:00
|
|
|
def submissions_grouped_by_day
|
|
|
|
submissions = Event.where(track: tracks, created_at: created_at..start_date)
|
|
|
|
submissions = submissions.group('date(created_at)')
|
|
|
|
submissions = submissions.select('created_at, count(id) as number')
|
|
|
|
submissions.group_by { |s| s.created_at.to_date }
|
|
|
|
end
|
|
|
|
|
|
|
|
def submissions_grouped_by_confirmation_day
|
|
|
|
submissions = Event.approved.where(track: tracks, created_at: created_at..start_date).where.not(confirmed_at: nil)
|
|
|
|
submissions = submissions.group('date(confirmed_at)')
|
|
|
|
submissions = submissions.select('confirmed_at, count(id) as number')
|
|
|
|
submissions.group_by { |s| s.confirmed_at.to_date }
|
|
|
|
end
|
|
|
|
|
2014-08-10 19:57:46 +03:00
|
|
|
private
|
|
|
|
|
2014-10-14 21:58:13 +03:00
|
|
|
def close_all_other_calls_for_papers
|
|
|
|
if call_for_papers_open? and call_for_papers_open_changed?
|
|
|
|
Conference.where.not(id: self.id).update_all call_for_papers_open: false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-10 19:57:46 +03:00
|
|
|
def end_date_is_before_start_date
|
|
|
|
if start_date.present? and end_date.present? and start_date > end_date
|
|
|
|
errors.add(:end_date, :cannot_be_before_start_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|