Sha256: 08c507aafe69dc7f1eea41d96365faa5577554a3aecb916fc3f7ca03503cdbf4
Contents?: true
Size: 1.4 KB
Versions: 41
Compression:
Stored size: 1.4 KB
Contents
class Event < ActiveRecord::Base include SocialStream::Models::Object scheduler belongs_to :room validates_presence_of :title validate :room_belongs_to_receiver def to_json(options = {}) if recurrence st = options[:start].try(:to_date) en = (options[:end] || end_at.end_of_month + 7.days).to_date recurrence.events(:starts => st, :until => en).map do |d| start_diff = d - start_at.to_date end_diff = d - end_at.to_date build_json start_at.advance(:days => start_diff), end_at.advance(:days => end_diff) end else build_json end end def poster_object object_properties. where('activity_object_properties.type' => 'ActivityObjectProperty::Poster'). first end def poster @poster ||= poster_object.try(:document) || build_poster end protected def build_json(start_time = start_at, end_time = end_at) { :id => id, :title => title, :start => start_time, :end => end_time, :allDay => all_day?, :roomId => room_id } end def build_poster Document.new(:event_property_object_id => activity_object_id, :owner_id => owner_id) end private def room_belongs_to_receiver return if room_id.blank? unless owner.room_ids.include?(room_id) errors.add(:room_id, :invalid) end end end
Version data entries
41 entries across 41 versions & 2 rubygems