Class: TicketType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TicketType
- Defined in:
- app/models/ticket_type.rb
Constant Summary collapse
- @@channels =
Each channel needs its own boolean column in the ticket types table.
{ :storefront => "S", :box_office => "B", :members => "M"}
Class Method Summary collapse
- .channels_for(organization) ⇒ Object
- .price_to_cents(price_in_dollars) ⇒ Object
- .set_show(show) ⇒ Object
Instance Method Summary collapse
- #applies_to_pass?(pass) ⇒ Boolean
- #as_json(options = {}) ⇒ Object
-
#available(channel = "storefront", member = nil) ⇒ Object
Returns an integer number of tickets available.
-
#available_tickets(ticket_limit = 4, member = nil) ⇒ Object
Returns Tickets.
- #available_to(member, limit = 0) ⇒ Object
- #channels ⇒ Object
- #committed ⇒ Object
- #comped ⇒ Object
- #dup! ⇒ Object
- #limit_to_s ⇒ Object
- #locked ⇒ Object
- #sold ⇒ Object
- #unlimited? ⇒ Boolean
Class Method Details
.channels_for(organization) ⇒ Object
101 102 103 |
# File 'app/models/ticket_type.rb', line 101 def self.channels_for(organization) (organization.can? :access, :membership) ? @@channels : @@channels.except(:members) end |
.price_to_cents(price_in_dollars) ⇒ Object
80 81 82 |
# File 'app/models/ticket_type.rb', line 80 def self.price_to_cents(price_in_dollars) (price_in_dollars.to_f * 100).to_i end |
.set_show(show) ⇒ Object
129 130 131 |
# File 'app/models/ticket_type.rb', line 129 def self.set_show(show) TicketType.joins(:section => :chart).where('charts.id = ?', show.chart_id).update_all(:show_id => show.id) end |
Instance Method Details
#applies_to_pass?(pass) ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/ticket_type.rb', line 69 def applies_to_pass?(pass) epts = EventsPassType.active .where(:organization_id => pass.organization.id) .where(:event_id => self.show.event.id) .where(:pass_type_id => pass.pass_type.id).first return false if epts.blank? return epts.ticket_types.include?(self.name) end |
#as_json(options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/ticket_type.rb', line 16 def as_json( = {}) { "id" => self.id, "name" => self.name, "price" => self.price, "limit" => self.limit, "available" => self.available, "description" => self.description } end |
#available(channel = "storefront", member = nil) ⇒ Object
Returns an integer number of tickets available
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/ticket_type.rb', line 39 def available(channel = "storefront", member = nil) available_in_section = Ticket.where(:section_id => self.section, :state => :on_sale, :cart_id => nil, :ticket_type_id => nil).count return available_in_section if unlimited? && !self.member_ticket? available_measures = [] available_measures << limit - committed.length - locked.length unless limit.nil? available_measures << available_in_section available_measures << available_to(member, available_in_section) if self.member_ticket? && channel == "storefront" [ available_measures.min, 0].max end |
#available_tickets(ticket_limit = 4, member = nil) ⇒ Object
Returns Tickets
30 31 32 33 34 |
# File 'app/models/ticket_type.rb', line 30 def available_tickets(ticket_limit = 4, member = nil) Ticket.available({:section_id => self.section.id, :ticket_type_id => nil }, [ticket_limit, self.available(member)].min) end |
#available_to(member, limit = 0) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/ticket_type.rb', line 52 def available_to(member, limit = 0) if member.nil? return 0 if self.member_ticket? elsif self.tickets_per_membership.nil? return limit else #how many member tickets has this member purchased for this show? member_tickets_purchased = member.member_tickets_purchased_for(self.show.event).count #how many tickets this member entitled to? tickets_entitled_to = member.memberships.current.where(:membership_type_id => self.membership_type_id).count * self.tickets_per_membership member_tickets_available = tickets_entitled_to - member_tickets_purchased member_tickets_available end end |
#channels ⇒ Object
97 98 99 |
# File 'app/models/ticket_type.rb', line 97 def channels @@channels end |
#committed ⇒ Object
109 110 111 |
# File 'app/models/ticket_type.rb', line 109 def committed tickets.select {|t| t.committed?} end |
#comped ⇒ Object
125 126 127 |
# File 'app/models/ticket_type.rb', line 125 def comped tickets.select {|t| t.comped?} end |
#dup! ⇒ Object
93 94 95 |
# File 'app/models/ticket_type.rb', line 93 def dup! TicketType.new(self.attributes.reject { |key, value| key == 'id' }, :without_protection => true) end |
#limit_to_s ⇒ Object
113 114 115 |
# File 'app/models/ticket_type.rb', line 113 def limit_to_s unlimited? ? "unlimited" : "#{self.limit} limit" end |
#locked ⇒ Object
121 122 123 |
# File 'app/models/ticket_type.rb', line 121 def locked tickets.select {|t| t.locked?} end |
#sold ⇒ Object
105 106 107 |
# File 'app/models/ticket_type.rb', line 105 def sold tickets.select {|t| t.sold?} end |
#unlimited? ⇒ Boolean
117 118 119 |
# File 'app/models/ticket_type.rb', line 117 def unlimited? self.limit.nil? end |