Sha256: efadb138f159f7273236b919565cff567279186772fc2364dac8c8e0c8913af6

Contents?: true

Size: 1.83 KB

Versions: 9

Compression:

Stored size: 1.83 KB

Contents

class FestivityEventsController < ApplicationController
  include Festivity::Mixins::NotFound
  no_login_required
  trusty_layout 'base'

  #caches_action :show

  def index
    order_by = params[:sort] ? params[:sort] : "start_date"
    @title = "#{current_site.festivity_festival_name}: Events"
    @events =  Rails.cache.fetch("#{cache_key}", expires_in: 2.hours) do
      FestivityEventList.search(
          {dates: search_dates.join(","),
           categories: params[:categories]},
          order_by).events
    end


    @selected_dates = params[:dates] ? params[:dates].split(",") : []
    @selected_categories = params[:categories] ? params[:categories].split(",") : []
    @selected_sort = order_by
    # If the request is AJAX, only return the event list itself, not the full page
    if request.xhr?
      render partial: "event_list"
    else
      render 'index'
    end

  end

  def show
    @event = FestivityEventPage.find_by_slug_and_status_id(params[:id], Status[:published].id)
    if @event
      @page = @event
      @related_events = FestivityEventList.find_related_events(
          {dates: search_dates.join(","), event_id: @event.id,
           categories: @event.festivity_categories.map{|cat| cat.id}}).events
      @title = "#{current_site.festivity_festival_name}: #{@event.title}"
    else
      file_not_found_for_site
    end

  end

  private

  def cache_key
    "#{params[:categories.to_s]}-#{params[:dates].to_s}-#{request.xhr?}"
  end

  def search_dates
    if params[:dates]
      params[:dates].split(",")
    else
      collect_festival_dates
    end

  end

  def collect_festival_dates
    festival_dates = current_site.festival_dates
    if current_site.date_during_festival?(Date.today)
      festival_dates = festival_dates.select{ |date| date == Date.today }
    end

    festival_dates.map{ |date| date.to_s }

  end


end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.1.0 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.7 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.6 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.5 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.4 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.3 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.2 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.1 app/controllers/festivity_events_controller.rb
trusty-festivity-extension-2.0.0 app/controllers/festivity_events_controller.rb