Sha256: 815564c06090cfc8d1ebfa25d586534fed4676ac308f8cf6473595a0d0ebfad4

Contents?: true

Size: 1.85 KB

Versions: 33

Compression:

Stored size: 1.85 KB

Contents

module EffectiveEventsHelper
  def effective_events_event_schedule(event)
    if event.start_at.beginning_of_day == event.end_at.beginning_of_day
      "#{event.start_at.strftime("%b %d, %Y %I:%M%P")} - #{event.end_at.strftime("%I:%M%P")}"
    else
      "#{event.start_at.strftime("%b %d, %Y")} - #{event.end_at.strftime("%b %d, %Y")}"
    end
  end

  def effective_events_event_tickets_collection(event, namespace = nil)
    raise('expected an Effective::Event') unless event.kind_of?(Effective::Event)

    # Allow an admin to assign archived tickets
    authorized = (namespace == :admin)
    tickets = (authorized ? event.event_tickets : event.event_tickets.reject(&:archived?))

    tickets.map do |ticket|
      title = ticket.to_s
      price = (ticket.price == 0 ? '$0' : price_to_currency(ticket.price))
      remaining = (ticket.capacity.present? ? "#{ticket.capacity_available} remaining" : nil)

      label = [title, price, remaining].compact.join(' - ')
      disabled = { disabled: :disabled } unless (authorized || ticket.available?)

      [label, ticket.to_param, disabled].compact
    end
  end

  def effective_events_event_products_collection(event, namespace = nil)
    raise('expected an Effective::Event') unless event.kind_of?(Effective::Event)

    # Allow an admin to assign archived products
    authorized = (namespace == :admin)
    products = (authorized ? event.event_products : event.event_products.reject(&:archived?))

    products.map do |product|
      title = product.to_s
      price = (product.price == 0 ? '$0' : price_to_currency(product.price))
      remaining = (product.capacity.present? ? "#{product.capacity_available} remaining" : nil)

      label = [title, price, remaining].compact.join(' - ')
      disabled = { disabled: :disabled } unless (authorized || product.available?)

      [label, product.to_param, disabled].compact
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
effective_events-0.10.2 app/helpers/effective_events_helper.rb
effective_events-0.10.1 app/helpers/effective_events_helper.rb
effective_events-0.10.0 app/helpers/effective_events_helper.rb
effective_events-0.9.3 app/helpers/effective_events_helper.rb
effective_events-0.9.2 app/helpers/effective_events_helper.rb
effective_events-0.9.1 app/helpers/effective_events_helper.rb
effective_events-0.9.0 app/helpers/effective_events_helper.rb
effective_events-0.8.0 app/helpers/effective_events_helper.rb
effective_events-0.7.4 app/helpers/effective_events_helper.rb
effective_events-0.7.3 app/helpers/effective_events_helper.rb
effective_events-0.7.2 app/helpers/effective_events_helper.rb
effective_events-0.7.1 app/helpers/effective_events_helper.rb
effective_events-0.7.0 app/helpers/effective_events_helper.rb
effective_events-0.6.13 app/helpers/effective_events_helper.rb
effective_events-0.6.12 app/helpers/effective_events_helper.rb
effective_events-0.6.11 app/helpers/effective_events_helper.rb
effective_events-0.6.10 app/helpers/effective_events_helper.rb
effective_events-0.6.9 app/helpers/effective_events_helper.rb
effective_events-0.6.8 app/helpers/effective_events_helper.rb
effective_events-0.6.7 app/helpers/effective_events_helper.rb