Class: Section

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Ticket::Foundry
Defined in:
app/models/section.rb

Direct Known Subclasses

DiscountSection

Constant Summary collapse

@@channels =

Each channel needs its own boolean column in the sections table. @@channels = { :storefront => “S”, :box_office => “B”, :members => “M”}

{ :storefront => "S", :box_office => "B"}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ticket::Foundry

#build_tickets, #create_tickets, #foundry_template

Instance Attribute Details

#skip_create_first_ticket_typeObject

Returns the value of attribute skip_create_first_ticket_type.



3
4
5
# File 'app/models/section.rb', line 3

def skip_create_first_ticket_type
  @skip_create_first_ticket_type
end

Instance Method Details

#as_json(options = {}) ⇒ Object



99
100
101
102
# File 'app/models/section.rb', line 99

def as_json(options = {})
  options ||= {}
  super(:methods => [:summary, :ticket_types]).merge(options)
end

#availableObject



95
96
97
# File 'app/models/section.rb', line 95

def available
  Ticket.on_sale.where(:section_id => self.id).where(:cart_id => nil).count
end

#channelsObject



34
35
36
# File 'app/models/section.rb', line 34

def channels
  @@channels
end

#create_first_ticket_typeObject



47
48
49
50
51
52
53
54
# File 'app/models/section.rb', line 47

def create_first_ticket_type
  if self.ticket_types.empty?
    self.ticket_types.build({ :name     => "General Admission",
                              :price    => 0,
                              :limit    => nil},
                              :without_protection => true).save
  end
end

#dup!Object



74
75
76
77
78
79
# File 'app/models/section.rb', line 74

def dup!    
  attrs = self.attributes.reject { |key, value| key == 'id' }
  self.class.new(attrs).tap do |copy|
    copy.ticket_types = self.ticket_types.collect { |ticket_type| ticket_type.dup! }
  end
end

#put_on_sale(qty = 0) ⇒ Object



81
82
83
84
85
86
# File 'app/models/section.rb', line 81

def put_on_sale(qty = 0)
  tickets.off_sale.limit(qty).each do |t|
    t.put_on_sale
  end
  show.refresh_stats
end

#summarizeObject



38
39
40
41
# File 'app/models/section.rb', line 38

def summarize
  tickets = Ticket.where(:section_id => id)
  @summary = SectionSummary.for_tickets(tickets)
end

#summaryObject



43
44
45
# File 'app/models/section.rb', line 43

def summary
  @summary || summarize
end

#take_off_sale(qty = 0) ⇒ Object



88
89
90
91
92
93
# File 'app/models/section.rb', line 88

def take_off_sale(qty = 0)
  tickets.on_sale.limit(qty).each do |t|
    t.take_off_sale
  end
  show.refresh_stats
end

#ticket_types_for(member = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/section.rb', line 56

def ticket_types_for(member = nil)
  types = []

  # Add storefront types regardless of anything
  types << ticket_types.storefront
  unless member.nil?

    #Add "unrestricted member" ticket_types that aren't tied to a particular membership type
    types << ticket_types.members.select{|ticket_type| !ticket_type.member_ticket?} unless member.nil?

    #Now add member ticket_types that apply to this particular member
    membership_type_ids = member.nil? ? [] : member.current_membership_types.collect(&:id)
    types << ticket_types.select{|ticket_type| ticket_type.members && membership_type_ids.include?(ticket_type.membership_type_id) }
  end

  types.flatten.uniq
end