From dc87d34594ebe534b0fd0ef9240194c37d06ce21 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 24 Apr 2020 13:16:15 +0300 Subject: [PATCH] FEATURE: Add include_subcategories report filter Follow up to dafb1d7c7fcc50ffe37285996a04c42509ccd768. --- plugin.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/plugin.rb b/plugin.rb index 452195f..861a9ac 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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 - else - if report.category_id - accepted_solutions = accepted_solutions.joins(:topic).where("topics.category_id IN (?)", Category.subcategory_ids(report.category_id.to_i)) + 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 + accepted_solutions = accepted_solutions.joins(:topic).where('topics.category_id = ?', category_id) end end