Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
934 views
in Q2A Core by
hi

 

i want block users to select their own answer as best. how can i do that ?

2 Answers

0 votes
by

answering myself:

in qa-theme-base.php comment out: 

elseif (isset($post['unselect_tags']))
                $this->post_hover_button($post, 'unselect_tags', '', 'qa-a-unselect');

This does not set the <input> and the user cannot unselect the best answer...

---

Thing that is missing: check if ADMIN to allow him the unselect...

5 min later... got it :)

            elseif ( isset($post['unselect_tags']) && (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) )
                $this->post_hover_button($post, 'unselect_tags', '', 'qa-a-unselect');

 

 

#Reference : http://www.question2answer.org/qa/20373/best-way-to-disable-the-option-remove-selected-answer

Thanks

by
this is to block  to remove unselect . I want to block people to select their answers as best answer.
+2 votes
by

It is impossible to do this without a corehack.

1. Locate function qa_question_set_selchildid in file qa-app-post-update.php

2. Locate this line inside that function:

$oldselchildid=$oldquestion['selchildid'];

3. Immediately BEFORE add the following code:

// CORE HACK: Prevent users to select own answers
if ($answers[$selchildid]['userid'] == $oldquestion['userid']) {
  return;
}
 
4. Play around your site and try to select an answer posted by the question creator. You shouldn't.
 
5. In order to make the select mark go away, go to /qa-theme/<your-theme>/qa-theme.php
 
6. Locate the doctype() function
 
6.1 If it is not there add this function to the file the same as any other function there:
function doctype() {
  qa_html_theme_base::doctype();
  if ($this->template === 'question' &&
      isset(
        $this->content['q_view']['raw']['userid'],
        $this->content['a_list']['as']
      ) && !empty($this->content['q_view']['raw']['userid'])
    ) {
    $questionCreator = $this->content['q_view']['raw']['userid'];
    $answerList = $this->content['a_list']['as'];
    foreach ($answerList as $index => $answer) {
      if (isset($answer['raw']['userid']) &&
          $answer['raw']['userid'] == $questionCreator
      ) {
        unset(
          $this->content['a_list']['as'][$index]['select_tags'],
          $this->content['a_list']['as'][$index]['select_text']
        );
      }
    }
  }
}
 
6.2 If it is, there take the code from 6.1 and everything between qa_html_theme_base::doctype(); and the last } (excluding both of those lines) and add that immediately after the function doctype() { in your already existing function
 
7. Enjoy

 

by
hi,
i correct this code to work that user cant select own answer as best answer(not question maker):
if ($answers[$selchildid]['userid'] == $userid) {
  return;
}

but in qa-theme.php your code is not working! besta answer button is still there! can you fix it?
by
Your correction to my code is not correct :) Leave it as it was (admins can select best answers too!).

Regarding qa-theme.php it is working for me. If you happen to be using some kind of plugin or theme that is interfering with the solution proposed, then remember you can always use CSS to hide it. The MOST important thing here is step 3 which will not allow you to set the answers in the system. So the rest (the UI) you can handle it the way you want
...