Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

How to allow only author to answer his own question? Thanks for your help.

+3 votes
220 views
asked May 8, 2017 in Q2A Core by john123

Is it possible that only author of the question allowed to answer his own question? All other users can comment on the answers but can not post answers.

1. Author can create question
2. Author can answer his own question
3. Other users can not answer but only can comment on answers.

I tried with permissions, but it enables answers for all users OR disables answers for all users.

Thanks for your help.

Q2A version: Latest

3 Answers

+1 vote
answered May 9, 2017 by MONKEY
Admin/
When you enter permissions you enable the padlocked  and the option to answer your own preguntas.luego to answer the question padlocked
commented May 9, 2017 by john123
Hi Monkey !  I understand what you mean.
Author closes the question, no one can answer it and can make comments on answer.

Which is great. However if author opens the question to add additional answers, it opens for everyone to add answers as well.
commented May 9, 2017 by MONKEY
Well those who respond clarifies that for now is only your update that please do not do if they do is simple because you can hide them
commented May 9, 2017 by john123
Thanks for your reply.

Other option would be to hide answer button for other users. Only author of the question can view answer button.  Other users can only view comment button.
+1 vote
answered May 9, 2017 by ProThoughts
This dissolves purpose of QA platform. It is possible to do this, you need to do modifications in core or come up with plugin.
commented May 9, 2017 by john123
Hi ProThoughts ! Thanks for your reply. Purpose of this is to allow experts to raise question and answer their own question to educate others. Others can make comments on expert provided answer but can not answer the question. Its like community of teachers.
commented May 9, 2017 by ProThoughts
Got it. quick solution can be blog plugin but whatever I tested had issues. check with arjunsuresh if he has working blog plugin.
commented May 9, 2017 by john123
ProThoughts !

Blog plugin does not have extended functionality of q2a.  It only allows comments not answers. It would be like blog post but not question - answer type of discussions.

I want only author (teacher)  to be able to add answers, not other users. is it possible to override answer button visibility?

What i  mean is only author of the question can view answer button, other users can not see answer button at all, but only comment button.
+3 votes
answered May 9, 2017 by sama55
edited May 11, 2017 by sama55
  1. Create your layer plugin.
  2. Replace "c_list" function inner layer plugin with "q_view_buttons" function below.

public function q_view_buttons($q_view) {
    if(qa_get_logged_in_level() < QA_USER_LEVEL_MODERATOR​) {
        if(isset($q_view['form']['buttons']['answer'])) {
            if(qa_is_logged_in() && $q_view['raw']['handle'] != qa_get_logged_in_handle()
            ||(!qa_is_logged_in() && $q_view['who']['data'] != qa_lang_html('main/me'))) {
                unset($q_view['form']['buttons']['answer']);
            }
        }
    }
    qa_html_theme_base::q_view_buttons($q_view);
}

commented May 9, 2017 by john123
Hi Sama55,

Thanks for your help.

I was able to follow your instructions to create layer plugin. It displays counts as it should.

Where do i add or replace following code with to hide buttons for other users than author ?

Here is current code

class qa_html_theme_layer extends qa_html_theme_base {
    public function c_list($c_list, $class) {
        if (!empty($c_list) && count($c_list['cs'])) {
            $title = qa_lang_html_sub(count($c_list['cs'])==1 ? 'main/1_comment' : 'main/x_comments', count($c_list['cs']));
            $this->part_title(array('title' => $title, 'title_tags' => 'class="c_list_title"'));
        }
        qa_html_theme_base::c_list($c_list, $class);
    }
}


--- Where should i put following code?


public function q_view_buttons($q_view) {
    if(isset($q_view['form']['buttons']['answer'])) {
        if(qa_is_logged_in() && $q_view['raw']['handle'] != qa_get_logged_in_handle()
        ||(!qa_is_logged_in() && $q_view['who']['data'] != qa_lang_html('main/me'))) {
            unset($q_view['form']['buttons']['answer']);
        }
    }
    qa_html_theme_base::q_view_buttons($q_view);
}


Thanks for your help.
commented May 9, 2017 by john123
Hi sama55,

Never mind.  It worked perfectly. I replace the code and it works great. Just space was missing and it was giving me an error.

But now its great. It works. :) Thank you so much for your help @sama55.
commented May 9, 2017 by sama55
You are welcome.
commented May 10, 2017 by ProThoughts
@sama55, nice solution thanks!

@john123, writing plugin helps you to enable disable this functionality. If you want permanent change then you can also just copy and paste function written by sama55 in qa-theme/snow/qa-theme.php file.
commented May 11, 2017 by john123
@sama55,

Layer plugin works great when hiding answers button from other users, however it also hides the answer button from admin as well.

Is there any way to allow question author and admin to view answer button on every question?

Thanks for your help.
commented May 11, 2017 by sama55
I changed code above. You can change user level (QA_USER_LEVEL_MODERATOR) along list below.
define('QA_USER_LEVEL_APPROVED', 10);
define('QA_USER_LEVEL_EXPERT', 20);
define('QA_USER_LEVEL_EDITOR', 50);
define('QA_USER_LEVEL_MODERATOR', 80); // <== Now level
define('QA_USER_LEVEL_ADMIN', 100);
define('QA_USER_LEVEL_SUPER', 120);
commented May 12, 2017 by john123
@sama55,

Thank you for updated code. It works great. Now admin can view answer button on all questions and other registered users can see answer button on their own question only.

Great insights. Thank you so much for taking the time to update the code.
...