diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 6ce053f82..7a50f3146 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -126,9 +126,9 @@ SQL def self.count_per_day_for_type(post_action_type, opts=nil) opts ||= {} - opts[:since_days_ago] ||= 30 result = unscoped.where(post_action_type_id: post_action_type) - result = result.where('post_actions.created_at >= ?', opts[:since_days_ago].days.ago) + result = result.where('post_actions.created_at >= ?', opts[:start_date] || (opts[:since_days_ago] || 30).days.ago) + result = result.where('post_actions.created_at <= ?', opts[:end_date]) if opts[:end_date] result = result.joins(post: :topic).where('topics.category_id = ?', opts[:category_id]) if opts[:category_id] result.group('date(post_actions.created_at)') .order('date(post_actions.created_at)') diff --git a/app/models/report.rb b/app/models/report.rb index 8def047bd..1da795401 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -35,6 +35,7 @@ class Report def self.find(type, opts=nil) opts ||= {} + # Load the report report = Report.new(type) report.start_date = opts[:start_date] if opts[:start_date] @@ -184,7 +185,7 @@ class Report def self.post_action_report(report, post_action_type) report.data = [] - PostAction.count_per_day_for_type(post_action_type, category_id: report.category_id).each do |date, count| + PostAction.count_per_day_for_type(post_action_type, category_id: report.category_id, start_date: report.start_date, end_date: report.end_date).each do |date, count| report.data << { x: date, y: count } end countable = PostAction.unscoped.where(post_action_type_id: post_action_type)