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>?

Returns the dates of the conference.

Returns:

  • (Range<Date>, nil)

    the dates of the conference



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


#delegatesActiveRecord::Relation

Returns directly associated delegates.

Returns:

  • (ActiveRecord::Relation)

    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.

Returns:

  • (ActiveRecord::Relation)

    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.

Returns:

  • (ActiveRecord::Relation)

    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?

Returns the translated name of the conference.

Returns:

  • (String, nil)

    the translated name of the conference



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.

Returns:

  • (ActiveRecord::Relation)

    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.

Returns:

  • (ActiveRecord::Relation)

    Presentations associated with #sessions

See Also:



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.

Returns:

  • (ActiveRecord::Relation)

    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.

Returns:

See Also:



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?

Returns the finish date of the conference. Nil if the conference has no dates.

Returns:

  • (Date, nil)

    the finish date of the conference. Nil if the conference has no dates



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.

Parameters:

  • date (Date)

    the new finish date



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}>?

Returns an array of hashes containing the date in ISO 8601 format and as a localised string Nil if the conference has no dates.

Returns:

  • (Array<Hash{Symbol=>String}>, nil)

    an array of hashes containing the date in ISO 8601 format and as a localised string Nil if the conference has no dates.



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

Returns the names of each institution associated with the conference.

Returns:

  • (String)

    the names of each institution associated with the conference



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

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

#sortedActiveRecord::Relation

Returns all conferences, ordered by date.

Returns:

  • (ActiveRecord::Relation)

    all conferences, ordered by date



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

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

#start_dateDate?

Returns the start date of the conference. Nil if the conference has no dates.

Returns:

  • (Date, nil)

    the start date of the conference. Nil if the conference has no dates



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.

Parameters:

  • date (Date)

    the new start date



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

Returns the conference as an iCal event.

Returns:

  • (Icalendar::Event)

    the conference as an iCal 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?

Returns the year of the conference. Nil if the conference has no dates.

Returns:

  • (Integer, nil)

    the year of the conference. Nil if the conference has no dates



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