BikeBikeBike/app/models/conference.rb

72 lines
1.8 KiB
Ruby
Raw Normal View History

2014-03-09 14:43:33 -06:00
class Conference < ActiveRecord::Base
2016-08-14 00:38:10 -07:00
translates :info, :title, :payment_message
2015-03-17 20:29:17 -07:00
2014-03-09 14:43:33 -06:00
mount_uploader :cover, CoverUploader
mount_uploader :poster, PosterUploader
belongs_to :conference_type
has_many :conference_host_organizations, :dependent => :destroy
has_many :organizations, :through => :conference_host_organizations
has_many :event_locations
2014-03-09 14:43:33 -06:00
2014-07-24 00:16:33 -06:00
#has_many :conference_registration_form_fields, :order => 'position ASC', :dependent => :destroy#, :class_name => '::ConferenceRegistrationFormField'
#has_many :registration_form_fields, :through => :conference_registration_form_fields
2014-03-09 14:43:33 -06:00
2014-03-23 13:31:08 -06:00
has_many :workshops
2014-03-09 14:43:33 -06:00
accepts_nested_attributes_for :conference_host_organizations, :reject_if => proc {|u| u[:organization_id].blank?}, :allow_destroy => true
def to_param
slug
end
2015-08-18 22:18:29 -07:00
def host?(user)
return false unless user.present?
2015-08-18 22:18:29 -07:00
organizations.each do |o|
return true if o.host?(user)
end
return false
end
2014-07-05 10:27:49 -06:00
def url(action = :show)
path(action)
end
def path(action = :show)
action = action.to_sym
'/conferences/' + conference_type.slug + '/' + slug + (action == :show ? '' : '/' + action.to_s)
end
2015-09-19 16:30:39 -07:00
def location
organizations.first.location
end
2014-03-09 14:43:33 -06:00
2015-09-19 16:30:39 -07:00
def registered?(user)
registration = ConferenceRegistration.find_by(:user_id => user.id, :conference_id => id)
2016-05-30 18:24:07 -07:00
return registration ? registration.is_attending : false
end
def registration_exists?(user)
ConferenceRegistration.find_by(:user_id => user.id, :conference_id => id).present?
end
def registration_open
registration_status == :open
end
def registration_status
s = read_attribute(:registration_status)
s.present? ? s.to_sym : nil
2016-05-30 18:24:07 -07:00
end
def registration_status=(new_registration_status)
write_attribute :registration_status, new_registration_status.to_s
2015-09-19 16:30:39 -07:00
end
2016-08-14 00:38:10 -07:00
def self.default_payment_amounts
[25, 50, 100]
end
2014-03-09 14:43:33 -06:00
end