implement manual event management and support for multiple speakers per event
This commit is contained in:
parent
46a6a59622
commit
790e2fd3a2
24 changed files with 180 additions and 89 deletions
|
|
@ -8,7 +8,13 @@ class Event < ActiveRecord::Base
|
|||
|
||||
has_many :event_users, dependent: :destroy
|
||||
has_many :users, through: :event_users
|
||||
has_many :speakers, through: :event_users, source: :user
|
||||
|
||||
has_many :speaker_event_users, -> { where(event_role: 'speaker') }, class_name: 'EventUser'
|
||||
has_many :speakers, through: :speaker_event_users, source: :user
|
||||
|
||||
has_one :submitter_event_user, -> { where(event_role: 'submitter') }, class_name: 'EventUser'
|
||||
has_one :submitter, through: :submitter_event_user, source: :user
|
||||
|
||||
has_many :votes, dependent: :destroy
|
||||
has_many :voters, through: :votes, source: :user
|
||||
has_many :commercials, as: :commercialable, dependent: :destroy
|
||||
|
|
@ -23,6 +29,7 @@ class Event < ActiveRecord::Base
|
|||
belongs_to :program
|
||||
|
||||
accepts_nested_attributes_for :event_users, allow_destroy: true
|
||||
accepts_nested_attributes_for :speakers, allow_destroy: true
|
||||
accepts_nested_attributes_for :users
|
||||
|
||||
before_create :generate_guid
|
||||
|
|
@ -33,6 +40,7 @@ class Event < ActiveRecord::Base
|
|||
validates :abstract, presence: true
|
||||
validates :event_type, presence: true
|
||||
validates :program, presence: true
|
||||
validates :speakers, presence: true
|
||||
validates :max_attendees, numericality: { only_integer: true, greater_than_or_equal_to: 1, allow_nil: true }
|
||||
|
||||
validate :max_attendees_no_more_than_room_size
|
||||
|
|
@ -113,20 +121,16 @@ class Event < ActiveRecord::Base
|
|||
@total_rating > 0 ? number_with_precision(@total_rating / @total.to_f, precision: 2, strip_insignificant_zeros: true) : 0
|
||||
end
|
||||
|
||||
def submitter
|
||||
result = event_users.where(event_role: 'submitter').first
|
||||
if result.nil?
|
||||
user = nil
|
||||
# Perhaps the event_users haven't been saved, if this is a new proposal
|
||||
event_users.each do |u|
|
||||
if u.event_role == 'submitter'
|
||||
user = u.user
|
||||
end
|
||||
end
|
||||
user
|
||||
else
|
||||
result.user
|
||||
# get event speakers with the event sumbmitter at the first position
|
||||
# if the submitter is also a speaker for this event
|
||||
def speakers_ordered
|
||||
speakers_list = speakers.to_a
|
||||
|
||||
if speakers_list.reject! { |speaker| speaker == submitter }
|
||||
speakers_list.unshift(submitter)
|
||||
end
|
||||
|
||||
speakers_list
|
||||
end
|
||||
|
||||
def transition_possible?(transition)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class User < ActiveRecord::Base
|
|||
|
||||
has_many :event_users, dependent: :destroy
|
||||
has_many :events, -> { uniq }, through: :event_users
|
||||
has_many :presented_events, -> { joins(:event_users).where(event_users: {event_role: 'speaker'}).uniq }, through: :event_users, source: :event
|
||||
has_many :registrations, dependent: :destroy
|
||||
has_many :events_registrations, through: :registrations
|
||||
has_many :ticket_purchases, dependent: :destroy
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue