2014-05-14 20:48:42 +00:00
|
|
|
module JamRuby
|
|
|
|
|
class RsvpSlot < ActiveRecord::Base
|
|
|
|
|
|
|
|
|
|
belongs_to :instrument, :class_name => "JamRuby::Instrument"
|
2014-07-08 18:34:03 +00:00
|
|
|
belongs_to :music_session, :class_name => "JamRuby::MusicSession"
|
2014-05-21 04:57:32 +00:00
|
|
|
has_many :rsvp_requests_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot", :foreign_key => "rsvp_slot_id"
|
2014-05-20 03:34:56 +00:00
|
|
|
has_many :rsvp_requests, :class_name => "JamRuby::RsvpRequest", :through => :rsvp_requests_rsvp_slots
|
2014-05-14 20:48:42 +00:00
|
|
|
|
2014-07-08 18:34:03 +00:00
|
|
|
validates :instrument, presence: true, if: :is_not_unstructured_rsvp?
|
|
|
|
|
validates :is_unstructured_rsvp, :inclusion => {:in => [true, false]}
|
|
|
|
|
validates :proficiency_level, presence: true, if: :is_not_unstructured_rsvp?
|
|
|
|
|
|
2014-06-19 04:21:34 +00:00
|
|
|
attr_accessor :chosen, :proficiency_desc
|
|
|
|
|
|
|
|
|
|
class << self
|
2014-06-23 04:58:37 +00:00
|
|
|
@@proficiency_map = ["Any Skill Level", "Beg", "Beg/Int", "Int", "Int/Adv", "Adv"]
|
2014-06-19 04:21:34 +00:00
|
|
|
end
|
2014-05-21 05:36:32 +00:00
|
|
|
|
2014-07-08 18:34:03 +00:00
|
|
|
def is_not_unstructured_rsvp?
|
|
|
|
|
!is_unstructured_rsvp?
|
|
|
|
|
end
|
2014-05-14 20:48:42 +00:00
|
|
|
# TODO: validates :proficiency_level
|
2014-05-20 06:45:00 +00:00
|
|
|
|
2014-05-21 05:36:32 +00:00
|
|
|
def self.index(music_session)
|
|
|
|
|
RsvpSlot.where("music_session_id = ?", music_session.id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def chosen
|
|
|
|
|
chosen_slots = RsvpRequestRsvpSlot.where("chosen = true AND rsvp_slot_id = ?", self.id)
|
|
|
|
|
!chosen_slots.blank?
|
2014-05-20 06:45:00 +00:00
|
|
|
end
|
2014-05-22 03:36:34 +00:00
|
|
|
|
2014-06-19 04:21:34 +00:00
|
|
|
def proficiency_desc
|
2014-06-23 04:58:37 +00:00
|
|
|
@@proficiency_map[self.proficiency_level]
|
2014-06-19 04:21:34 +00:00
|
|
|
end
|
|
|
|
|
|
2014-05-22 03:36:34 +00:00
|
|
|
# def has_rsvp_from_user(user)
|
|
|
|
|
# user_slot = RsvpRequest.joins(:rsvp_requests_rsvp_slots)
|
|
|
|
|
# .where(:rsvp_request_id => )
|
|
|
|
|
# .where(:user_id => user.id)
|
|
|
|
|
# end
|
2014-05-14 20:48:42 +00:00
|
|
|
end
|
|
|
|
|
end
|