class Event
Constants
- LOCATION_TYPES
Public Instance Methods
add_to_index()
click to toggle source
Just index all the embedded event_occurrences
# File lib/buweb/event.rb, line 188 def add_to_index event_occurrences.each(&:add_to_index) end
clone()
click to toggle source
Calls superclass method
# File lib/buweb/event.rb, line 171 def clone new_event = super new_event.set_slug new_event.address = self.address.clone new_event.campus_location = self.campus_location.clone if self.campus_location new_event.write_attributes( ws_id: nil, aasm_state: nil, publish_at: nil, archive_at: nil, start_date: nil, end_date: nil, ) return new_event end
day_span()
click to toggle source
# File lib/buweb/event.rb, line 155 def day_span unending_event? ? 1 : (end_date.to_date - start_date.to_date + 1).to_i end
get_first_occurrence()
click to toggle source
# File lib/buweb/event.rb, line 207 def get_first_occurrence event_occurrences.asc(:start_time).first end
get_last_occurrence()
click to toggle source
# File lib/buweb/event.rb, line 211 def get_last_occurrence # I'm going to assume no wierd overlapping dates, where it starts # before another occurrence but ends after, mainly since end_date # is not guaranteed to exist. event_occurrences.asc(:start_time).last end
get_next_occurrence()
click to toggle source
# File lib/buweb/event.rb, line 197 def get_next_occurrence # Return the next upcomming occurrences event_occurrences.asc(:start_time).each do |o| return o if o.start_time > Time.now || (o.end_time && o.end_time > Time.now) end # Otherwise return the last one return event_occurrences.asc(:start_time).last end
location()
click to toggle source
# File lib/buweb/event.rb, line 133 def location if location_type == 'on-campus' custom_campus_location.presence || campus_location elsif location_type == 'off-campus' address end end
location_pending?()
click to toggle source
# File lib/buweb/event.rb, line 129 def location_pending? location_type == 'pending' end
multiple_day_event?()
click to toggle source
# File lib/buweb/event.rb, line 163 def multiple_day_event? day_span > 1 end
next_occurrence()
click to toggle source
Will always return an event occurrence. It will try to show the next upcomming one otherwise it will show the last occurrence if there are no more future dates.
# File lib/buweb/event.rb, line 194 def next_occurrence @next_occurrence ||= get_next_occurrence end
projected_ending()
click to toggle source
# File lib/buweb/event.rb, line 167 def projected_ending unending_event? ? start_date.end_of_day : end_date end
set_slug()
click to toggle source
sets slug from title
# File lib/buweb/event.rb, line 142 def set_slug return unless title? appendage = nil while ::Event.where(slug: "#{title.parameterize}#{appendage}").present? appendage.nil? ? appendage = 1 : appendage += 1 end self.slug = "#{title.parameterize}#{appendage}" end
single_day_event?()
click to toggle source
# File lib/buweb/event.rb, line 159 def single_day_event? day_span == 1 end
to_s()
click to toggle source
# File lib/buweb/event.rb, line 125 def to_s title.to_s end
unending_event?()
click to toggle source
# File lib/buweb/event.rb, line 151 def unending_event? end_date.blank? end
Private Instance Methods
at_least_one_occurrence()
click to toggle source
# File lib/buweb/event.rb, line 232 def at_least_one_occurrence if event_occurrences.length == 0 errors.add :base, "Valid time is required." end end
cache_dates()
click to toggle source
We will cache start and end dates for performance reasons
# File lib/buweb/event.rb, line 250 def cache_dates first_occurrence = get_first_occurrence last_occurrence = get_last_occurrence return if first_occurrence.nil? || last_occurrence.nil? self.start_date = first_occurrence.start_time self.end_date = last_occurrence.end_time || last_occurrence.start_time end
non_imported_site_presence()
click to toggle source
# File lib/buweb/event.rb, line 220 def non_imported_site_presence if !imported && site_id.blank? errors.add :site, 'is required.' end end
set_ws_id()
click to toggle source
max wcms id and wcms-music id. Both sources will share the same id space self.ws_id = ::Event.any_of(
{ws_source: 'WCMS'}, {ws_source: 'WCMS-Music'}
).pluck(:ws_id).map(&:to_i).max + 1
# File lib/buweb/event.rb, line 243 def set_ws_id if ws_id.blank? && !imported self.ws_id = ::Event.where(imported: false).max(:ws_id).to_i + 1 end end
site_categories_type()
click to toggle source
# File lib/buweb/event.rb, line 226 def site_categories_type if site_categories.present? && site_categories.ne(type: "Event").present? errors.add :site_categories, 'must be for events.' end end