Class: Show
Constant Summary
Constants included
from Ext::Uuid
Ext::Uuid::PREFIX
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Ext::Uuid
included, #set_uuid, uuid
#chart_for, #record_publish
#glance
#build_tickets, #create_tickets, #foundry_template
Class Method Details
.next_datetime(show) ⇒ Object
154
155
156
|
# File 'app/models/show.rb', line 154
def self.next_datetime(show)
show.nil? ? future(Time.now.beginning_of_day + 20.hours) : future(show.datetime_local_to_event + 1.day)
end
|
Instance Method Details
#<=>(obj) ⇒ Object
275
276
277
278
279
280
281
282
283
|
# File 'app/models/show.rb', line 275
def <=>(obj)
return -1 unless obj.kind_of? Show
if self.event == obj.event
self.datetime <=> obj.datetime
else
self.event <=> obj.event
end
end
|
#applies_to_pass?(pass) ⇒ Boolean
71
72
73
74
75
76
77
78
79
80
|
# File 'app/models/show.rb', line 71
def applies_to_pass?(pass)
epts = EventsPassType.active
.where(:organization_id => self.organization.id)
.where(:event_id => self.event.id)
.where(:pass_type_id => pass.pass_type.id).first
return false if epts.blank?
return !epts.excluded_shows.include?(self.id)
end
|
#as_json(options = {}) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
|
# File 'app/models/show.rb', line 179
def as_json(options={})
{ "id" => id,
"uuid" => uuid,
"chart_id" => chart.id,
"state" => state,
"show_time" => show_time,
"datetime" => datetime_local_to_event,
"destroyable" => destroyable?,
"chart" => chart_for("storefront", options[:organization_id]).as_json(options)
}
end
|
For a single show being displayed in the widget
194
195
196
197
198
|
# File 'app/models/show.rb', line 194
def as_widget_json(options = {})
as_json.merge(:event => event.as_json,
:venue => event.venue.as_json,
:chart => chart_for("storefront", options[:organization_id]).as_json(options))
end
|
#bulk_change_price(ids, price) ⇒ Object
214
215
216
|
# File 'app/models/show.rb', line 214
def bulk_change_price(ids, price)
tickets.where(:id => ids).collect{ |ticket| ticket.id if ticket.change_price(price) }.compact
end
|
#bulk_delete(ids) ⇒ Object
210
211
212
|
# File 'app/models/show.rb', line 210
def bulk_delete(ids)
tickets.where(:id => ids).collect{ |ticket| ticket.id if ticket.destroy }end
|
#bulk_off_sale(ids) ⇒ Object
205
206
207
208
|
# File 'app/models/show.rb', line 205
def bulk_off_sale(ids)
targets = (ids == :all) ? tickets : tickets.where(:id => ids)
Ticket.take_off_sale(targets)
end
|
#bulk_on_sale(ids) ⇒ Object
200
201
202
203
|
# File 'app/models/show.rb', line 200
def bulk_on_sale(ids)
targets = (ids == :all) ? tickets : tickets.where(:id => ids)
Ticket.put_on_sale(targets)
end
|
#compable_tickets ⇒ Object
267
268
269
|
# File 'app/models/show.rb', line 267
def compable_tickets
tickets.select(&:compable?)
end
|
#create_and_on_sale_tickets ⇒ Object
113
114
115
116
|
# File 'app/models/show.rb', line 113
def create_and_on_sale_tickets
create_tickets
bulk_on_sale(:all)
end
|
#delayed_destroy ⇒ Object
241
242
243
244
245
|
# File 'app/models/show.rb', line 241
def delayed_destroy
return false unless destroyable?
Delayed::Job.enqueue(DestroyShowJob.new(self))
true
end
|
#destroyable? ⇒ Boolean
Horribly inefficient. Don’t use with a list of shows.
237
238
239
|
# File 'app/models/show.rb', line 237
def destroyable?
(tickets_comped + tickets_sold).empty? && items.empty?
end
|
#destroyable_tickets ⇒ Object
263
264
265
|
# File 'app/models/show.rb', line 263
def destroyable_tickets
tickets.select(&:destroyable?)
end
|
#dup! ⇒ Object
167
168
169
170
171
172
173
|
# File 'app/models/show.rb', line 167
def dup!
copy = Show.new(self.attributes.reject { |key, value| key == 'id' || key == 'uuid' || key == 'state' })
copy.event = self.event
copy.datetime = copy.datetime + 1.day
copy.chart = self.chart.dup!
copy
end
|
#event_deleted? ⇒ Boolean
126
127
128
|
# File 'app/models/show.rb', line 126
def event_deleted?
!unscoped_event.deleted_at.nil?
end
|
#go!(and_publish = true) ⇒ Object
wraps build, publish (or unpublish), and save
62
63
64
65
66
67
68
69
|
# File 'app/models/show.rb', line 62
def go!(and_publish = true)
return false if !valid?
transaction do
build!
and_publish ? publish! : unpublish!
save
end
end
|
#gross_potential ⇒ Object
130
131
132
|
# File 'app/models/show.rb', line 130
def gross_potential
@gross_potential ||= tickets.inject(0) { |sum, ticket| sum += ticket.price.to_i }
end
|
#gross_sales ⇒ Object
134
135
136
|
# File 'app/models/show.rb', line 134
def gross_sales
@gross_sales ||= tickets_sold.inject(0) { |sum, ticket| sum += ticket.price.to_i }
end
|
#has_door_list? ⇒ Boolean
158
159
160
|
# File 'app/models/show.rb', line 158
def has_door_list?
published? or unpublished?
end
|
#imported? ⇒ Boolean
122
123
124
|
# File 'app/models/show.rb', line 122
def imported?
unscoped_event.imported?
end
|
#live? ⇒ Boolean
247
248
249
|
# File 'app/models/show.rb', line 247
def live?
(tickets_comped + tickets_sold).any?
end
|
#load(attrs) ⇒ Object
162
163
164
165
|
# File 'app/models/show.rb', line 162
def load(attrs)
super(attrs)
set_attributes(attrs)
end
|
#off_saleable_tickets ⇒ Object
259
260
261
|
# File 'app/models/show.rb', line 259
def off_saleable_tickets
tickets.select(&:off_saleable?)
end
|
#on_saleable_tickets ⇒ Object
255
256
257
|
# File 'app/models/show.rb', line 255
def on_saleable_tickets
tickets.select(&:on_saleable?)
end
|
#parsed_local_datetime ⇒ Object
109
110
111
|
# File 'app/models/show.rb', line 109
def parsed_local_datetime
@parsed_local_datetime = (DateTime.parse(self.local_datetime) rescue self.datetime_local_to_event)
end
|
#played? ⇒ Boolean
251
252
253
|
# File 'app/models/show.rb', line 251
def played?
datetime < Time.now
end
|
#refresh_stats ⇒ Object
Run synchronously only with great care.
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/models/show.rb', line 85
def refresh_stats
tickets.reload
self.local_datetime = self.datetime_local_to_event.to_s unless self.event.nil?
self.capacity = self.glance.available.capacity
self.on_sale = self.glance.available.on_sale
self.off_sale = self.glance.available.off_sale
self.sold = self.glance.sold.total
self.comped = self.glance.comped.total
self.open = self.glance.available.open
unless self.event.time_zone.nil?
self.offset = ActiveSupport::TimeZone.create(self.event.time_zone).parse(self.local_datetime).formatted_offset
end
self.time_zone = self.event.time_zone
self.iana_time_zone = ActiveSupport::TimeZone::MAPPING[self.event.time_zone]
self.save(:validate => false)
self.event.delay.refresh_stats
self.cached_stats
end
|
#reseller_settleables ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
|
# File 'app/models/show.rb', line 222
def reseller_settleables
settleables = {}
items.includes(:reseller_order).select(&:reseller_order).reject(&:modified?).each do |item|
reseller = item.reseller_order.organization
settleables[reseller] ||= []
settleables[reseller] << item
end
settleables
end
|
#reseller_sold_count ⇒ Object
285
286
287
|
# File 'app/models/show.rb', line 285
def reseller_sold_count
self.ticket_offers.inject(0) { |sum, to| sum + to.sold }
end
|
#sections_for(member) ⇒ Object
271
272
273
|
# File 'app/models/show.rb', line 271
def sections_for(member)
member.nil? ? self.chart.sections.storefront : self.chart.sections.members
end
|
#settleables ⇒ Object
218
219
220
|
# File 'app/models/show.rb', line 218
def settleables
items.reject(&:modified?)
end
|
#show_time ⇒ Object
175
176
177
|
# File 'app/models/show.rb', line 175
def show_time
I18n.l(datetime_local_to_event, :format => :long_with_day)
end
|
#tickets_comped ⇒ Object
142
143
144
|
# File 'app/models/show.rb', line 142
def tickets_comped
@tickets_comped ||= tickets.select { |ticket| ticket.comped? }
end
|
#tickets_sold ⇒ Object
138
139
140
|
# File 'app/models/show.rb', line 138
def tickets_sold
@tickets_sold ||= tickets.select { |ticket| ticket.sold? }
end
|
#tickets_validated ⇒ Object
146
147
148
|
# File 'app/models/show.rb', line 146
def tickets_validated
tickets.where(:validated => true).count
end
|
#to_s ⇒ Object
150
151
152
|
# File 'app/models/show.rb', line 150
def to_s
show_time
end
|
#unscoped_event ⇒ Object
118
119
120
|
# File 'app/models/show.rb', line 118
def unscoped_event
::Event.unscoped.find(event_id)
end
|
#update_ticket_types ⇒ Object
We can’t do this until the show is saved, obviously
292
293
294
|
# File 'app/models/show.rb', line 292
def update_ticket_types
TicketType.set_show(self)
end
|