Class: Spina::Admin::Conferences::Conference
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Spina::Admin::Conferences::Conference
- Includes:
- Partable
- 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 20
|
#delegates ⇒ ActiveRecord::Relation
Returns directly associated delegates.
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 |
#events ⇒ ActiveRecord::Relation
Destroying a conference destroys dependent events.
Returns directly associated events.
39 |
# File 'app/models/spina/admin/conferences/conference.rb', line 39 has_many :events, -> { includes(:translations) }, inverse_of: :conference, dependent: :destroy |
#institutions ⇒ ActiveRecord::Relation
Returns Institutions associated with #rooms.
64 |
# File 'app/models/spina/admin/conferences/conference.rb', line 64 has_many :institutions, -> { distinct.includes(:translations) }, through: :rooms |
#name ⇒ String?
25 |
# File 'app/models/spina/admin/conferences/conference.rb', line 25 translates :name, fallbacks: true |
#presentation_types ⇒ ActiveRecord::Relation
A conference cannot be destroyed if it has dependent presentation types.
Returns directly associated presentation types.
34 |
# File 'app/models/spina/admin/conferences/conference.rb', line 34 has_many :presentation_types, -> { includes(:translations) }, inverse_of: :conference, dependent: :restrict_with_error |
#presentations ⇒ ActiveRecord::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 |
#rooms ⇒ ActiveRecord::Relation
Returns Rooms associated with #sessions.
59 |
# File 'app/models/spina/admin/conferences/conference.rb', line 59 has_many :rooms, -> { distinct.includes(:translations) }, through: :sessions |
#sessions ⇒ ActiveRecord::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_date ⇒ Date?
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_dates ⇒ Array<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 |
#location ⇒ String
124 125 126 |
# File 'app/models/spina/admin/conferences/conference.rb', line 124 def location institutions.collect(&:name).to_sentence end |
#sorted ⇒ ActiveRecord::Relation
28 |
# File 'app/models/spina/admin/conferences/conference.rb', line 28 scope :sorted, -> { order dates: :desc } |
#start_date ⇒ Date?
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_event ⇒ Icalendar::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::Account.first.email event.categories = Conference.model_name.human(count: 0) event.summary = name event end |
#to_ics ⇒ Object
Use #to_event instead
146 147 148 |
# File 'app/models/spina/admin/conferences/conference.rb', line 146 def to_ics to_event end |
#year ⇒ Integer?
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 |