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

How to get $question in page module?

+2 votes
111 views
asked Mar 3 in Plugins by q2apro

I am writing a flag reason plugin, and want to use the core functions (to be found in question-submit.php) as much as possible:

require_once QA_INCLUDE_DIR . 'app/votes.php';

$error = qa_flag_error_html($question, $userid, qa_request());

if (!$error) {

if (qa_flag_set_tohide($question, $userid, $handle, $cookieid, $question))

qa_question_set_status($question, QA_POST_STATUS_HIDDEN, null, null, null, $answers, $commentsfollows, $closepost); // hiding not really by this user so pass nulls

return true;

}

But I do not know how I can read the $question variable from within the page module.

After searching a bit, I found the $question defined in pages/question.php:

list($question, $childposts, $achildposts, $parentquestion, $closepost, $duplicateposts, $extravalue, $categories, $favorite) = $questionData;

Any help?

Q2A version: 1.8.0

1 Answer

0 votes
answered Mar 3 by pupi1985
selected Mar 4 by q2apro
 
Best answer

I think I don't fully get the question. The text you pasted is part of the qa_page_q_single_click_q() function. I understand you want to reuse that function. So you need to call it sending a question. You can fetch the question using qa_db_full_post_selectspec() or qa_db_posts_basic_selectspec().

commented Mar 4 by q2apro
Thanks. But in general, why is the $voteuserid first parameter of this function? Weird...

From selects.php: "If $voteuserid is set, retrieve the vote made by a particular that user on each post."
commented Mar 4 by pupi1985
It is used to get information about the loggedin user and the question. For example, if the user has flagged the question, if the user has voted the question, etc. If that is not relevant you can null the parameter and retrieve it as if it was anonymous.
commented Mar 4 by q2apro
Thanks again. Based on the core functions I have released the "flag reasons" plugin: http://www.question2answer.org/qa/62668/new-plugin-flag-reasons-available-first-version-only-q
...