Class: Caboose::CalendarEvent

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.events_for_day(calendar_id, d) ⇒ Object



18
19
20
21
22
23
24
# File 'app/models/caboose/calendar_event.rb', line 18

def self.events_for_day(calendar_id, d)
  q = ["calendar_id = ? 
    and cast(begin_date as date) <= ?
    and cast(end_date   as date) >= ?",
    calendar_id, d.to_date, d.to_date]
  self.where(q).reorder(:begin_date).all
end

Instance Method Details

#duplicate(d) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/caboose/calendar_event.rb', line 26

def duplicate(d)
  e = CalendarEvent.create(        
    :calendar_id             => self.calendar_id,
    :calendar_event_group_id => self.calendar_event_group_id,
    :name                    => self.name,
    :description             => self.description,
    :location                => self.location,
    :begin_date              => d,
    :end_date                => d + (self.end_date - self.begin_date).seconds,
    :all_day                 => self.all_day,
    :repeats                 => self.repeats
  )
  return e
end