Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Q&A's unanswered view incorrectly shows announcements and has a bad pager. Patch attached.

bfcambfcam New
edited June 2015 in Vanilla 2.0 - 2.8

In the /discussions/unanswered view of questions currently unanswered, there are two problems.

  1. This view shows regular discussions that are marked as annoucements.
  2. The pager uses the count of all discussions (whether questions or not) instead of the count of questions. So the pager will tend to show a bunch of empty pages.

I've attached my fix for these problems. The way I've worked around these problems isn't great. The main issue is that there isn't enough event hooks to setup things up properly before the queries fire.

Tested lightly.

--- class.qna.plugin.php
+++ class.qna.plugin.php
@@ -791,7 +791,7 @@

         if ($Unanswered) {
           $Args['Wheres']['Type'] = 'Question';
-          $Sender->SQL->WhereIn('d.QnA', array('Unanswered', 'Rejected'));
+          $Args['Wheres']['QnA'] = array('Unanswered', 'Rejected');
           Gdn::Controller()->Title('Unanswered Questions');
         } elseif ($QnA = Gdn::Request()->Get('qna')) {
           $Args['Wheres']['QnA'] = $QnA;
@@ -798,6 +798,33 @@
         }
       }

+    public function DiscussionModel_AfterAddColumns_Handler($Sender, $Args) {
+        $Unanswered = Gdn::Controller()->ClassName == 'DiscussionsController' && Gdn::Controller()->RequestMethod == 'unanswered';
+
+        if ($Unanswered || Gdn::Request()->Get('qna')) {
+            $Data = $Args['Data'];
+            $Sender->RemoveAnnouncements($Data);
+        }
+    }
+
+    public function DiscussionsController_BeforeBuildPager_Handler($Sender) {
+        $Unanswered = Gdn::Controller()->ClassName == 'DiscussionsController' && Gdn::Controller()->RequestMethod == 'unanswered';
+        $Wheres = array();
+
+        if ($Unanswered) {
+            $Wheres['Type'] = 'Question';
+            $Wheres['QnA'] = array('Unanswered', 'Rejected');
+        } elseif ($QnA = Gdn::Request()->Get('qna')) {
+            $Wheres['QnA'] = $QnA;
+        }
+
+        if ($Wheres) {
+            $DiscussionModel = new DiscussionModel();
+            $CountDiscussions = $DiscussionModel->GetCount($Wheres);
+            $Sender->SetData('CountDiscussions', $CountDiscussions);
+        }
+    }
+
       /**
       *
       * @param DiscussionModel $Sender

Comments

Sign In or Register to comment.