Class: FestivityEventList

Inherits:
Object
  • Object
show all
Includes:
Concerns::FestivitySqlBuilder
Defined in:
app/models/festivity_event_list.rb

Defined Under Namespace

Classes: FestivityEvent, FestivityEventPerformance, FestivityLocation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_performances) ⇒ FestivityEventList

Returns a new instance of FestivityEventList.



7
8
9
10
11
# File 'app/models/festivity_event_list.rb', line 7

def initialize(event_performances)
  @events = event_performances.group_by {|perf| perf.event_id }.
      map { |perfs| FestivityEventList::FestivityEvent.new(perfs[0], perfs[1]) }

end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'app/models/festivity_event_list.rb', line 5

def events
  @events
end

Class Method Details

.collect_festival_dates(site) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'app/models/festivity_event_list.rb', line 80

def self.collect_festival_dates(site)
  festival_dates = site.festival_datetimes
  if site.date_during_festival?(Time.now)
    festival_dates = festival_dates.select{ |date| date.datetime == Time.now }
  end

  festival_dates.map{ |date| date.to_s }

end

.find_by_location(location_id, site) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/festivity_event_list.rb', line 47

def self.find_by_location(location_id, site)
  begin
    where_clause = parse_criteria(dates: collect_festival_dates(site).join(","), filter_type: site.festivity_filter_type)
  rescue ActiveRecord::RecordNotFound
    return FestivityEventList.new([])
  end

  FestivityEventList.new(
      FestivityEventList::FestivityEventPerformance.
          includes(:assets).
          joins(:festivity_categories).
          where(where_clause).
          where(location_id: location_id).
          group("performance_id").
          order("featured_item DESC, start_date ASC").
          preload(:festivity_categories)
  )
end


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/models/festivity_event_list.rb', line 66

def self.find_related_events(criteria)
  where_clause = parse_criteria(criteria)
  FestivityEventList.new(
      FestivityEventList::FestivityEventPerformance.
          includes(:assets).
          joins(:festivity_categories).
          where(where_clause).
          where("event_id != ?", criteria[:event_id]).
          group("performance_id").
          order("featured_item DESC, start_date ASC").
          preload(:festivity_categories)
  )
end

.hourlyObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/festivity_event_list.rb', line 32

def self.hourly
  current_site = Page.current_site
  festival_date_times = FestivityEventList.collect_festival_dates(current_site)
  festival_dates = festival_date_times.map! {|date| date.to_date}
  now = DateTime.now.in_time_zone("Eastern Time (US & Canada)")

  if festival_dates.include?(now.to_date)
    FestivityPerformance.where(start_date: now...now + 1.day).includes(:festivity_event_page).where(pages: {status_id: 100, site_id: Page.current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.first(3)
  elsif festival_dates.first > now.to_date
    FestivityPerformance.includes(:festivity_event_page).where(pages: {status_id: 100, site_id: current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.first(3)
  else
    FestivityPerformance.includes(:festivity_event_page).where(pages: {status_id: 100, site_id: current_site.id, layout_id: nil}).compact.sort_by{|e| e[:date]}.last(3)
  end
end

.search(criteria, order_by) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/festivity_event_list.rb', line 13

def self.search(criteria, order_by)
  begin
  where_clause = parse_criteria(criteria)
  rescue ActiveRecord::RecordNotFound
    return FestivityEventList.new([])
  end

  # where in event ids
  FestivityEventList.new(
      FestivityEventList::FestivityEventPerformance.
          includes(:assets).
          joins(:festivity_categories).
          where(where_clause).
          group("performance_id").
          order("featured_item DESC, #{order_by} ASC").
          preload(:festivity_categories)
  )
end