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



32
33
34
35
36
37
38
# File 'app/models/caboose/calendar_event.rb', line 32

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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/caboose/calendar_event.rb', line 40

def duplicate(d)
  btime = self.begin_date.to_s[10..-1]
  etime = self.end_date.to_s[10..-1]
  bdate = DateTime.parse(d.to_s + btime)
  edate = DateTime.parse(d.to_s + btime) + (self.end_date - self.begin_date).seconds
  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              => bdate,
    :end_date                => edate,
    :all_day                 => self.all_day,
    :repeats                 => self.repeats,
    :published               => self.published,
    :url                     => self.url
  )
  return e
end