Class: Effective::Event
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Event
- Includes:
- PgSearch::Model
- Defined in:
- app/models/effective/event.rb
Instance Method Summary collapse
- #any_waitlist? ⇒ Boolean
- #body ⇒ Object
-
#capacity_available(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration.
-
#capacity_selectable(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration.
-
#capacity_taken(event_ticket:, event_registration: nil) ⇒ Object
Just used in tests so far.
- #closed? ⇒ Boolean
- #delayed? ⇒ Boolean
- #delayed_payment_date_upcoming? ⇒ Boolean
-
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception.
- #duplicate! ⇒ Object
- #early_bird? ⇒ Boolean
- #early_bird_past? ⇒ Boolean
- #early_bird_status ⇒ Object
-
#event_product_available?(event_product, quantity:) ⇒ Boolean
Can I register/purchase this many new event products?.
-
#event_ticket_available?(event_ticket, except: nil, quantity: 0) ⇒ Boolean
Can I register/purchase this many new event tickets?.
- #excerpt ⇒ Object
-
#registerable? ⇒ Boolean
No longer includes sold_out? we check that separately.
- #sold_out?(except: nil) ⇒ Boolean
- #start_time ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#any_waitlist? ⇒ Boolean
192 193 194 |
# File 'app/models/effective/event.rb', line 192 def any_waitlist? event_tickets.any? { |et| et.waitlist? } end |
#body ⇒ Object
184 185 186 |
# File 'app/models/effective/event.rb', line 184 def body rich_text_body end |
#capacity_available(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration
268 269 270 |
# File 'app/models/effective/event.rb', line 268 def capacity_available(event_ticket:, event_registration: nil) event_ticket.capacity_available(except: event_registration) end |
#capacity_selectable(event_ticket:, event_registration: nil) ⇒ Object
The amount of tickets that can be purchased except ones from an event registration
259 260 261 262 263 264 265 |
# File 'app/models/effective/event.rb', line 259 def capacity_selectable(event_ticket:, event_registration: nil) return 0 if event_ticket.archived? return 100 if event_ticket.capacity.blank? return 100 if event_ticket.waitlist? event_ticket.capacity_selectable(except: event_registration) end |
#capacity_taken(event_ticket:, event_registration: nil) ⇒ Object
Just used in tests so far
273 274 275 |
# File 'app/models/effective/event.rb', line 273 def capacity_taken(event_ticket:, event_registration: nil) event_ticket.capacity_taken(except: event_registration) end |
#closed? ⇒ Boolean
203 204 205 206 |
# File 'app/models/effective/event.rb', line 203 def closed? return false if registration_end_at.blank? registration_end_at < Time.zone.now end |
#delayed? ⇒ Boolean
306 307 308 |
# File 'app/models/effective/event.rb', line 306 def delayed? delayed_payment? && delayed_payment_date.present? end |
#delayed_payment_date_upcoming? ⇒ Boolean
310 311 312 313 |
# File 'app/models/effective/event.rb', line 310 def delayed_payment_date_upcoming? return false unless delayed? delayed_payment_date > Time.zone.now.to_date end |
#duplicate ⇒ Object
Returns a duplicated event object, or throws an exception
238 239 240 241 242 243 244 245 246 247 248 |
# File 'app/models/effective/event.rb', line 238 def duplicate Event.new(attributes.except('id', 'updated_at', 'created_at')).tap do |event| event.title = event.title + ' (Copy)' event.slug = event.slug + '-copy' event.rich_text_body = rich_text_body event.rich_text_excerpt = rich_text_excerpt event.assign_attributes(published_start_at: nil, published_end_at: nil) end end |
#duplicate! ⇒ Object
250 251 252 |
# File 'app/models/effective/event.rb', line 250 def duplicate! duplicate.tap { |event| event.save! } end |
#early_bird? ⇒ Boolean
217 218 219 220 |
# File 'app/models/effective/event.rb', line 217 def early_bird? return false if early_bird_end_at.blank? early_bird_end_at > Time.zone.now end |
#early_bird_past? ⇒ Boolean
222 223 224 225 |
# File 'app/models/effective/event.rb', line 222 def early_bird_past? return false if early_bird_end_at.blank? early_bird_end_at <= Time.zone.now end |
#early_bird_status ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'app/models/effective/event.rb', line 227 def early_bird_status if early_bird? 'Early Bird Pricing' elsif early_bird_past? 'Expired' else 'None' end end |
#event_product_available?(event_product, quantity:) ⇒ Boolean
Can I register/purchase this many new event products?
292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'app/models/effective/event.rb', line 292 def event_product_available?(event_product, quantity:) raise('expected an EventProduct') unless event_product.kind_of?(Effective::EventProduct) raise('expected quantity to be greater than 0') unless quantity.to_i > 0 return false if event_product.archived? return true if event_product.capacity.blank? # No capacity enforced for this product # Total number already sold registered = registered_event_addons.count { |r| r.event_product_id == event_product.id } # If there's capacity for this many more (registered + quantity) <= event_product.capacity end |
#event_ticket_available?(event_ticket, except: nil, quantity: 0) ⇒ Boolean
Can I register/purchase this many new event tickets?
278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'app/models/effective/event.rb', line 278 def event_ticket_available?(event_ticket, except: nil, quantity: 0) raise('expected an EventTicket') unless event_ticket.kind_of?(Effective::EventTicket) raise('expected except to be an EventRegistration') if except && !except.class.try(:effective_events_event_registration?) raise('expected quantity to be greater than 0') unless quantity.to_i > 0 return false if event_ticket.archived? return true if event_ticket.capacity.blank? # No capacity enforced return true if event_ticket.waitlist? # Always available for waitlist # Do we have any tickets available left? event_ticket.capacity_available(except: except) >= quantity.to_i end |
#excerpt ⇒ Object
188 189 190 |
# File 'app/models/effective/event.rb', line 188 def excerpt rich_text_excerpt end |
#registerable? ⇒ Boolean
No longer includes sold_out? we check that separately
197 198 199 200 201 |
# File 'app/models/effective/event.rb', line 197 def registerable? return false unless published? return false if closed? (external_registration? && external_registration_url.present?) || event_tickets.present? end |
#sold_out?(except: nil) ⇒ Boolean
208 209 210 211 212 213 214 215 |
# File 'app/models/effective/event.rb', line 208 def sold_out?(except: nil) raise('expected except to be an EventRegistration') if except && !except.class.try(:effective_events_event_registration?) return false unless event_tickets.present? return false if any_waitlist? event_tickets.none? { |event_ticket| event_ticket_available?(event_ticket, except: except, quantity: 1) } end |
#start_time ⇒ Object
254 255 256 |
# File 'app/models/effective/event.rb', line 254 def start_time start_at end |
#to_s ⇒ Object
180 181 182 |
# File 'app/models/effective/event.rb', line 180 def to_s title.presence || model_name.human end |