2013-01-07 09:04:09 +01:00
|
|
|
class Registration < ActiveRecord::Base
|
2014-06-23 19:07:50 +03:00
|
|
|
belongs_to :user
|
2013-01-07 09:04:09 +01:00
|
|
|
belongs_to :conference
|
2013-02-02 16:43:47 +01:00
|
|
|
belongs_to :dietary_choice
|
|
|
|
|
|
2013-02-16 13:30:53 +01:00
|
|
|
has_and_belongs_to_many :social_events
|
2013-07-11 07:47:05 +03:00
|
|
|
has_and_belongs_to_many :events
|
2014-02-09 18:05:57 +02:00
|
|
|
has_and_belongs_to_many :qanswers
|
2014-01-01 11:39:59 +02:00
|
|
|
has_and_belongs_to_many :vchoices
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
has_many :events_registrations
|
|
|
|
|
has_many :workshops, through: :events_registrations, source: :event
|
|
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
attr_accessible :user_id, :conference_id, :attending_social_events, :attending_with_partner,
|
2014-06-24 12:14:53 +03:00
|
|
|
:using_affiliated_lodging, :arrival, :departure, :user_attributes, :attended,
|
|
|
|
|
:other_dietary_choice, :dietary_choice_id, :handicapped_access_required,
|
2014-08-28 15:21:05 +02:00
|
|
|
:social_event_ids, :other_special_needs,
|
2014-06-24 12:14:53 +03:00
|
|
|
:event_ids, :volunteer, :vchoice_ids, :qanswer_ids, :qanswers_attributes
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-06-23 19:07:50 +03:00
|
|
|
accepts_nested_attributes_for :user
|
2013-02-16 13:30:53 +01:00
|
|
|
accepts_nested_attributes_for :social_events
|
2014-02-09 18:05:57 +02:00
|
|
|
accepts_nested_attributes_for :qanswers
|
2013-07-16 09:47:23 +02:00
|
|
|
|
2014-06-24 12:14:53 +03:00
|
|
|
delegate :name, to: :user
|
|
|
|
|
delegate :email, to: :user
|
|
|
|
|
delegate :nickname, to: :user
|
|
|
|
|
delegate :affiliation, to: :user
|
|
|
|
|
|
2013-07-12 10:45:40 +03:00
|
|
|
alias_attribute :other_needs, :other_special_needs
|
2014-06-02 12:37:57 +02:00
|
|
|
|
2014-08-22 15:08:54 +02:00
|
|
|
validates_uniqueness_of :user_id, scope: :conference_id, message: 'already Registered!'
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
after_create :set_week, :subscribe_to_conference, :send_registration_mail
|
2014-06-25 14:58:33 +02:00
|
|
|
|
2014-06-02 12:37:57 +02:00
|
|
|
def week
|
|
|
|
|
created_at.strftime('%W').to_i
|
|
|
|
|
end
|
2014-06-25 14:58:33 +02:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2014-08-28 15:21:05 +02:00
|
|
|
def subscribe_to_conference
|
|
|
|
|
Subscription.create(conference_id: conference.id, user_id: user.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def send_registration_mail
|
|
|
|
|
if conference.email_settings.send_on_registration?
|
|
|
|
|
Mailbot.delay.registration_mail(conference, user)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-06-25 14:58:33 +02:00
|
|
|
def set_week
|
|
|
|
|
self.week = created_at.strftime('%W')
|
|
|
|
|
save!
|
|
|
|
|
end
|
2013-07-15 16:07:23 +02:00
|
|
|
end
|