Public schedule adapted to the new relations

Public schedule and all events adapted to the new relations and models to allow having several schedules in the admin shcedule.
This commit is contained in:
Ana 2016-07-20 23:20:47 +02:00
parent dfd64a4510
commit 354e15a76d
12 changed files with 71 additions and 61 deletions

View file

@ -3,7 +3,25 @@ class EventSchedule < ActiveRecord::Base
belongs_to :event
belongs_to :room
scope :confirmed, -> { joins(:event).where('state = ?', 'confirmed') }
scope :canceled, -> { joins(:event).where('state = ?', 'canceled') }
scope :withdrawn, -> { joins(:event).where('state = ?', 'withdrawn') }
def room_guid
room.try(:guid)
end
##
# Returns end of the event
#
def end_time
start_time + event.event_type.length.minutes
end
##
# Returns events that are scheduled in the same room and start_time as event
#
def intersecting_events
room.event_schedules.where(start_time: start_time, schedule: schedule).where.not(id: id)
end
end