Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
927 views
in Themes by
Hi,

I want to keep the red color even if there is an answer as long as there are no experts answers. Where should I look? Should I develop a plugin to change the logic?

Thanks

1 Answer

+1 vote
by
selected by
 
Best answer

You will have to write a plugin. The logic should involve a layer to render the appropriate color as well as figuring out if the question has an answer that belongs to an expert user.

Regarding the rendering just overwrite the a_count() function to also include the qa-a-count-zero CSS class if the condition is met.

Regarding the condition I recommend to check the qa-include/pages/question.php file and see how the qa_db_full_child_posts_selectspec() function works. Then you'll have to call that function for every item in the question list and in the question itself to fetch all the answers of the question. Then it is just a matter of checking if the answer belongs to an expert user (QA_USER_LEVEL_EXPERT).

by
Thanks for the detailed answer.
I'm more curious about changing the query that lists all the questions and have a join clause with answers and get the max level of all the answers, then I wouldn't have to run an additional query for every question.
Any idea where I should look?
by
Good point. As I don't know the level of programming knowledge of the asker I need to keep it as simple as possible in the structure of the answer.

Indeed, it is better to make a single query, similar to the one in the selectspec I provided and join to the answers and users table. In fact, you can filter out experts and above in the join itself so you would only be getting in the result IDs of questions that have answers posted by experts+.

You should run that query in the initialize() function and store the result in an array. Then a_count() just checks if the current post being displayed matches the given ID. If it does, then add the qa-a-count-zero CSS class.

In a way, qa-include/plugins/qa-layer-voters-flaggers.php follows a similar mechanism.

Strictly answering your question, I can't be more precise on where to look. If you want to do so, you'll have to write it on your own, as the query you're looking is very ad-hoc, but the selectspec I gave you should be quite close.
by
Thanks a lot.
Instead of selecting ids, and checking against them in qa_count(), I would love to add a column to the *select questions* query called max_level_of_answerer and in qa_count() just test if this level is > QA_USER_LEVEL_EXPERT
Any idea where is that query then I can build the join and aggregation myself
by
If you change a query that is used all along Q2A then you might have unexpected results.

Still, if you still want to go that way, bear in mind the "one" query should be in qa_db_posts_basic_selectspec() function. If you are looking for more specific ones you will have to search in the same file (selects.php) for the one you want to change or starting from the page itself you want this applied to and check what the page itself is using to fetch the data
by
Awesome, that's what I was doing.
Thanks for all the details.
by
Just one last comment,
How do I debug the full string SQL query that is being generated before execution?
by
Also, I don't know why I can't see the accept button
by
You can enable this flag in qa-config.php:

define('QA_DEBUG_PERFORMANCE', true);

Although I usually end up tailing the logs of the MySQL instance. Probably, as this case is simple enough it might be enough for you to just see it in the web page.

BTW, the accept button is the gray tick, right below the vote counts.
by
For some reason I don't see it.
Screenshot
https://ibb.co/nywHvn
by
Interesting. Maybe there is a minimum amount of points you need to have before accepting an answer. Funny thing, I didn't remember that to happen when I joined here. Never mind!.
...