Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Exporting/importing several question categories at once

From MoodleDocs

Current save in XML file

I have this structure.

str.png

My first category contains these questins.

question for my first category .png

Subcategory first category contains these questins.

question for subcategory first category .png

Exporting My first category with "Write context to file", I get the current file structure.

<?xml version="1.0" encoding="UTF-8"?> <quiz>

 <question type="category">
   <category>
       <text>$course$/По умолчанию для Главная страница/My first category</text>
   </category>
 </question>
 <question type="cloze">
   <name>
     <text>My first question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Embedded answers question. Write "hello" {1:SA:=hello}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>
 <question type="cloze">
   <name>
     <text>My second question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Now you can choose from several options! Choose one {1:MC:two~three~four~=one}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>
 <question type="category">
   <category>
       <text>$course$/По умолчанию для Главная страница/My first category/Subcategory first category</text>
   </category>
 </question>
 <question type="cloze">
   <name>
     <text>Testing question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Write that in your head {1:SA:=brain}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>

</quiz>

Exporting My first category without "Write context to file", I get the current file structure.

<?xml version="1.0" encoding="UTF-8"?> <quiz>

 <question type="category">
   <category>
       <text>По умолчанию для Главная страница/My first category</text>
   </category>
 </question>
 <question type="cloze">
   <name>
     <text>My first question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Embedded answers question. Write "hello" {1:SA:=hello}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>
 <question type="cloze">
   <name>
     <text>My second question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Now you can choose from several options! Choose one {1:MC:two~three~four~=one}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>
 <question type="category">
   <category>
       <text>По умолчанию для Главная страница/My first category/Subcategory first category</text>
   </category>
 </question>
 <question type="cloze">
   <name>
     <text>Testing question</text>
   </name>
   <questiontext format="html">

<text><![CDATA[

Write that in your head {1:SA:=brain}.

]]></text>

   </questiontext>
   <generalfeedback format="html">
     <text></text>
   </generalfeedback>
   <penalty>0.3333333</penalty>
   <hidden>0</hidden>
 </question>

</quiz>

Interface

The new interface, which lets you export several question categories at once.

To activate the export / import multiple categories question, select "Write a several question categories".

activate.jpg

After choosing "Write a several question categories" look of combobox list elements will be changed as it shown on the picture.

change.jpg

How to change the interface is described below .

1. Category you want to export, are chosen as you can watch at the image.

choose categories.jpg

2. To select a diapason of categories, select a category which is the first one in the diapason, hold down the Shift key and select the last category in diapason.

diapason categories.jpg

3. Select categories with subcategories. When you click on the category for the first time, only this category is selected. When you click on the category for the second time, the categories that are one level below, are selected too.

categories with subcategories.jpg

When you click on the category for the third time, all selections are canceled.

selections are canceled.jpg

To select a category with all its subcategories, press the Ctrl key and click on the category.

all subcategories.jpg

4. Select the diapason of categories with subcategories. To select a diapason of categories with all their subcategories, select a category which is the first one in diapason , hold down the Shift + Ctrl keys and select the last category in the diapason.

diapason with all subcategories.jpg

5. Select all categories. Select the top line in the drop-down box.

all categories.jpg

To achieve the desired result, I have to use it.

Change export/import function and file structure

I think that these changes will not affect the file format.

What about export/import function. After analyzing file "...\moodle\question\format\xml\format.php" I made a conclusion that only one category was saved, so for implementation of this interface I have to change this functions.