Class: ManifestationCheckoutStat

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CalculateStat, Statesman::Adapters::ActiveRecordQueries
Defined in:
app/models/manifestation_checkout_stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



11
12
13
# File 'app/models/manifestation_checkout_stat.rb', line 11

def mode
  @mode
end

Instance Method Details

#calculate_count!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/manifestation_checkout_stat.rb', line 22

def calculate_count!
  self.started_at = Time.zone.now
  Manifestation.find_each do |manifestation|
    daily_count = Checkout.manifestations_count(start_date.beginning_of_day, end_date.tomorrow.beginning_of_day, manifestation)
    #manifestation.update_attributes({daily_checkouts_count: daily_count, total_count: manifestation.total_count + daily_count})
    if daily_count > 0
      self.manifestations << manifestation
      sql = ['UPDATE checkout_stat_has_manifestations SET checkouts_count = ? WHERE manifestation_checkout_stat_id = ? AND manifestation_id = ?', daily_count, id, manifestation.id]
      ManifestationCheckoutStat.connection.execute(
        self.class.send(:sanitize_sql_array, sql)
      )
    end
  end
  self.completed_at = Time.zone.now
  transition_to!(:completed)
  send_message
end

#state_machineObject



15
16
17
# File 'app/models/manifestation_checkout_stat.rb', line 15

def state_machine
  ManifestationCheckoutStatStateMachine.new(self, transition_class: ManifestationCheckoutStatTransition)
end