Class: Spina::Admin::Conferences::Conference
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Admin::Conferences::Conference
- Includes:
- AttrJson::NestedAttributes, AttrJson::Record, Partable, TranslatedContent
- Defined in:
- app/models/spina/admin/conferences/conference.rb
Overview
Instance Attribute Summary collapse
-
#dates ⇒ Range<Date>?
The dates of the conference.
-
#delegates ⇒ ActiveRecord::Relation
Directly associated delegates.
-
#events ⇒ ActiveRecord::Relation
Directly associated events.
-
#institutions ⇒ ActiveRecord::Relation
Institutions associated with #rooms.
-
#name ⇒ String?
The translated name of the conference.
-
#presentation_types ⇒ ActiveRecord::Relation
Directly associated presentation types.
-
#presentations ⇒ ActiveRecord::Relation
Presentations associated with #sessions.
-
#rooms ⇒ ActiveRecord::Relation
Rooms associated with #sessions.
-
#sessions ⇒ ActiveRecord::Relation
Sessions associated with #presentation_types.
Instance Method Summary collapse
-
#finish_date ⇒ Date?
The finish date of the conference.
-
#finish_date=(date) ⇒ void
Sets the finish date of the conference.
-
#localized_dates ⇒ Array<Hash{Symbol=>String}>?
An array of hashes containing the date in ISO 8601 format and as a localised string Nil if the conference has no dates.
-
#location ⇒ String
The names of each institution associated with the conference.
-
#sorted ⇒ ActiveRecord::Relation
All conferences, ordered by date.
-
#start_date ⇒ Date?
The start date of the conference.
-
#start_date=(date) ⇒ void
Sets the start date of the conference.
-
#to_event ⇒ Icalendar::Event
The conference as an iCal event.
-
#to_ics ⇒ Object
deprecated
Deprecated.
Use #to_event instead
-
#year ⇒ Integer?
The year of the conference.
Instance Attribute Details
#dates ⇒ Range<Date>?
|
|
# File 'app/models/spina/admin/conferences/conference.rb', line 23
|
#delegates ⇒ ActiveRecord::Relation
Returns directly associated delegates.
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 |
#events ⇒ ActiveRecord::Relation
Destroying a conference destroys dependent events.
Returns directly associated events.
42 |
# File 'app/models/spina/admin/conferences/conference.rb', line 42 has_many :events, -> { includes(:translations) }, inverse_of: :conference, dependent: :destroy |
#institutions ⇒ ActiveRecord::Relation
Returns Institutions associated with #rooms.
62 |
# File 'app/models/spina/admin/conferences/conference.rb', line 62 has_many :institutions, -> { distinct.includes(:translations) }, through: :rooms |
#name ⇒ String?
28 |
# File 'app/models/spina/admin/conferences/conference.rb', line 28 translates :name, fallbacks: true |
#presentation_types ⇒ ActiveRecord::Relation
A conference cannot be destroyed if it has dependent presentation types.
Returns directly associated presentation types.
37 |
# File 'app/models/spina/admin/conferences/conference.rb', line 37 has_many :presentation_types, -> { includes(:translations) }, inverse_of: :conference, dependent: :restrict_with_error |
#presentations ⇒ ActiveRecord::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 |
#rooms ⇒ ActiveRecord::Relation
Returns Rooms associated with #sessions.
57 |
# File 'app/models/spina/admin/conferences/conference.rb', line 57 has_many :rooms, -> { distinct.includes(:translations) }, through: :sessions |
#sessions ⇒ ActiveRecord::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_date ⇒ Date?
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_dates ⇒ Array<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 |
#location ⇒ String
121 122 123 |
# File 'app/models/spina/admin/conferences/conference.rb', line 121 def location institutions.collect(&:name).to_sentence end |
#sorted ⇒ ActiveRecord::Relation
31 |
# File 'app/models/spina/admin/conferences/conference.rb', line 31 scope :sorted, -> { order dates: :desc } |
#start_date ⇒ Date?
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_event ⇒ Icalendar::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::Account.first.email event.categories = Conference.model_name.human(count: 0) event.summary = name event end |
#to_ics ⇒ Object
Use #to_event instead
143 144 145 |
# File 'app/models/spina/admin/conferences/conference.rb', line 143 def to_ics to_event end |
#year ⇒ Integer?
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 |