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

Inherits:
ApplicationRecord show all
Includes:
Partable
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 20


#delegatesActiveRecord::Relation

Returns directly associated delegates.

See Also:



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

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:



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

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

#institutionsActiveRecord::Relation

Returns Institutions associated with #rooms.

See Also:



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

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

#nameString?



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

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:



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

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

#presentationsActiveRecord::Relation

Returns Presentations associated with #sessions.



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

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

#roomsActiveRecord::Relation

Returns Rooms associated with #sessions.

See Also:

  • Room
  • Session#rooms


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

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

#sessionsActiveRecord::Relation

Returns Sessions associated with #presentation_types.



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

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

Instance Method Details

#finish_dateDate?



91
92
93
94
95
96
97
98
99
# File 'app/models/spina/admin/conferences/conference.rb', line 91

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.



104
105
106
# File 'app/models/spina/admin/conferences/conference.rb', line 104

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

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



117
118
119
120
121
# File 'app/models/spina/admin/conferences/conference.rb', line 117

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



124
125
126
# File 'app/models/spina/admin/conferences/conference.rb', line 124

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

#sortedActiveRecord::Relation



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

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

#start_dateDate?



77
78
79
80
81
# File 'app/models/spina/admin/conferences/conference.rb', line 77

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.



86
87
88
# File 'app/models/spina/admin/conferences/conference.rb', line 86

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

#to_eventIcalendar::Event



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

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



146
147
148
# File 'app/models/spina/admin/conferences/conference.rb', line 146

def to_ics
  to_event
end

#yearInteger?



109
110
111
112
113
# File 'app/models/spina/admin/conferences/conference.rb', line 109

def year
  return if start_date.blank?

  start_date.try(:year)
end