ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng, $ilCtrl;
145 
146  if (!$this->getTest() instanceof ilObjTest) {
147  throw new ilException('Incomplete object configuration. Please pass an instance of ilObjTest before calling the export!');
148  }
149 
150  try {
151  $this->buildExportFile(new ilTestExportFilename($this->getTest()));
152  } catch (ilException $e) {
153  if ($this->txt($e->getMessage()) == '-' . $e->getMessage() . '-') {
154  ilUtil::sendFailure($e->getMessage(), true);
155  } else {
156  ilUtil::sendFailure($this->txt($e->getMessage()), true);
157  }
158  $ilCtrl->redirectByClass('iltestexportgui');
159  }
160 
161  ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
162  $ilCtrl->redirectByClass('iltestexportgui');
163  }
164 
171  abstract protected function buildExportFile(ilTestExportFilename $export_path);
172 
180  abstract protected function getFormatIdentifier();
181 
186  abstract public function getFormatLabel();
187 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Abstract parent class for all event hook plugin classes.
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
Removing first two heading rows for CSV export
Definition: 26utf8.php:79
const IL_COMP_MODULE
txt($a_var)
Get Language Variable (prefix will be prepended automatically)
Create styles array
The data for the language used.
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...
global $lng
Definition: privfeed.php:17