Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
2.0k views
in Q2A Core by
I'd like for unanswered questions to be visible only to logged-in users, to prevent off-color/abusive content from appearing to the public. Is there any way to accomplish this?

2 Answers

+1 vote
by
Moderation will be part of the next release - that should help you with that and achieve exactly what you want! In the mean time, you could hook yourself to the event thrown when question are created and set them as hidden - only admin will then see them.

Another option for you would be to create your own theme and when outputing question list, you could ignore all those that are unswered for not logged in users.

Finally, built in right now and with no coding involved, you can only go to Permissions and decide to show your questions (all of them) only to registered users.
by
That's great to hear about moderation coming--that would be the ideal solution. The last option is easy but it won't work, since I do need the public to see the questions that have been answered.

Is there any way you or someone else could explain, more or less step-by-step, how to do either of the other solutions--set created questions as hidden or output only answered questions for not logged in users? I can sort of read PHP in very small doses, but I'm far from a programmer.
0 votes
by
edited by

If you use the "theme" solution, unanswered question would be not be shown but this will have some side effects on paging (the paging counts all questions while you would only show the answered one; so some page might be empty and all pages won't be the same size) - but as a temp and simple solution until the next version, I think this would work out. First check out how to create your custom advanced theme here (http://www.question2answer.org/themes.php#advanced) - (really simple) and in your qa-theme.php write this:

 
function main()
{
           
if (isset($this->content['q_list']['qs'])  && qa_get_logged_in_userid() == null) {
$qs=$this->content['q_list']['qs'];
 
foreach($qs as $question_idx => $question) {
if ($question['answers_raw'] == 0) {
unset($qs[$question_idx]);
}
}
$this->content['q_list']['qs'] = $qs;
 
}
qa_html_theme_base::main();
}
 
 
The event solution is a bit more complex, but you can look in the plugin - events to  see how to do it here http://www.question2answer.org/plugins.php . 
by
Thank you so much, I will give it a try!
by
I was reading again your question and I was curious to know why 'answered' question are 'safer' than unanswered? Do you only allow a particular group of users to answer question? Also, keep in mind that user who posted a question could modify them afterwards.
by
That's correct--only a particular group can answer questions. Registration would not be open to most users. So, anonymous people asking questions, registered users answering them. If someone posts something abusive, I don't want it showing up publicly.

Unfortunately I tried the code you supplied in the qa-theme.php file and it did not work--users who are not logged in can still see the unanswered questions as well as answered questions. I don't know if the error is mine or yours, though...
by
My bad, a reference problem. When I tested it I wasn't calling back the parent method. See the modified version which I've tested in the Candy theme and worked fine.
by
Hm, didn't work. I got

Notice: Undefined index: qs in /home/[path]/qa-include/qa-theme-base.php on line 1046

Warning: Invalid argument supplied for foreach() in /home/[path]/qa-include/qa-theme-base.php on line 1046

And no questions appeared at all.  Again, it's quite possible I made some other mistake here.
by
Sorry, copy paste issue I think! :) New version!
by
Perfect, it works now! Many thanks.
...