mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-61410 question: support course tags on import
This commit is contained in:
parent
2ee6e02e21
commit
13596866e7
2 changed files with 24 additions and 9 deletions
|
@ -425,8 +425,14 @@ class qformat_default {
|
|||
|
||||
$result = question_bank::get_qtype($question->qtype)->save_question_options($question);
|
||||
|
||||
if (isset($question->tags)) {
|
||||
core_tag_tag::set_item_tags('core_question', 'question', $question->id, $question->context, $question->tags);
|
||||
if (!empty($question->tags)) {
|
||||
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
|
||||
$question->context, $question->tags);
|
||||
}
|
||||
|
||||
if (!empty($question->coursetags)) {
|
||||
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
|
||||
context_course::instance($this->course->id), $question->coursetags);
|
||||
}
|
||||
|
||||
if (!empty($result->error)) {
|
||||
|
|
|
@ -383,14 +383,22 @@ class qformat_xml extends qformat_default {
|
|||
public function import_question_tags($qo, $questionxml) {
|
||||
global $CFG;
|
||||
|
||||
if (core_tag_tag::is_enabled('core_question', 'question')
|
||||
&& array_key_exists('tags', $questionxml['#'])
|
||||
&& !empty($questionxml['#']['tags'][0]['#']['tag'])) {
|
||||
$qo->tags = array();
|
||||
if (core_tag_tag::is_enabled('core_question', 'question')) {
|
||||
|
||||
$qo->tags = [];
|
||||
if (!empty($questionxml['#']['tags'][0]['#']['tag'])) {
|
||||
foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) {
|
||||
$qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
|
||||
}
|
||||
}
|
||||
|
||||
$qo->coursetags = [];
|
||||
if (!empty($questionxml['#']['coursetags'][0]['#']['tag'])) {
|
||||
foreach ($questionxml['#']['coursetags'][0]['#']['tag'] as $tagdata) {
|
||||
$qo->coursetags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1472,7 +1480,8 @@ class qformat_xml extends qformat_default {
|
|||
|
||||
if (!is_null($tagobjects)) {
|
||||
$tagobjects = $tagobjects[$question->id];
|
||||
$sortedtagobjects = question_sort_tags($tagobjects, $this->category);
|
||||
$categorycontext = context::instance_by_id($this->category->contextid);
|
||||
$sortedtagobjects = question_sort_tags($tagobjects, $categorycontext);
|
||||
|
||||
if (!empty($sortedtagobjects->coursetags)) {
|
||||
// Set them on the form to be rendered as existing tags.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue