Sha256: 0493529543e473507943b0aa08c57ef18c8dbc06856cb338944e878732cf76b1

Contents?: true

Size: 1.84 KB

Versions: 4

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

class Tramway::Event::Event < ::Tramway::Event::ApplicationRecord
  mount_uploader :photo, PhotoUploader

  validate :check_dimensions

  def check_dimensions
    if photo.present?
      errors.add :photo, :too_small_image if photo.width < 1920 || photo.height < 1080
    end
  end

  has_many :participants, class_name: 'Tramway::Event::Participant'
  has_many :participant_form_fields, class_name: 'Tramway::Event::ParticipantFormField'
  has_many :sections, class_name: 'Tramway::Event::Section'
  has_many :partakings, as: :part, class_name: 'Tramway::Event::Partaking'
  has_many :partnerships, class_name: 'Tramway::Partner::Partnership', as: :partner
  has_many :organizations, as: :partners, through: :partnerships, class_name: 'Tramway::Partner::Organization'
  has_many :actions, -> { order(id: :asc) }, class_name: 'Tramway::Event::Action'
  has_and_belongs_to_many :places

  enumerize :reach, default: :open, in: %i[open closed]

  scope :actual, -> { order(:begin_date).where('end_date > ?', DateTime.now) }
  scope :past, -> { where 'end_date < ?', DateTime.now }
  scope :open, -> { where reach: :open }
  scope :closed, -> { where reach: :closed }

  def request_collecting_state
    return :not_initialized unless request_collecting_begin_date.present? || request_collecting_end_date.present?
    return :will_begin_soon if request_collecting_begin_date > DateTime.now
    return :is_over if request_collecting_end_date.present? && request_collecting_end_date.to_date < Date.today
    return :are_being_right_now if request_collecting_begin_date&.past? && (request_collecting_end_date&.future? || request_collecting_end_date&.today?)
    return :are_being_right_now if request_collecting_begin_date < DateTime.now && !request_collecting_end_date.present?
  end

  include ::Tramway::Partner::Scopes if defined? ::Tramway::Partner
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tramway-event-1.12.1 app/models/tramway/event/event.rb
tramway-event-1.12.0.1 app/models/tramway/event/event.rb
tramway-event-1.12 app/models/tramway/event/event.rb
tramway-event-1.11.5.1 app/models/tramway/event/event.rb