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

QnA - Best Answer

This discussion is related to the Q&A addon.

Is there a way to disable the "Best Answer" at the top feature.

We are finding that this seriously hampers our support forum as the "Best Answer" is removed from the normal discussion flow and ends up "lost" at the top.

Best, of course, would be to have a Best Answer at the top, but retain the comment in the normal flow.

Comments

  • hgtonighthgtonight ∞ · New Moderator

    You can modify your own copy of the plugin. In /plugins/QnA/class.qna.plugin.php find the DiscussionController_BeforeDiscussionRender_Handler function definition. Comment out the following lines:

    // Remove the accepted answers from the comments.
    if (isset($Sender->Data['Comments'])) {
       $Comments = $Sender->Data['Comments']->Result();
       $Comments = array_filter($Comments, function($Row) {
          return strcasecmp(GetValue('QnA', $Row), 'accepted');
       });
       $Sender->Data['Comments'] = new Gdn_DataSet(array_values($Comments));
    }
    

    That should do what you want.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

    BleistivtMakke375
  • AdrianAdrian Wandering Spirit Montreal Vanilla Staff
    edited June 2015

    @weavertheme we actually made this an option in config (recent modification)

    I have updated the plugin found in the Add-on repo. You can now just add to config.php

    QnA.AcceptedAnswers.Filter = FALSE

    Sorry I did not see this sooner.

    Update

    As mentioned below here is proper syntax
    ['QnA']['AcceptedAnswers']['Filter'] = FALSE;`

    hgtonightBleistivt
  • hgtonighthgtonight ∞ · New Moderator

    @Adrian said:
    weavertheme we actually made this an option in config (recent modification)

    I have updated the plugin found in the Add-on repo. You can now just add to config.php

    QnA.AcceptedAnswers.Filter = FALSE

    Sorry I did not see this sooner.

    Good to know my patch was identical:)

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • AdrianAdrian Wandering Spirit Montreal Vanilla Staff
    edited January 2015

    @hgtonight I would not doubt it ;) I think you have a good handle on things :D

  • I think you meant:
    $Configuration['Plugins']['QnA']['AcceptedAnswers']['Filter'] = TRUE;

    but that doesn't work when I try it. If I change the new code in class.qna.plugins.php to test for FALSE, it works, but then the config setting seems irrelevant.

    And if you have to fix this, then how about another on to skip the "Best Answer" display, too. My moderators really don't like that. I simply put a return; at the beginning of the DiscussionController_BeforeDiscussionRender_Handler
    function, but that may be breaking the Read/New Comments functionality - don't know for sure.

  • AdrianAdrian Wandering Spirit Montreal Vanilla Staff

    @weavertheme sorry, I had just noticed I had improper syntax, the post above has been fixed.

  • I'm using Vanilla 2.2.1

    I've tried putting this in config.php to have the Best Answer within the conversation flow, and not on the top:
    $Configuration['Plugins']['QnA']['AcceptedAnswers']['Filter'] = FALSE;
    It doesn't change anything.
    $Configuration['Plugins']['QnA']['AcceptedAnswers']['Filter'] = TRUE; didn't make a difference too.

    If i comment out the above mentioned block like this, it does work (Best answers on top, but ALL answers in the conversation flow)

                  // Remove the accepted answers from the comments.
                  // Allow this to be skipped via config.
                  /* if (C('QnA.AcceptedAnswers.Filter', TRUE)) {
                     if (isset($Sender->Data['Comments'])) {
                        $Comments = $Sender->Data['Comments']->Result();
                        $Comments = array_filter($Comments, function($Row) {
                           return strcasecmp(GetValue('QnA', $Row), 'accepted');
                        });
                        $Sender->Data['Comments'] = new Gdn_DataSet(array_values($Comments));
                     }
                  } */
    

    Best regards

  • If you replace $Configuration['Plugins']['QnA']['AcceptedAnswers']['Filter'] =false; with $Configuration['QnA']['AcceptedAnswers']['Filter'] = false; or if (C('QnA.AcceptedAnswers.Filter', TRUE)) with if (C('Plugins.QnA.AcceptedAnswers.Filter', TRUE)) it would work too.

  • Awesome.
    $Configuration['QnA']['AcceptedAnswers']['Filter'] = FALSE; works!
    Thanks!

    Vanillaplus
  • Glad it worked out!

    Just for future reference: If you see c("X.Y.Z" , 'some default value') somewhere, that's basically a shorthand for "check if $Configuration['X']['Y']['Z'] is set, if yes return it if not return 'some default value'".

    R_J
  • Thanks!

    I've already figured out the correlation between the config.php entry and the code c("X.Y.Z",'some default value').

    Best Regards

    Caylus
  • also comment out this line //$sender->setData('Answers', $answers);

Sign In or Register to comment.