Help display question text contain image programmatically

Help display question text contain image programmatically

by Trần Nam Định -
Number of replies: 1

I do that 

foreach ($questions as $question) {

$questionInstance = question_bank::load_question($question->id);
$quba = question_engine::make_questions_usage_by_activity('qtype_multichoice', $contextId);
$quba->set_preferred_behaviour('adaptive');
$slot = $quba->add_question($questionInstance, $questionInstance->defaultmark);
$quba->start_question($slot);

$response = $questionInstance->get_correct_response();
$response['-submit'] = 1;
$quba->process_action($slot, $response);

$options = new question_display_options();
$options->readonly = true;
$options->flags = question_display_options::HIDDEN;
$options->suppressruntestslink = true;


echo $quba->render_question($slot, $options);
echo "<hr/>";
}

I got image url is "http://localhost/ktqg/pluginfile.php/2/question/questiontext/2aAnyxTdO2/1/5289/iconmultyuser.png"

instate of "http://localhost/ktqg/pluginfile.php/2/question/questiontext/945/1/5289/iconmultyuser.png"

Please help me fix it! :'(


Attachment preview question error.png
Average of ratings: -
In reply to Trần Nam Định

Re: Help display question text contain image programmatically

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You need to save the usage in the database.

Therefore, probably best to use component 'core_question_preview' in the

question_engine::make_questions_usage_by_activity('qtype_multichoice', $contextId);
line, since old previews get automatically cleaned up after a while.