refatored conferences_controller
This commit is contained in:
parent
616615a749
commit
50bce629d8
3 changed files with 200 additions and 73 deletions
57
app/services/conferences_calendar_service.rb
Normal file
57
app/services/conferences_calendar_service.rb
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
class ConferencesCalendarService
|
||||
def initialize(calendar, conference)
|
||||
@calendar = calendar
|
||||
@conference = conference
|
||||
end
|
||||
|
||||
def not_full_calendar
|
||||
calendar.event do |e|
|
||||
default_calendar_params(e)
|
||||
if @conference.venue
|
||||
venue_calendar_params(e)
|
||||
end
|
||||
end
|
||||
calendar
|
||||
end
|
||||
|
||||
def full_calendar
|
||||
icalendar_proposals(@calendar, event_schedules.map(&:event), @conference)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_calendar_params(event)
|
||||
event.dtstart = @conference.start_date
|
||||
event.dtstart.ical_params = { 'VALUE'=>'DATE' }
|
||||
event.dtend = @conference.end_date
|
||||
event.dtend.ical_params = { 'VALUE'=>'DATE' }
|
||||
event.duration = "P#{(@conference.end_date - @conference.start_date + 1).floor}D"
|
||||
event.created = @conference.created_at
|
||||
event.last_modified = @conference.updated_at
|
||||
event.summary = @conference.title
|
||||
event.description = @conference.description
|
||||
event.uid = @conference.guid
|
||||
event.url = conference_url(@conference.short_title)
|
||||
end
|
||||
|
||||
def venue_calendar_params(event)
|
||||
venue = @conference.venue
|
||||
event.geo = venue.latitude, venue.longitude if venue.latitude && venue.longitude
|
||||
location = location(venue)
|
||||
event.location = location if location
|
||||
end
|
||||
|
||||
def location(venue)
|
||||
location = ''
|
||||
location += "#{venue.street}, " if venue.street
|
||||
location += "#{venue.postalcode} #{venue.city}, " if venue.postalcode && venue.city
|
||||
location += venue.country_name if venue.country_name
|
||||
location
|
||||
end
|
||||
|
||||
def event_schedules
|
||||
@conference.program.selected_event_schedules(
|
||||
includes: [{ event: %i[event_type speakers submitter] }]
|
||||
)
|
||||
end
|
||||
end
|
||||
89
app/services/conferences_service.rb
Normal file
89
app/services/conferences_service.rb
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
class ConferencesService
|
||||
def initialize(conference = nil)
|
||||
@conference = conference
|
||||
@cfps = @conference&.program&.cfps
|
||||
@splashpage = @conference&.splashpage
|
||||
end
|
||||
|
||||
def self.conference_by_filter(conference_finder_conditions)
|
||||
Conference.unscoped.eager_load(
|
||||
:splashpage,
|
||||
:program,
|
||||
:registration_period,
|
||||
:contact,
|
||||
venue: :commercial
|
||||
).find_by!(conference_finder_conditions)
|
||||
end
|
||||
|
||||
def conference_image_url(request)
|
||||
"#{request.protocol}#{request.host}#{@conference.picture}"
|
||||
end
|
||||
|
||||
def cfp_variables_if_event_open(call_for_events)
|
||||
if call_for_events.try(:open?)
|
||||
[event_types, track_names]
|
||||
end
|
||||
end
|
||||
|
||||
def cfp_call_by_type(type)
|
||||
@cfps.find { |call| call.cfp_type == type }
|
||||
end
|
||||
|
||||
def if_include_tracks
|
||||
if @splashpage.include_tracks
|
||||
tracks
|
||||
end
|
||||
end
|
||||
|
||||
def if_include_booths
|
||||
if @splashpage.include_booths
|
||||
booths
|
||||
end
|
||||
end
|
||||
|
||||
def if_include_registrations_or_tickets
|
||||
if @splashpage.include_registrations || @splashpage.include_tickets
|
||||
tickets
|
||||
end
|
||||
end
|
||||
|
||||
def if_include_lodgings
|
||||
if @splashpage.include_lodgings
|
||||
lodgings
|
||||
end
|
||||
end
|
||||
|
||||
def sponsorship_levels
|
||||
@conference.sponsorship_levels.eager_load(
|
||||
:sponsors
|
||||
).order('sponsorship_levels.position ASC', 'sponsors.name')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lodgings
|
||||
@conference.lodgings.order('name')
|
||||
end
|
||||
|
||||
def track_names
|
||||
@conference.confirmed_tracks.pluck(:name).sort
|
||||
end
|
||||
|
||||
def event_types
|
||||
@conference.event_types.pluck(:title)
|
||||
end
|
||||
|
||||
def tracks
|
||||
@conference.confirmed_tracks.eager_load(
|
||||
:room
|
||||
).order('tracks.name')
|
||||
end
|
||||
|
||||
def booths
|
||||
@conference.confirmed_booths.order('title')
|
||||
end
|
||||
|
||||
def tickets
|
||||
@conference.tickets.order('price_cents')
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue