mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
MDL-61132 Questions: Adapt logic on export/import
Modified import/export to adapt with "Top" categories.
This commit is contained in:
parent
8df402e401
commit
f86f8c85c1
@ -69,7 +69,8 @@ class question_export_form extends moodleform {
|
||||
// Export options.
|
||||
$mform->addElement('header', 'general', get_string('general', 'form'));
|
||||
|
||||
$mform->addElement('questioncategory', 'category', get_string('exportcategory', 'question'), compact('contexts'));
|
||||
$mform->addElement('questioncategory', 'category', get_string('exportcategory', 'question'),
|
||||
array('contexts' => $contexts, 'top' => true));
|
||||
$mform->setDefault('category', $defaultcategory);
|
||||
$mform->addHelpButton('category', 'exportcategory', 'question');
|
||||
|
||||
|
@ -499,6 +499,12 @@ class qformat_default {
|
||||
$contextid = false;
|
||||
}
|
||||
|
||||
// Before 3.5, question categories could be created at top level.
|
||||
// From 3.5 onwards, all question categories should be a child of a special category called the "top" category.
|
||||
if (isset($catnames[0]) && (($catnames[0] != 'top') || (count($catnames) < 3))) {
|
||||
array_unshift($catnames, 'top');
|
||||
}
|
||||
|
||||
if ($this->contextfromfile && $contextid !== false) {
|
||||
$context = context::instance_by_id($contextid);
|
||||
require_capability('moodle/question:add', $context);
|
||||
@ -509,9 +515,15 @@ class qformat_default {
|
||||
|
||||
// Now create any categories that need to be created.
|
||||
foreach ($catnames as $catname) {
|
||||
if ($category = $DB->get_record('question_categories',
|
||||
if ($parent == 0) {
|
||||
$category = question_get_top_category($context->id, true);
|
||||
$parent = $category->id;
|
||||
} else if ($category = $DB->get_record('question_categories',
|
||||
array('name' => $catname, 'contextid' => $context->id, 'parent' => $parent))) {
|
||||
$parent = $category->id;
|
||||
} else if ($parent == 0) {
|
||||
$category = question_get_top_category($context->id, true);
|
||||
$parent = $category->id;
|
||||
} else {
|
||||
require_capability('moodle/question:managecategory', $context);
|
||||
// create the new category
|
||||
|
Loading…
x
Reference in New Issue
Block a user