ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once 'Services/Component/classes/class.ilPlugin.php';
5 require_once 'Modules/Test/classes/class.ilTestExportFilename.php';
6 
13 abstract 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  throw new ilException('The format must be of type string.');
118  }
119 
120  if (!strlen($format_id)) {
121  throw new ilException('The format is empty.');
122  }
123 
124  if (strtolower($format_id) != $format_id) {
125  throw new ilException('Please use a lowercase format.');
126  }
127 
128  if (in_array($format_id, self::$reserved_formats)) {
129  throw new ilException('The format must not be one of: ' . implode(', ', self::$reserved_formats));
130  }
131 
132  return $format_id;
133  }
134 
138  final public function export()
139  {
144  global $DIC;
145  $lng = $DIC['lng'];
146  $ilCtrl = $DIC['ilCtrl'];
147 
148  if (!$this->getTest() instanceof ilObjTest) {
149  throw new ilException('Incomplete object configuration. Please pass an instance of ilObjTest before calling the export!');
150  }
151 
152  try {
153  $this->buildExportFile(new ilTestExportFilename($this->getTest()));
154  } catch (ilException $e) {
155  if ($this->txt($e->getMessage()) == '-' . $e->getMessage() . '-') {
156  ilUtil::sendFailure($e->getMessage(), true);
157  } else {
158  ilUtil::sendFailure($this->txt($e->getMessage()), true);
159  }
160  $ilCtrl->redirectByClass('iltestexportgui');
161  }
162 
163  ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
164  $ilCtrl->redirectByClass('iltestexportgui');
165  }
166 
173  abstract protected function buildExportFile(ilTestExportFilename $export_path);
174 
182  abstract protected function getFormatIdentifier();
183 
188  abstract public function getFormatLabel();
189 }
Abstract parent class for all event hook plugin classes.
global $DIC
Definition: saml.php:7
getComponentName()
Get Component Name.
getComponentType()
Get Component Type.
getFormatLabel()
This method should return a human readable label for your export.
getFormatIdentifier()
A unique identifier which describes your export type, e.g.
slotInit()
Object initialization done by slot.
global $ilCtrl
Definition: ilias.php:18
$lng
const IL_COMP_MODULE
txt(string $a_var)
Get Language Variable (prefix will be prepended automatically)
test()
Definition: build.php:107
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
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...