module UpcomingEvents::DisciplineExtensions

Attributes

upcoming_events[RW]
upcoming_weekly_series[RW]

Public Instance Methods

find_all_upcoming_events(dates) click to toggle source
# File app/models/upcoming_events/discipline_extensions.rb, line 6
def find_all_upcoming_events(dates)
  single_day_events = SingleDayEvent.all(
    :conditions => scope_by_sanctioned(['date between ? and ? and cancelled = false and parent_id is null and discipline in (?)', dates.begin, dates.end, self.names]),
    :order => 'date')

  # Find MultiDayEvents, not their children, nor MultiDayEvents subclasses
  multi_day_events = MultiDayEvent.all(
    :select => "distinct events.id, events.name, events.date, events.discipline, events.flyer, events.flyer_approved, events.beginner_friendly, events.bar_points, events.website, events.registration_link",
    :joins => "left outer join events as childrens_events on childrens_events.parent_id = events.id",
    :conditions => scope_by_sanctioned([%Q{ childrens_events.date between ? and ? and 
                                            (childrens_events.type is null or childrens_events.type = 'SingleDayEvent') and
                                            events.cancelled = false and 
                                            events.practice = false and
                                            events.instructional = false and 
                                            events.discipline in (?) and 
                                            events.type = ? }, 
                                        dates.begin, dates.end, self.names, "MultiDayEvent"]),
    :order => 'events.date')

  # Find Series events, but not their parents, nor WeeklySeries
  series_events = SingleDayEvent.all(
      :select => "distinct events.id, events.name, events.date, events.discipline, events.flyer, events.flyer_approved, events.beginner_friendly, events.bar_points, events.website, events.registration_link",
      :include => :parent,
      :conditions => scope_by_sanctioned(
                       [%Q{ events.date between ? and ? 
                            and events.cancelled = false 
                            and events.instructional = false 
                            and events.practice = false 
                            and events.parent_id is not null 
                            and parents_events.type = ?
                            and parents_events.discipline in (?) }, 
                        dates.begin, dates.end, "Series", self.names]),
      :order => 'events.date') 
  
  single_day_events + multi_day_events + series_events
end
find_all_upcoming_weekly_series(dates) click to toggle source
# File app/models/upcoming_events/discipline_extensions.rb, line 43
def find_all_upcoming_weekly_series(dates)
  WeeklySeries.all(
    :select => "distinct events.id, events.name, events.date, events.discipline, events.flyer, events.flyer_approved, events.beginner_friendly, events.bar_points, events.website, events.registration_link",
    :joins => "left outer join events as childrens_events on childrens_events.parent_id = events.id",
    :conditions => scope_by_sanctioned([%Q{ childrens_events.date between ? and ? and 
                                            (childrens_events.type is null or childrens_events.type = 'SingleDayEvent') and
                                            events.cancelled = false and 
                                            events.practice = false and
                                            events.instructional = false and 
                                            events.discipline in (?)}, 
                                        dates.begin, dates.end, self.names]),
    :order => 'events.date')
end