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
|
2014-11-04 21:16:06 +02:00
|
|
|
validate :start_date_is_before_end_date
|
2014-08-10 19:57:46 +03:00
|
|
|
|
2014-09-01 13:44:41 +03:00
|
|
|
translates :title, :description
|
|
|
|
|
2014-11-04 23:02:28 +02:00
|
|
|
has_many :tracks
|
|
|
|
has_many :halls
|
2015-04-17 22:12:13 +03:00
|
|
|
has_many :events, through: :tracks
|
2015-04-20 18:55:06 +03:00
|
|
|
has_one :call_for_participation, dependent: :destroy
|
2015-05-30 18:53:14 +03:00
|
|
|
has_many :participant_profiles, class_name: 'PersonalProfile'
|
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
|
|
|
|
2015-05-23 18:47:08 +03:00
|
|
|
after_create :create_call_for_participation
|
|
|
|
|
2015-04-20 19:11:39 +03:00
|
|
|
def submissions_grouped_by_day
|
|
|
|
submissions = events.group('date(events.created_at)').select('events.created_at, count(events.id) as number')
|
|
|
|
submissions.group_by { |s| s.created_at.to_date }
|
|
|
|
end
|
|
|
|
|
|
|
|
def submissions_grouped_by_confirmation_day
|
|
|
|
submissions = events.approved.confirmed.group('date(events.confirmed_at)').select('events.confirmed_at, count(events.id) as number')
|
|
|
|
submissions.group_by { |s| s.confirmed_at.to_date }
|
|
|
|
end
|
|
|
|
|
2015-06-09 21:50:23 +03:00
|
|
|
def slug
|
|
|
|
title.gsub(' ', '-')
|
|
|
|
end
|
|
|
|
|
|
|
|
# TODO (2015-06-09) Stupid and temporary, put slug in db
|
|
|
|
# TODO (2015-06-09) Also, doesn't work due to translations?
|
|
|
|
# def self.find_by_slug(slug)
|
|
|
|
# find_by(title: slug.to_s.gsub('-', ' '))
|
|
|
|
# end
|
|
|
|
|
2014-08-10 19:57:46 +03:00
|
|
|
private
|
|
|
|
|
2014-11-04 21:16:06 +02:00
|
|
|
def start_date_is_before_end_date
|
2014-08-10 19:57:46 +03:00
|
|
|
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
|