Class: Calendar

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/calendar.rb

Instance Method Summary collapse

Instance Method Details

#entries_between(start_date, end_date, filter, position = nil, distance = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/calendar.rb', line 8

def entries_between(start_date, end_date, filter, position = nil, distance = nil) 
  e = self.calendar_entries.where(["(start_date <= ? and end_date >= ?)", end_date, start_date]).includes({:location=>:subregion})

  if filter =~ /subregions.name/
    e = e.joins({:location=>:subregion})
  elsif filter =~ /location/
   e = e.joins(:location) 
  end

  if filter =~ /calendar_entry_types/ || filter =~ /calendar_entry_type_id/
    e = e.joins(:calendar_entry_type)
  end

  if position 
    e = e.near(position, distance || 25)
  end

  e = e.where(filter) if filter.not_blank? 
  e = e.all
end