Development Guide

Test-Export Plugins

This feature is available for ILIAS 4.4.x+.

The purpose of this plugin slot is offering the possibility to create, list and dowload custom test export files in the export area of ILIAS tests. It is also possible to use this plugin slot as a kind of hook to transport certain test data to another service, e.g. by a webservice. Each active test export plugin will be listed in the list of possible export formats in the Export area of an ILIAS test.

The plugin slot is named Export (Administration » Plugins » Slots). The corresponding plugin target directory is: [ILIAS_MAIN_DIRECTORY]/Customizing/global/plugins/Modules/Test/Export . Your plugin class has to named il[YOUR_PLUGIN_NAME]Plugin (filename: class.il[YOUR_PLUGIN_NAME]Plugin.php) and extend the abstract class ilTestExportPlugin (located in: [ILIAS_MAIN_DIRECTORY]/Modules/Test/classes).
 
You have to implement three abstract methods.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require_once 'Modules/Test/classes/class.ilTestExportPlugin.php';
 
class ilYourTestExportPlugin extends ilTestExportPlugin
{
/**
* A unique identifier which describes your export type, e.g. imsm
* There is currently no mapping implemented concerning the filename.
* Feel free to create csv, xml, zip files ....
*
* @return string
*/

protected function getFormatIdentifier()
{
return 'helloworld';
}
 
/**
* This method should return a human readable label for your export. The string could be a translated language variable.
* @return string
*/

public function getFormatLabel()
{
return 'YourDesiredLabel';
}
 
/**
* This method is called if the user wants to export a test of YOUR export type
* If you throw an exception of type ilException with a respective language variable, ILIAS presents a translated failure message.
* @throws ilException
* @param string $export_path The path to store the export file
*/

protected function buildExportFile(ilTestExportFilename $export_path)
{
// Add your export code here
}
}

Please note, that the format identifier is not meant to be the exports filename extension.
Also, the export formats ILIAS ships with are not be used here and are reserved. (At the time of this writing: xml, xls and csv)

The following paragraph is only important if you want to create/list/download an ILIAS compliant export file (have a look at the screenshot above). It is not important if you transport test data to another system (which is also possible as mentioned above).

An instance of class ilTestExportFilename is passed as the one and only argument to your overridden buildExportFile method. This object can be used to get an ILIAS compliant filename for your export content. Therefore you have to call ...

1
2
3
4
5
6
7
[...]
protected function buildExportFile(ilTestExportFilename $export_path);
{
$filename = $export_path->getPathname("csv");
// Do something with the filename, use e.g. file_put_contents, fopen/fwrite/fclose, ...
}
[...]

This method returns a compliant filename based on the passed file extension. You can use the return value to put your export content into the file. If the file is stored in filesystem (this has to be done by using native php functions), it is automatically listed in the list of export files and can be downloaded.

Additional Infomation

Your plugin has access to the current test instance. Your can call the getTest() method to retrieve this instance. You can use it to fetch relevant information of the test you want to export, by calling any of its public methods.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[...]
protected function buildExportFile(ilTestExportFilename $export_path);
{
$filename = $export_path->getPathname("csv");
$data = $this->getTest()->getCompleteEvaluationData(TRUE);
 
foreach($data->getParticipants() as $active_id => $userdata)
{
// Do something with the participants
 
$pass = $userdata->getScoredPass();
foreach($userdata->getQuestions($pass) as $question)
{
$objQuestion = $this->getTest()->_instanciateQuestion($question["id"]);
$solutions = $objQuestion->getSolutionValues($active_id, $pass);
// Your code here
}
 
// Access some user related properties
$last_visited = $data->getParticipant($active_id)->getLastVisit()
// Your code here
}
 
$content = 'XYZ';
file_put_contents($filename, $content);
}
[...]