Note:

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

Import/export for questiontype plugins: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 1: Line 1:
''This is a proposal currently in development''
== Motivation ==
== Motivation ==


While it is easy enough to add import and export capability for core questiontypes there is no clear way to allow contributed questiontype authors to enhance their plugin with import and export code. This is an outline proposal for including hooks for that functionality. It is primarily aimed at the Moodle XML format (the most comprehensive import/export format) but with a definite goal not to exclude any other format that may wish to use it.
While it is easy enough to add import and export capability for core questiontypes there is no clear way to allow contributed questiontype authors to enhance their plugin with import and export code. This is an outline proposal for including hooks for that functionality. It is primarily aimed at the Moodle XML format (the most comprehensive import/export format) but with a definite goal not to exclude any other format that may wish to use it.
== New Methods in Questiontype Class ==
The main mechanism for this process will be new classes for import and export to be added to the questiontype class. These should be overridden by question plugs that wish the support import and/or export. Note that these will not (and should not) be implemented for core question types.
=== Import ===
    /**
    * Override to provide import functionality for plugin questions (only)
    * @param format string the name of the import format making request
    * @param name string the name of the question type (in the import file)
    * @param data mixed the segment of data containing the question
    * @return object question object suitable for save_options() call or false if cannot handle
    */
    function import( $format, $name, $data ) {
        return false;
    }
Notes:
* The method provides a single entry point for all formats
* The name is supplied as it may differ from the questiontype name - more on this...


== See Also ==
== See Also ==

Revision as of 14:19, 1 August 2007

This is a proposal currently in development

Motivation

While it is easy enough to add import and export capability for core questiontypes there is no clear way to allow contributed questiontype authors to enhance their plugin with import and export code. This is an outline proposal for including hooks for that functionality. It is primarily aimed at the Moodle XML format (the most comprehensive import/export format) but with a definite goal not to exclude any other format that may wish to use it.

New Methods in Questiontype Class

The main mechanism for this process will be new classes for import and export to be added to the questiontype class. These should be overridden by question plugs that wish the support import and/or export. Note that these will not (and should not) be implemented for core question types.

Import

   /**
    * Override to provide import functionality for plugin questions (only)
    * @param format string the name of the import format making request
    * @param name string the name of the question type (in the import file)
    * @param data mixed the segment of data containing the question
    * @return object question object suitable for save_options() call or false if cannot handle
    */
   function import( $format, $name, $data ) {
       return false;
   } 

Notes:

  • The method provides a single entry point for all formats
  • The name is supplied as it may differ from the questiontype name - more on this...


See Also