ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestExportPlugin.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/Component/classes/class.ilPlugin.php';
5require_once 'Modules/Test/classes/class.ilTestExportFilename.php';
6
13abstract class ilTestExportPlugin extends ilPlugin
14{
18 protected $test;
19
23 protected $timestmap = -1;
24
28 protected static $reserved_formats = array(
29 'xml',
30 'csv'
31 );
32
37 final public function getComponentType()
38 {
39 return IL_COMP_MODULE;
40 }
41
46 final public function getComponentName()
47 {
48 return "Test";
49 }
50
55 final public function getSlot()
56 {
57 return "Export";
58 }
59
64 final public function getSlotId()
65 {
66 return "texp";
67 }
68
72 final protected function slotInit()
73 {
74 }
75
79 final public function setTest($test)
80 {
81 $this->test = $test;
82 }
83
87 final protected function getTest()
88 {
89 return $this->test;
90 }
91
95 public function setTimestmap($timestmap)
96 {
97 $this->timestmap = $timestmap;
98 }
99
103 public function getTimestmap()
104 {
105 return $this->timestmap;
106 }
107
112 final public function getFormat()
113 {
114 $format_id = $this->getFormatIdentifier();
115
116 if(!is_string($format_id))
117 {
118 throw new ilException('The format must be of type string.');
119 }
120
121 if(!strlen($format_id))
122 {
123 throw new ilException('The format is empty.');
124 }
125
126 if(strtolower($format_id) != $format_id)
127 {
128 throw new ilException('Please use a lowercase format.');
129 }
130
131 if(in_array($format_id, self::$reserved_formats))
132 {
133 throw new ilException('The format must not be one of: ' . implode(', ', self::$reserved_formats));
134 }
135
136 return $format_id;
137 }
138
142 final public function export()
143 {
148 global $lng, $ilCtrl;
149
150 if(!$this->getTest() instanceof ilObjTest)
151 {
152 throw new ilException('Incomplete object configuration. Please pass an instance of ilObjTest before calling the export!');
153 }
154
155 try
156 {
157 $this->buildExportFile(new ilTestExportFilename($this->getTest()));
158 }
159 catch(ilException $e)
160 {
161 if($this->txt($e->getMessage()) == '-' . $e->getMessage() . '-')
162 {
163 ilUtil::sendFailure($e->getMessage(), true);
164 }
165 else
166 {
167 ilUtil::sendFailure($this->txt($e->getMessage()), true);
168 }
169 $ilCtrl->redirectByClass('iltestexportgui');
170 }
171
172 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
173 $ilCtrl->redirectByClass('iltestexportgui');
174 }
175
182 abstract protected function buildExportFile(ilTestExportFilename $export_path);
183
191 abstract protected function getFormatIdentifier();
192
197 abstract public function getFormatLabel();
198}
const IL_COMP_MODULE
Base class for ILIAS Exception handling.
txt($a_var)
Get Language Variable (prefix will be prepended automatically)
Abstract parent class for all event hook plugin classes.
getComponentType()
Get Component Type.
getComponentName()
Get Component Name.
slotInit()
Object initialization done by slot.
getFormatLabel()
This method should return a human readable label for your export.
buildExportFile(ilTestExportFilename $export_path)
This method is called if the user wants to export a test of YOUR export type If you throw an exceptio...
getFormatIdentifier()
A unique identifier which describes your export type, e.g.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40