Class: Spina::Admin::Conferences::Presentation

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

Overview

Presentation records.

Validators

Presence

#title, #date, #start_time, #start_datetime, #abstract, #presenters.

Conference date (using ConferenceDateValidator)

#date.

Translations

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#abstractString?

Returns the presentation abstract.

Returns:

  • (String, nil)

    the presentation abstract



32
# File 'app/models/spina/admin/conferences/presentation.rb', line 32

translates :title, :abstract, fallbacks: true

#attachmentsActiveRecord::Relation

Note:

This relation accepts nested attributes.

Note:

Destroying a presentation destroys associated attachments.

Returns directly associated presentation attachments.

Returns:

  • (ActiveRecord::Relation)

    directly associated presentation attachments

See Also:

  • Attachment


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

has_many :attachments, class_name: 'Spina::Admin::Conferences::PresentationAttachment', dependent: :destroy,
inverse_of: :presentation

#conferenceConference?

Returns Conference associated with #presentation_type.

Returns:

See Also:



60
# File 'app/models/spina/admin/conferences/presentation.rb', line 60

has_one :conference, -> { includes(:translations) }, through: :presentation_type

#nameString?

Returns the presentation title (alias).

Returns:

  • (String, nil)

    the presentation title (alias)

See Also:



40
# File 'app/models/spina/admin/conferences/presentation.rb', line 40

alias_attribute :name, :title

#presentation_typePresentationType?

Returns Presentation type associated with #session.

Returns:

See Also:



50
# File 'app/models/spina/admin/conferences/presentation.rb', line 50

has_one :presentation_type, -> { includes(:translations) }, through: :session

#presentersActiveRecord::Relation

Returns directly associated delegates.

Returns:

  • (ActiveRecord::Relation)

    directly associated delegates

See Also:



71
72
73
# File 'app/models/spina/admin/conferences/presentation.rb', line 71

has_and_belongs_to_many :presenters, class_name: 'Spina::Admin::Conferences::Delegate', # rubocop:disable Rails/HasAndBelongsToMany
foreign_key: :spina_conferences_presentation_id,
association_foreign_key: :spina_conferences_delegate_id

#roomRoom?

Returns Room associated with #session.

Returns:

See Also:



55
# File 'app/models/spina/admin/conferences/presentation.rb', line 55

has_one :room, -> { includes(:translations) }, through: :session

#sessionSession?

Returns directly associated session.

Returns:

  • (Session, nil)

    directly associated session

See Also:



45
# File 'app/models/spina/admin/conferences/presentation.rb', line 45

belongs_to :session, -> { includes(:translations) }, inverse_of: :presentations, touch: true

#start_datetimeActiveSupport::TimeWithZone?

Returns the presentation start time.

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the presentation start time



26
# File 'app/models/spina/admin/conferences/presentation.rb', line 26

default_scope { includes(:translations) }

#start_timeActiveSupport::TimeWithZone?

Returns the start time (alias).

Returns:

  • (ActiveSupport::TimeWithZone, nil)

    the start time (alias)

See Also:



84
# File 'app/models/spina/admin/conferences/presentation.rb', line 84

alias_attribute :start_time, :start_datetime

#titleString?

Returns the presentation title.

Returns:

  • (String, nil)

    the presentation title



32
# File 'app/models/spina/admin/conferences/presentation.rb', line 32

translates :title, :abstract, fallbacks: true

Class Method Details

.import(file) ⇒ void

This method returns an undefined value.

Imports a presentation from CSV.

Parameters:

  • file (String)

    the CSV file to be read

See Also:



90
91
92
# File 'app/models/spina/admin/conferences/presentation.rb', line 90

def self.import(file)
  PresentationImportJob.perform_later IO.read(file)
end

Instance Method Details

#dateDate?

Returns the start date of the presentation. Nil if the presentation has no start date and time.

Returns:

  • (Date, nil)

    the start date of the presentation. Nil if the presentation has no start date and time



95
96
97
98
99
# File 'app/models/spina/admin/conferences/presentation.rb', line 95

def date
  return if start_datetime.blank?

  start_datetime.to_date
end

#sortedActiveRecord::Relation

Returns all conferences, ordered by date.

Returns:

  • (ActiveRecord::Relation)

    all conferences, ordered by date



35
# File 'app/models/spina/admin/conferences/presentation.rb', line 35

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

#to_eventIcalendar::Event

Returns the presentation as an iCal event.

Returns:

  • (Icalendar::Event)

    the presentation as an iCal event



102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/spina/admin/conferences/presentation.rb', line 102

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

  event.dtstart = start_datetime
  event.dtend = start_datetime + presentation_type.duration
  event.location = session.room_name
  presenters.each { |presenter| event.contact = presenter.full_name_and_institution }
  event.categories = Presentation.model_name.human(count: 0)
  event.summary = title
  event.append_custom_property('alt_description', abstract.try(:html_safe))
  event.description = abstract.try(:gsub, %r{</?[^>]*>}, '')
  event
end

#to_icsObject

Deprecated.

Use #to_event instead



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

def to_ics
  to_event
end