16/Exportacion/importación de preguntas

De MoodleDocs

Nota: Pendiente de Traducir. ¡Anímese a traducir esta página!.     ( y otras páginas pendientes)

Importando o exportando preguntas

Las preguntas provenientes de otros cursos Moodle o de otros sistemas de e-learning (por ejemplo: Blackboard, Webct etc.) pueden importarse a Moodle. De forma similar, Moodle ofrece un proceso para exportar preguntas hacia otros sistemas en diferentes formatos ( XML, QTI etc.). El código para importar y exportar está escrito principalmente en los archivos format.php localizados en un directorio específico para el tipo de archivos de formato de donde se realiza la importación o exportación.

  • typicamente
    • question/format/aiken/format.php
    • question/format/blackboard/format.php
    • question/format/qti2/format.php
    • question/format/xml/format.php

existe una clase qformat_default definida en question/format.php y el proceso se controla por

  • question/import.php
  • question/export.php

La principal dificultad para codificar estos archivos específicos format.php estriba en que los desarrolladores deben estar conscientes de

  • el formato que codifica los archivos a importar o exportar (XML, QTI etc.)
  • los parámetros necesarios para los diferentes tipos de preguntas de Moodle, donde fácilmente se pueden introducir nuevos tipos en el futuro cercano debido a la reingeniería del código de las preguntas de Moodle.

Where to find the information to code for import/export format.php files.

As we are developping new questiontypes or new import functions from external files, we need to safeguard the default_questiontype->save_question() from importing bad question data. We must well document these question parameters and get stronger validation before saving a new question.

The most exhaustive developper documentations rely on the knowledge of the database tables, the tags definition and a good comprehension of the few comments inserted in the code.

Efforts have been made to document the database (i.e. Gustav Delius has work a lot on the question part) but as usual solving the bugs and developping new features took most of the energy.

For the description of the different question parameters you should look at the developper docs Quiz database structure and the quiz_questions table that have been renamed question when the question code has been replaced as independent from the quiz in moodle 1.6.

These docs illustrate well the difficulty to maintain an up-to-date, I had to correct it (at least I try...) for the modifications done by Gustav himself in the database .

The format.php code flow for import

When importing questions

  • the import.php open the file
  • the specific format.php
  • the format.php clone in a certain way the default_questiontype->save_question()

by saving the question common elements

  • afterwards it calls the specific qtype->save_question_options() function

which are the regular way to save these options that were retrieved from the imported file.


The 1.6 question table contains the id,category,parent,name,questiontext,questiontextformat,image,defaultgrade,penalty,qtype,length,stamp,version,hidden as the old quiz_questions table with the following modifications.

It is difficult to types that can be data structure of and each question type is expected to implement supply at least Importing or Importing and exporting have in common the data structure of questions in moodle but different requirements about the import or export modules unless the import or export is related to the same standard (ex.QTI). The moodle data structure should be avalable elsewhere.

See also

Lesson question types - both Lesson and Quiz can import the basic Moodle question types.