FEATURE: accepted solutions admin report

This commit is contained in:
Régis Hanol 2015-06-25 02:41:24 +02:00
parent 8011731aa0
commit e321c12ff7
2 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,8 @@
en:
site_settings:
allow_solved_on_all_topics: "Allow users to select solutions on all topics (by default you control this by editing categories)"
reports:
accepted_solutions:
title: "Accepted solutions"
xaxis: "Day"
yaxis: "Total"

View File

@ -90,6 +90,28 @@ after_initialize do
["is_accepted_answer"]
end
if Report.respond_to?(:add_report)
AdminDashboardData::GLOBAL_REPORTS << "accepted_solutions"
Report.add_report("accepted_solutions") do |report|
report.data = []
accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id")
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id = ?", report.category_id) if report.category_id
accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date)
.where("topic_custom_fields.created_at <= ?", report.end_date)
.group("DATE(topic_custom_fields.created_at)")
.order("DATE(topic_custom_fields.created_at)")
.count
.each do |date, count|
report.data << { x: date, y: count }
end
report.total = accepted_solutions.count
report.prev30Days = accepted_solutions.where("topic_custom_fields.created_at >= ?", report.start_date - 30.days)
.where("topic_custom_fields.created_at <= ?", report.start_date)
.count
end
end
require_dependency 'topic_view_serializer'
class ::TopicViewSerializer
attributes :accepted_answer