Class: Spina::Admin::Conferences::Conference

Inherits:
ApplicationRecord show all
Includes:
AttrJson::NestedAttributes, AttrJson::Record, Partable, TranslatedContent
Defined in:
app/models/spina/admin/conferences/conference.rb

Overview

Conference records.

Validators

Presence

#name, #start_date, #finish_date, #year.

Conference date (using FinishDateValidator)

#finish_date.

Translations

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#datesRange<Date>?



# File 'app/models/spina/admin/conferences/conference.rb', line 23


#delegatesActiveRecord::Relation

Returns directly associated delegates.

See Also:



66
67
# File 'app/models/spina/admin/conferences/conference.rb', line 66

has_and_belongs_to_many :delegates, foreign_key: :spina_conferences_conference_id, # rubocop:disable Rails/HasAndBelongsToMany
association_foreign_key: :spina_conferences_delegate_id

#eventsActiveRecord::Relation

Note:

Destroying a conference destroys dependent events.

Returns directly associated events.

See Also:



42
# File 'app/models/spina/admin/conferences/conference.rb', line 42

has_many :events, -> { includes(:translations) }, inverse_of: :conference, dependent: :destroy

#institutionsActiveRecord::Relation

Returns Institutions associated with #rooms.

See Also:



62
# File 'app/models/spina/admin/conferences/conference.rb', line 62

has_many :institutions, -> { distinct.includes(:translations) }, through: :rooms

#nameString?



28
# File 'app/models/spina/admin/conferences/conference.rb', line 28

translates :name, fallbacks: true

#presentation_typesActiveRecord::Relation

Note:

A conference cannot be destroyed if it has dependent presentation types.

Returns directly associated presentation types.

See Also:



37
# File 'app/models/spina/admin/conferences/conference.rb', line 37

has_many :presentation_types, -> { includes(:translations) }, inverse_of: :conference, dependent: :restrict_with_error

#presentationsActiveRecord::Relation

Returns Presentations associated with #sessions.



52
# File 'app/models/spina/admin/conferences/conference.rb', line 52

has_many :presentations, -> { distinct.includes(:translations) }, through: :sessions

#roomsActiveRecord::Relation

Returns Rooms associated with #sessions.

See Also:

  • Room
  • Session#rooms


57
# File 'app/models/spina/admin/conferences/conference.rb', line 57

has_many :rooms, -> { distinct.includes(:translations) }, through: :sessions

#sessionsActiveRecord::Relation

Returns Sessions associated with #presentation_types.



47
# File 'app/models/spina/admin/conferences/conference.rb', line 47

has_many :sessions, -> { distinct.includes(:translations) }, through: :presentation_types

Instance Method Details

#finish_dateDate?



88
89
90
91
92
93
94
95
96
# File 'app/models/spina/admin/conferences/conference.rb', line 88

def finish_date
  return if dates.blank?

  if dates.exclude_end?
    dates.end - 1.day if dates.end.is_a? Date
  else
    dates.end
  end
end

#finish_date=(date) ⇒ void

This method returns an undefined value.

Sets the finish date of the conference.



101
102
103
# File 'app/models/spina/admin/conferences/conference.rb', line 101

def finish_date=(date)
  self.dates = start_date..date.try(:to_date)
end

#localized_datesArray<Hash{Symbol=>String}>?



114
115
116
117
118
# File 'app/models/spina/admin/conferences/conference.rb', line 114

def localized_dates
  return if dates.blank?

  dates.entries.collect { |date| { date: date.to_formatted_s(:iso8601), localization: I18n.l(date, format: :long) } }
end

#locationString



121
122
123
# File 'app/models/spina/admin/conferences/conference.rb', line 121

def location
  institutions.collect(&:name).to_sentence
end

#sortedActiveRecord::Relation



31
# File 'app/models/spina/admin/conferences/conference.rb', line 31

scope :sorted, -> { order dates: :desc }

#start_dateDate?



74
75
76
77
78
# File 'app/models/spina/admin/conferences/conference.rb', line 74

def start_date
  return if dates.blank?

  dates.begin
end

#start_date=(date) ⇒ void

This method returns an undefined value.

Sets the start date of the conference.



83
84
85
# File 'app/models/spina/admin/conferences/conference.rb', line 83

def start_date=(date)
  self.dates = date.try(:to_date)..finish_date
end

#to_eventIcalendar::Event



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/models/spina/admin/conferences/conference.rb', line 126

def to_event # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  event = Icalendar::Event.new
  return event if invalid?

  event.dtstart = start_date
  event.dtstart.ical_param(:value, 'DATE')
  event.dtend = finish_date
  event.dtend.ical_param(:value, 'DATE')
  event.location = location
  event.contact = Spina::.first.email
  event.categories = Conference.model_name.human(count: 0)
  event.summary = name
  event
end

#to_icsObject

Deprecated.

Use #to_event instead



143
144
145
# File 'app/models/spina/admin/conferences/conference.rb', line 143

def to_ics
  to_event
end

#yearInteger?



106
107
108
109
110
# File 'app/models/spina/admin/conferences/conference.rb', line 106

def year
  return if start_date.blank?

  start_date.try(:year)
end