Class: Event

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
EventPresenter, Ext::DelayedIndexing, Ext::Integrations::Event, Ext::Resellable::Event, Ext::Uuid, Ticket::Reporting
Defined in:
app/models/event.rb

Direct Known Subclasses

TempDiscount

Constant Summary collapse

CATEGORIES =
["Dance", "Film & Electronic Media", "Literary Arts", "Music", "Theater", "Visual Arts", "Other"]
ANY_EVENT_TEXT =
"(Any Event)"
ANY_EVENT_ID =
"-1"

Constants included from Ext::Uuid

Ext::Uuid::PREFIX

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ext::DelayedIndexing

included

Methods included from EventPresenter

included

Methods included from Ticket::Reporting

#glance

Methods included from Ext::Uuid

included, #set_uuid, uuid

Methods included from Ext::Integrations::Event

#shows_with_sales

Class Method Details

.for_event_storefront(organization, member = nil) ⇒ Object

The list of events do be deplayed on their event index



113
114
115
116
117
# File 'app/models/event.rb', line 113

def self.for_event_storefront(organization, member = nil)
  event_rel = organization.events.joins(:shows).where('shows.datetime > ?', DateTime.now).group(:event_id).public
  event_rel = event_rel.where(:members_only => false) if member.nil?
  event_rel.all
end

.storefront_find(id, member = nil) ⇒ Object

Find a single event for the single event storefront view



122
123
124
125
126
# File 'app/models/event.rb', line 122

def self.storefront_find(id, member = nil)
  event_rel = Event.includes(:venue)
  event_rel = event_rel.where(:members_only => false) if member.nil?
  event_rel.find(id)
end

Instance Method Details

#<=>(obj) ⇒ Object



228
229
230
231
232
# File 'app/models/event.rb', line 228

def <=>(obj)
  return -1 unless obj.kind_of? Event

  self.name.downcase <=> obj.name.downcase
end

#applies_to_pass?(pass) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
91
# File 'app/models/event.rb', line 86

def applies_to_pass?(pass)
  EventsPassType.active
                .where(:organization_id => self.organization_id)
                .where(:event_id => self.id)
                .where(:pass_type_id => pass.pass_type_id).count > 0
end

#artfully_ticketedObject



97
98
99
# File 'app/models/event.rb', line 97

def artfully_ticketed
  true
end

#as_full_calendar_jsonObject



198
199
200
201
202
203
204
205
206
207
208
# File 'app/models/event.rb', line 198

def as_full_calendar_json
  shows.includes(:event).collect do |p|
    { :title  => '',
      :start  => p.datetime_local_to_event,
      :allDay => false,
      :id     => p.id,
      :state  => p.state,
      :event_id => self.id
    }
  end
end

#as_json(options = {}) ⇒ Object



210
211
212
# File 'app/models/event.rb', line 210

def as_json(options = {})
  super(options)
end

#as_widget_json(options = {}) ⇒ Object



194
195
196
# File 'app/models/event.rb', line 194

def as_widget_json(options = {})
  as_json(options.merge({:methods => ['venue', 'uuid'], :except => [:members_only, :cached_stats]})).merge('performances' => upcoming_public_shows.as_json)
end

#assign_chart(chart) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'app/models/event.rb', line 214

def assign_chart(chart)
  if already_has_chart(chart)
    self.errors[:base] << "Chart \"#{chart.name}\" has already been added to this event"
    return self
  end

  if is_free? && chart.has_paid_sections?
    self.errors[:base] << "Cannot add chart with paid sections to a free event"
    return self
  end
  chart.assign_to(self)
  self
end

#create_default_chartObject



148
149
150
151
152
153
# File 'app/models/event.rb', line 148

def create_default_chart
  chart = self.charts.build({ :name => self.name, 
                              :is_template => false })
  chart.organization = self.organization
  chart.save
end

#default_chartObject



155
156
157
# File 'app/models/event.rb', line 155

def default_chart
  charts.first
end

#destroyObject



102
103
104
# File 'app/models/event.rb', line 102

def destroy
  update_attribute(:deleted_at, Time.now)
end

#destroy!Object



101
# File 'app/models/event.rb', line 101

alias :destroy! :destroy

#destroyable?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'app/models/event.rb', line 128

def destroyable?
  items.blank?
end

#filter_charts(charts) ⇒ Object



140
141
142
# File 'app/models/event.rb', line 140

def filter_charts(charts)
  charts.reject { |chart| already_has_chart(chart) }
end

#free?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'app/models/event.rb', line 82

def free?
  is_free?
end

#imported?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/event.rb', line 132

def imported?
  !self.import_id.nil?
end

#itemsObject



136
137
138
# File 'app/models/event.rb', line 136

def items
  Item.where(:show_id => self.shows)
end

#next_public_showObject



179
180
181
# File 'app/models/event.rb', line 179

def next_public_show
  upcoming_public_shows.empty? ? nil : upcoming_public_shows.first
end

#next_showObject



187
188
189
190
191
192
# File 'app/models/event.rb', line 187

def next_show
  shows.build(:datetime => Show.next_datetime(shows.last))
  show = shows.pop
  show.chart = default_chart.dup!
  show
end

#played_shows(limit = 5) ⇒ Object



173
174
175
176
177
# File 'app/models/event.rb', line 173

def played_shows(limit = 5)
  played = shows.select { |show| show.datetime_local_to_event < (DateTime.now - 1.hours) }
  return played if limit == :all
  played.take(limit)
end

#refresh_statsObject

Run synchronously only with great care.



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

def refresh_stats
  self.on_sale  = self.glance.available.on_sale
  self.off_sale = self.glance.available.off_sale
  self.sold     = self.glance.sold.total
  self.sales_total     = self.glance.sales.total
  self.save(:validate => false)
  self.cached_stats
end

#set_primary_categoryObject



144
145
146
# File 'app/models/event.rb', line 144

def set_primary_category
  self.primary_category ||= "Other"
end

#single_show?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'app/models/event.rb', line 106

def single_show?
  shows.length == 1
end

#to_sObject



93
94
95
# File 'app/models/event.rb', line 93

def to_s
  name
end

#upcoming_public_showsObject



183
184
185
# File 'app/models/event.rb', line 183

def upcoming_public_shows
  upcoming_shows(:all).select(&:published?)
end

#upcoming_shows(limit = 5) ⇒ Object

You’ll almost always want upcoming_public_shows instead



166
167
168
169
170
171
# File 'app/models/event.rb', line 166

def upcoming_shows(limit = 5)
  shows_rel = upcoming_shows_rel
  shows_rel = upcoming_shows_rel.limit(limit) unless limit == :all
  @upcoming ||= shows_rel.all
  @upcoming
end

#upcoming_shows_relObject



159
160
161
# File 'app/models/event.rb', line 159

def upcoming_shows_rel
  shows.includes(:event => :venue).where('shows.datetime > ?', (DateTime.now - 1.hours))
end