Class: ManifestationCheckoutStat

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.per_pageObject



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

def self.per_page
  10
end

Instance Method Details

#calculate_countObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/manifestation_checkout_stat.rb', line 18

def calculate_count
  self.started_at = Time.zone.now
  Manifestation.find_each do |manifestation|
    daily_count = Checkout.manifestations_count(self.start_date, self.end_date, 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, self.id, manifestation.id]
      ActiveRecord::Base.connection.execute(
        self.class.send(:sanitize_sql_array, sql)
      )
    end
  end
  self.completed_at = Time.zone.now
end