Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
844 views
in Q2A Core by

I get 'spammed' by maths students who seem to have a hard time with their professor. Within 1 week there were sometimes 5 * same question!

And of course they  don't use the search before asking + the "related questions" shown after the question title is given, are mostly not matching...

That's why I have to close them manually as duplicate (pain enough).

 

And yep, now I need to list those duplicates to be able to delete them.

Q2A version: 1.5.3
by
Why don't you just hide the questions instead of closing them?
by
Because if I close the questions, the students will post them again. But if the questions are marked as duplicate, the students can follow the link to the original question that is already answered.

1 Answer

0 votes
by
 
Best answer
$queryDuplicates = qa_db_query_sub('SELECT postid,closedbyid,title,userid,created
                                FROM `^posts`
                                WHERE `type` = "Q"
                                AND `closedbyid` IS NOT NULL
                                ORDER BY created ASC
                                ;');
                                
// initiate output string
$duplicatesList = "<table> <thead><tr> <th style='text-align:center'>Date</th> <th>Question Title</th> <th>User</th> <th>Answers</th> <th>Comments</th> </tr></thead>";

$dupCount = 0;
while ( ($duprow = qa_db_read_one_assoc($queryDuplicates,true)) !== null ) {
    // query recent user
    $currentUser = $duprow['userid'];
    $userrow = qa_db_select_with_pending( qa_db_user_account_selectspec($currentUser, true) );

    // check closed-by to see if just-closed (type=NOTE) or if its duplicate-closed (type=Q)
    $closedByQu = qa_db_read_one_value( qa_db_query_sub('SELECT postid FROM `^posts`
                                                            WHERE `postid` = #
                                                            AND `type` = "Q"
                                                            ;', $duprow['closedbyid']), true );
    if(isset($closedByQu)) {
        $dupCount++;
        // get number of answers to recent question
        $nAnswers = qa_db_read_one_value( qa_db_query_sub('SELECT COUNT(*) FROM `^posts`
                                                            WHERE `parentid` = #
                                                            AND `type` = "A"
                                                            ;', $duprow['postid']), true );
        // get number of comments to recent question
        $nComments = qa_db_read_one_value( qa_db_query_sub('SELECT COUNT(*) FROM `^posts`
                                                            WHERE `parentid` = #
                                                            AND `type` = "C"
                                                            ;', $duprow['postid']), true );
        $duplicatesList .= '<tr> <td>'.substr($duprow['created'],0,10).'</td> <td><a href="'.qa_path_html(qa_q_request($duprow['postid'], $duprow['title']), null, qa_opt('site_url'), null, null).'">'.$duprow['title'].'</a></td> <td>'. qa_get_one_user_html($userrow['handle'], false) .'</td> <td>'.$nAnswers.'</td> <td>'.$nComments.'</td> </tr>';
    }
}
$duplicatesList .= "</table>";
...