Module: EffectiveEventsHelper

Defined in:
app/helpers/effective_events_helper.rb

Instance Method Summary collapse

Instance Method Details

#effective_events_event_products_collection(event, namespace = nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/effective_events_helper.rb', line 65

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 || event.event_product_available?(product, quantity: 1))

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

#effective_events_event_registrant_user_collection(event_registrant) ⇒ Object



84
85
86
87
88
89
90
# File 'app/helpers/effective_events_helper.rb', line 84

def effective_events_event_registrant_user_collection(event_registrant)
  raise("expected an Effective::EventRegistrant") unless event_registrant.kind_of?(Effective::EventRegistrant)

  Array(event_registrant.event_registration&.event_ticket_member_users).map do |user|
    ["<span>#{user}</span> <small>#{user.email}</small>", user.to_param]
  end
end

#effective_events_event_registrant_user_hintObject



92
93
94
95
96
97
98
99
100
101
# File 'app/helpers/effective_events_helper.rb', line 92

def effective_events_event_registrant_user_hint
  url = if current_user.class.try(:effective_memberships_organization_user?)
    organization = current_user.membership_organizations.first || current_user.organizations.first
    effective_memberships.edit_organization_path(organization, anchor: 'tab-representatives') if organization
  end
  
  return if url.blank?

  "Can't find the member you need? <a href='#{url}' target='blank'>Click here</a> to add them to your #{EffectiveResources.etd(EffectiveMemberships.Organization)}."
end

#effective_events_event_schedule(event) ⇒ Object



18
19
20
21
22
23
24
# File 'app/helpers/effective_events_helper.rb', line 18

def effective_events_event_schedule(event)
  if event.start_at.beginning_of_day == event.end_at.beginning_of_day
    "#{event.start_at.strftime("%A, %B %d, %Y ยท %l:%M%P")} - #{event.end_at.strftime("%l:%M%P")}"
  else
    "#{event.start_at.strftime("%A, %B %d, %Y")} - #{event.end_at.strftime("%A, %B %d, %Y")}"
  end
end

#effective_events_event_tickets_collection(event, namespace = nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/effective_events_helper.rb', line 43

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)
  member = current_user.try(:is_any?, :member)

  tickets = (authorized ? event.event_tickets : event.event_tickets.reject(&:archived?))
  tickets = tickets.reject { |ticket| ticket.member_only? } unless (authorized || member)

  tickets.map do |ticket|
    title = ticket.to_s
    price = effective_events_ticket_price(event, ticket)

    label = [title, price].compact.join(' - ')

    disabled = { disabled: :disabled } unless (authorized || ticket.waitlist? || event.event_ticket_available?(ticket, quantity: 1))

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

#effective_events_ticket_price(event, ticket) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/effective_events_helper.rb', line 26

def effective_events_ticket_price(event, ticket)
  raise('expected an Effective::Event') unless event.kind_of?(Effective::Event)
  raise('expected an Effective::EventTicket') unless ticket.kind_of?(Effective::EventTicket)

  prices = [
    (ticket.early_bird_price if event.early_bird?), 
    (ticket.regular_price if ticket.regular? || ticket.member_or_non_member?),
    (ticket.member_price if ticket.member_only? || ticket.member_or_non_member?)
  ].compact.sort.uniq

  if prices.length > 1
    "#{(prices.first == 0 ? '$0' : price_to_currency(prices.first))} or #{(prices.last == 0 ? '$0' : price_to_currency(prices.last))}"
  else
    (prices.first == 0 ? '$0' : price_to_currency(prices.first))
  end
end

#event_labelObject

Event



9
10
11
# File 'app/helpers/effective_events_helper.rb', line 9

def event_label
  et(Effective::Event)
end

#events_labelObject

Events



14
15
16
# File 'app/helpers/effective_events_helper.rb', line 14

def events_label
  ets(Effective::Event)
end

#events_name_labelObject

Events



4
5
6
# File 'app/helpers/effective_events_helper.rb', line 4

def events_name_label
  et('effective_events.name')
end