From 3a7005c9643a0780cb65bd7f7d8d95ea58d9871c Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 2 Mar 2018 12:21:54 +0800 Subject: [PATCH] MDL-61410 question: support course tags on export --- question/format/xml/format.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index efd209c6579..63ae9f56777 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -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 .= " \n"; + foreach ($coursetagobjects as $tagobject) { + $expout .= " " . $this->writetext($tagobject->get_display_name(), 0, true) . "\n"; + } + $expout .= " \n"; + } + if (!empty($question->tags)) { $expout .= " \n"; - foreach ($tags as $tag) { + foreach ($question->tags as $tag) { $expout .= " " . $this->writetext($tag, 0, true) . "\n"; } $expout .= " \n";