app/models/event.rb in artfully_ose-1.2.0 vs app/models/event.rb in artfully_ose-1.3.0.pre1
- old
+ new
@@ -2,18 +2,18 @@
include Ext::Integrations::Event
include Ext::Resellable::Event
include Ext::Uuid
include Ticket::Reporting
include EventPresenter
+ include OhNoes::Destroy
require 'email_validator'
CATEGORIES = ["Dance", "Film & Electronic Media", "Literary Arts", "Music", "Theater", "Visual Arts", "Other"]
attr_accessible :name, :producer, :description, :contact_email, :contact_phone, :image, :venue_attributes,
:show_special_instructions, :special_instructions_caption, :public, :primary_category,
- :secondary_categories, :primary_category_other, :secondary_category_other, :members_only,
- :subtitle
+ :secondary_categories, :primary_category_other, :secondary_category_other, :members_only, :subtitle
store :cached_stats, :accessors => [ :on_sale, :off_sale, :sold, :sales_total ]
belongs_to :organization
belongs_to :venue
@@ -51,12 +51,14 @@
after_create :create_default_chart
serialize :secondary_categories, Array
default_scope where(:deleted_at => nil).order("events.created_at DESC")
+ scope :storefront, where(:deleted_at => nil).where(:public => true)
scope :published, includes(:shows).where(:shows => { :state => "published" })
scope :public, where(:public => true)
+ scope :not_deleted, where('deleted_at IS NULL')
delegate :time_zone, :to => :venue
ANY_EVENT_TEXT = "(Any Event)"
ANY_EVENT_ID = "-1"
@@ -95,27 +97,31 @@
end
def artfully_ticketed
true
end
-
- alias :destroy! :destroy
- def destroy
- update_attribute(:deleted_at, Time.now)
- end
-
+
def single_show?
shows.length == 1
end
#
- # The list of events do be deplayed on their event index
+ # The list of events to be displayed on their event index
#
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
+ event_ids = organization.shows
+ .published
+ .joins(:event)
+ .where('datetime > ?', DateTime.now)
+ .merge(Event.storefront)
+ .reorder('datetime asc')
+ .pluck(:event_id)
+ .uniq
+ events = []
+ event_ids.each {|id| events << Event.includes(:venue).find(id)}
+ events.reject!{|e| e.members_only} if member.nil?
+ events
end
#
# Find a single event for the single event storefront view
#
@@ -161,14 +167,20 @@
end
#
# You'll almost always want upcoming_public_shows instead
#
- def upcoming_shows(limit = 5)
+ def upcoming_shows(limit = 5, reload = false)
shows_rel = upcoming_shows_rel
shows_rel = upcoming_shows_rel.limit(limit) unless limit == :all
- @upcoming ||= shows_rel.all
+
+ if reload
+ @upcoming = shows_rel.all
+ else
+ @upcoming ||= shows_rel.all
+ end
+
@upcoming
end
def played_shows(limit = 5)
played = shows.select { |show| show.datetime_local_to_event < (DateTime.now - 1.hours) }
@@ -178,11 +190,15 @@
def next_public_show
upcoming_public_shows.empty? ? nil : upcoming_public_shows.first
end
+ def next_show_include_unpublished
+ upcoming_shows.empty? ? nil : upcoming_shows.first
+ end
+
def upcoming_public_shows
- upcoming_shows(:all).select(&:published?)
+ upcoming_shows(:all, true).select(&:published?)
end
def next_show
shows.build(:datetime => Show.next_datetime(shows.last))
show = shows.pop