<commit_before># frozen_string_literal: true

# == Schema Information
#
# Table name: events
#
#  id              :integer          not null, primary key
#  title           :string(255)
#  slug            :string(255)
#  content         :text(65535)
#  all_day         :boolean          default(FALSE)
#  start_date      :datetime
#  end_date        :datetime
#  show_as_gallery :boolean          default(FALSE)
#  show_calendar   :boolean          default(FALSE)
#  online          :boolean          default(TRUE)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#
# Indexes
#
#  index_events_on_slug  (slug)
#

#
# == Event model
#
class Event < ActiveRecord::Base
  include Core::Referenceable
  include OptionalModules::Assets::Imageable
  include OptionalModules::Assets::VideoPlatformable
  include OptionalModules::Assets::VideoUploadable
  include OptionalModules::Searchable
  include PrevNextable
  include Linkable

  translates :title, :slug, :content, fallbacks_for_empty_translations: true
  active_admin_translates :title, :slug, :content, fallbacks_for_empty_translations: true

  extend FriendlyId
  friendly_id :title, use: [:slugged, :history, :globalize, :finders]

  has_one :location, as: :locationable, dependent: :destroy
  accepts_nested_attributes_for :location, reject_if: :all_blank, allow_destroy: true

  validate :calendar_date_correct?, unless: proc { end_date.blank? && start_date.blank? }

  delegate :address, :postcode, :city, to: :location, prefix: true, allow_nil: true

  scope :online, -> { where(online: true) }
  scope :current_or_coming, -> { where('(start_date <= ? AND end_date is ?) OR (start_date >= ?) OR (start_date <= ? AND end_date >= ?)', Time.zone.now, nil, Time.zone.now, Time.zone.now, Time.zone.now) }

  def calendar_date_correct?
    return true unless end_date <= start_date
    errors.add :start_date, I18n.t('form.errors.start_date')
    errors.add :end_date, I18n.t('form.errors.end_date')
  end

  def self.with_conditions
    event_order = EventSetting.first.event_order
    return current_or_coming.order(start_date: :asc) if event_order.key == 'current_or_coming'
    order(start_date: :desc)
  end
end<commit_msg>Update current_or_coming Event scope to handle one day events as well<commit_after># frozen_string_literal: true

# == Schema Information
#
# Table name: events
#
#  id              :integer          not null, primary key
#  title           :string(255)
#  slug            :string(255)
#  content         :text(65535)
#  all_day         :boolean          default(FALSE)
#  start_date      :datetime
#  end_date        :datetime
#  show_as_gallery :boolean          default(FALSE)
#  show_calendar   :boolean          default(FALSE)
#  online          :boolean          default(TRUE)
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#
# Indexes
#
#  index_events_on_slug  (slug)
#

#
# == Event model
#
class Event < ActiveRecord::Base
  include Core::Referenceable
  include OptionalModules::Assets::Imageable
  include OptionalModules::Assets::VideoPlatformable
  include OptionalModules::Assets::VideoUploadable
  include OptionalModules::Searchable
  include PrevNextable
  include Linkable

  translates :title, :slug, :content, fallbacks_for_empty_translations: true
  active_admin_translates :title, :slug, :content, fallbacks_for_empty_translations: true

  extend FriendlyId
  friendly_id :title, use: [:slugged, :history, :globalize, :finders]

  has_one :location, as: :locationable, dependent: :destroy
  accepts_nested_attributes_for :location, reject_if: :all_blank, allow_destroy: true

  validate :calendar_date_correct?, unless: proc { end_date.blank? && start_date.blank? }

  delegate :address, :postcode, :city, to: :location, prefix: true, allow_nil: true

  scope :online, -> { where(online: true) }
  scope :current_or_coming, -> { where('(start_date >= ?) OR (start_date <= ? AND end_date >= ?) OR (start_date = ? AND all_day = ?)', Time.zone.now, Time.zone.now, Time.zone.now, Time.zone.today, true) }

  def calendar_date_correct?
    return true unless end_date <= start_date
    errors.add :start_date, I18n.t('form.errors.start_date')
    errors.add :end_date, I18n.t('form.errors.end_date')
  end

  def self.with_conditions
    event_order = EventSetting.first.event_order
    return current_or_coming.order(start_date: :asc) if event_order.key == 'current_or_coming'
    order(start_date: :desc)
  end
end
{'fraction_non_alphanumeric': 0.10528653931585961, 'fraction_numerical': 0.006663705019991115, 'mean_word_length': 3.7350157728706623, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5618114', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1422, 'n_words': 336}