Skip to content

Commit

Permalink
MDL-61410 question: merge course and question tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Mar 19, 2018
1 parent 1796eb1 commit bbd655b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
32 changes: 24 additions & 8 deletions question/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class qformat_default {
public $stoponerror = true;
public $translator = null;
public $canaccessbackupdata = true;

protected $importcontext = null;

// functions to indicate import/export functionality
Expand Down Expand Up @@ -425,14 +424,31 @@ public function importprocess($category) {

$result = question_bank::get_qtype($question->qtype)->save_question_options($question);

if (!empty($question->tags)) {
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
$question->context, $question->tags);
}
if (core_tag_tag::is_enabled('core_question', 'question')) {
// Is the current context we're importing in a course context?
$importingcontext = $this->importcontext;
$importingcoursecontext = $importingcontext->get_course_context(false);
$isimportingcontextcourseoractivity = !empty($importingcoursecontext);

if (!empty($question->coursetags)) {
if ($isimportingcontextcourseoractivity) {
$mergedtags = array_merge($question->coursetags, $question->tags);

core_tag_tag::set_item_tags('core_question', 'question', $question->id,
$question->context, $mergedtags);
} else {
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
context_course::instance($this->course->id), $question->coursetags);

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($question->tags)) {
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
$importingcontext, $question->tags);
}
}
} else {
core_tag_tag::set_item_tags('core_question', 'question', $question->id,
$question->context, $question->tags);
}
}

if (!empty($result->error)) {
Expand Down
2 changes: 1 addition & 1 deletion question/format/xml/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ public function writequestion($question) {
if (core_tag_tag::is_enabled('core_question', 'question')) {
$tagobjects = core_tag_tag::get_item_tags('core_question', 'question', $question->id);

if (!is_null($tagobjects)) {
if (!empty($tagobjects)) {
$context = context::instance_by_id($contextid);
$sortedtagobjects = question_sort_tags($tagobjects, $context, [$this->course]);

Expand Down

0 comments on commit bbd655b

Please sign in to comment.