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


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

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

#custom_field_value(key) ⇒ Object


62
63
64
65
66
67
68
69
70
# File 'app/models/caboose/calendar_event.rb', line 62

def custom_field_value(key)
  fv = Caboose::EventCustomFieldValue.where(:calendar_event_id => self.id, :key => key).first
  if fv.nil?
    f = Caboose::EventCustomField.where(:site_id => self.calendar.site_id, :key => key).first
    return nil if f.nil?
    fv = Caboose::EventCustomFieldValue.create(:calendar_event_id => self.id, :event_custom_field_id => f.id, :key => key, :value => f.default_value, :sort_order => f.sort_order)
  end
  return fv.value
end

#duplicate(d) ⇒ Object


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

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

#verify_custom_field_values_existObject


72
73
74
75
76
77
# File 'app/models/caboose/calendar_event.rb', line 72

def verify_custom_field_values_exist
  Caboose::EventCustomField.where(:site_id => self.calendar.site_id).all.each do |f|
    fv = Caboose::EventCustomFieldValue.where(:calendar_event_id => self.id, :event_custom_field_id => f.id).first                  
    Caboose::EventCustomFieldValue.create(:calendar_event_id => self.id, :event_custom_field_id => f.id, :key => f.key, :value => f.default_value, :sort_order => f.sort_order) if fv.nil?
  end
end