FEATURE: Add include_subcategories report filter

Follow up to dafb1d7c7f.
This commit is contained in:
Dan Ungureanu 2020-04-24 13:16:15 +03:00
parent dafb1d7c7f
commit dc87d34594
No known key found for this signature in database
GPG Key ID: 0AA2A00D6ACC8B84
1 changed files with 6 additions and 9 deletions

View File

@ -313,15 +313,12 @@ SQL
accepted_solutions = TopicCustomField.where(name: "accepted_answer_post_id")
if report.respond_to?(:add_filter)
category_filter = report.filters.dig(:category)
report.add_filter('category', default: category_filter)
if category_filter
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(category_filter.to_i))
end
category_id, include_subcategories = report.add_category_filter
if category_id
if include_subcategories
accepted_solutions = accepted_solutions.joins(:topic).where('topics.category_id IN (?)', Category.subcategory_ids(category_id))
else
if report.category_id
accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(report.category_id.to_i))
accepted_solutions = accepted_solutions.joins(:topic).where('topics.category_id = ?', category_id)
end
end