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

My users had a great idea, that i would like to support and implement:

+ Sorting of unanswered questions (Q that have no answer) by number of upvotes.

This would show other answering users the important questions at once.

How can we implement this easily?

 

Important PS: Have you actually noticed that the recent q2a definition of "unanswered question" is a question that has answers, but no selected answer, or no upvoted answer? ... My understanding says, if a question has an answer it is not unanswered anymore. Time for discussion maybe.

 

Q2A version: 1.6.2
by
What can I change in qa-page-unanswered.php to achieve this?

I think we have to change: function qa_db_unanswered_qs_selectspec from qa-db-selects.php
by
edited by
By the way, in qa-page-unanswered.php in the description on top you find:

Description: Controller for page **listing recent questions without answers**

But as you see, current q2a v1.6.3 is listing questions with answers (non-selected best answer, and answers with no upvotes). Not so good :)

1 Answer

+2 votes
by
edited by
 
Best answer

Got it ... solution:

1. open qa-db-selects.php

2. change after case 'amaxvote':

$bysql='amaxvote=0';

to: $bysql='amaxvote=0 AND closedbyid IS NULL AND acount=0';

3. Find in the following lines (around line 380): $selectspec['source'].=" JOIN (SELECT postid ...

and replace it with:

        // q2apro: sort by upvotes
        if($by=='amaxvote') {
            $selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE ".qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments'])."type=$ AND ".$bysql." AND closedbyid IS NULL ORDER BY ^posts.upvotes DESC LIMIT #,#) y ON ^posts.postid=y.postid";
        }
        else {
            $selectspec['source'].=" JOIN (SELECT postid FROM ^posts WHERE ".qa_db_categoryslugs_sql_args($categoryslugs, $selectspec['arguments'])."type=$ AND ".$bysql." AND closedbyid IS NULL ORDER BY ^posts.created DESC LIMIT #,#) y ON ^posts.postid=y.postid";
        }

4.  add after $selectspec['sortdesc']='created';

      // sort by upvotes
        if($by=='amaxvote') {
            $selectspec['sortdesc']='upvotes';
        }

 

5. It should work now: yourdomain.com/unanswered?by=upvotes

 

Demo here: http://www.mathelounge.de/unanswered?by=upvotes

by
Thank you! I haven't tested yet, but this will be a wonderful modification!
by
As you see in the provided link, it works :)

Only issue is: I have not yet found the way how to set the correct pagination. It is showing too many pages of open questions (see numbering on bottom of page). Still trying to find the appropriate code lines.
by
edited by
Okay, found the solution for this as well. We have a cached value here, so we need to change in qa-db-post-create.php:

qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_unupaqcount', COUNT(*) FROM ^posts WHERE type='Q' AND amaxvote=0 AND closedbyid IS NULL");

to:

qa_db_query_sub("REPLACE ^options (title, content) SELECT 'cache_unupaqcount', COUNT(*) FROM ^posts WHERE type='Q' AND amaxvote=0 AND closedbyid IS NULL AND acount=0");

Adding a "AND acount=0" in the end.

Afterwards go to /admin/stats and hit the button "recount posts". That's it .)
by
problem
PHP Notice:  Undefined index: up in /home/public_html/qa-include/util/sort.php on line 57
...