From 2e4a7bc482f7dcdd69227d3d8d8930f714f7bb3d Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 27 Feb 2017 18:19:21 +0000 Subject: [PATCH] Allow filtering by solved or unsolved --- plugin.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plugin.rb b/plugin.rb index 65dd583..845b660 100644 --- a/plugin.rb +++ b/plugin.rb @@ -337,6 +337,27 @@ SQL end end + require_dependency 'topic_query' + + TopicQuery.add_custom_filter(:solved) do |results, topic_query| + if topic_query.options[:solved] == 'true' + results = results.where("topics.id IN ( + SELECT tc.topic_id + FROM topic_custom_fields tc + WHERE tc.name = 'accepted_answer_post_id' AND + tc.value IS NOT NULL + )") + elsif topic_query.options[:solved] == 'false' + results = results.where("topics.id NOT IN ( + SELECT tc.topic_id + FROM topic_custom_fields tc + WHERE tc.name = 'accepted_answer_post_id' AND + tc.value IS NOT NULL + )") + end + results + end + require_dependency 'topic_list_item_serializer' class ::TopicListItemSerializer