MDL-61410 question: support course tags on export

This commit is contained in:
Simey Lameze 2018-03-02 12:21:54 +08:00
parent b63a3b04b1
commit 3a7005c964

View File

@ -1467,10 +1467,31 @@ class qformat_xml extends qformat_default {
$expout .= $this->write_hints($question);
// Write the question tags.
$tags = core_tag_tag::get_item_tags_array('core_question', 'question', $question->id);
if (!empty($tags)) {
// If the question has course tags then we need to filter them to only
// include the tags for this course.
get_question_options($question, true);
if (isset($question->coursetagobjects)) {
// Get the tag objects for the course being viewed.
$courseid = $this->course->id;
$coursecontext = context_course::instance($courseid);
$coursetagobjects = array_filter(
$question->coursetagobjects,
function($tagobject) use ($coursecontext) {
return $coursecontext->id == $tagobject->taginstancecontextid;
}
);
// Set them on the form to be rendered as existing tags.
$expout .= " <coursetags>\n";
foreach ($coursetagobjects as $tagobject) {
$expout .= " <tag>" . $this->writetext($tagobject->get_display_name(), 0, true) . "</tag>\n";
}
$expout .= " </coursetags>\n";
}
if (!empty($question->tags)) {
$expout .= " <tags>\n";
foreach ($tags as $tag) {
foreach ($question->tags as $tag) {
$expout .= " <tag>" . $this->writetext($tag, 0, true) . "</tag>\n";
}
$expout .= " </tags>\n";