ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilTestExportGUI Class Reference

Export User Interface Class. More...

+ Inheritance diagram for ilTestExportGUI:
+ Collaboration diagram for ilTestExportGUI:

Public Member Functions

 __construct (ilObjTestGUI $parent_gui, private ilDBInterface $db, private ilLogger $logger, private ilObjectDataCache $obj_cache, private ilComponentRepository $component_repository, Generator $active_export_plugins, private ilTestHTMLGenerator $html_generator, private array $selected_files, private QuestionInfoService $questioninfo,)
 
 createTestExportWithResults ()
 Create test export file. More...
 
 createTestResultsExport ()
 
 createTestArchiveExport ()
 
 listExportFiles ()
 
 download ()
 
 delete ()
 
- Public Member Functions inherited from ilExportGUI
 __construct (object $a_parent_gui, ?ilObject $a_main_obj=null)
 
 addFormat (string $a_key, string $a_txt="", object $a_call_obj=null, string $a_call_func="")
 
 getFormats ()
 
 addCustomColumn (string $a_txt, object $a_obj, string $a_func)
 
 addCustomMultiCommand (string $a_txt, object $a_obj, string $a_func)
 
 getCustomMultiCommands ()
 
 getCustomColumns ()
 
 executeCommand ()
 
 listExportFiles ()
 
 createExportFile ()
 
 confirmDeletion ()
 Confirm file deletion. More...
 
 delete ()
 
 download ()
 Download file. More...
 
 handleCustomMultiCommand ()
 

Protected Member Functions

 buildExportTableGUI ()
 
- Protected Member Functions inherited from ilExportGUI
 initFileIdentifierFromQuery ()
 
 initFileIdentifiersFromPost ()
 
 initFormatFromPost ()
 
 initExportOptionsFromPost ()
 
 buildExportTableGUI ()
 
 getParentGUI ()
 
 showItemSelection ()
 Show container item selection table. More...
 
 saveItemSelection ()
 

Private Member Functions

 getExportTypeFromFileName (string $export_file)
 

Additional Inherited Members

- Protected Attributes inherited from ilExportGUI
ILIAS Export InternalGUIService $gui
 
Factory $refinery
 
Services $http
 
array $formats = array()
 
array $custom_columns = array()
 
array $custom_multi_commands = array()
 
ilObject $obj
 
ilLanguage $lng
 
ilGlobalTemplateInterface $tpl
 
ilCtrlInterface $ctrl
 
ilAccessHandler $access
 
ilErrorHandling $error
 
ilToolbarGUI $toolbar
 
ilObjectDefinition $objDefinition
 
ilTree $tree
 

Detailed Description

Export User Interface Class.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

ilTestExportGUI: ilParticipantsTestResultsGUI

Definition at line 35 of file class.ilTestExportGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilTestExportGUI::__construct ( ilObjTestGUI  $parent_gui,
private ilDBInterface  $db,
private ilLogger  $logger,
private ilObjectDataCache  $obj_cache,
private ilComponentRepository  $component_repository,
Generator  $active_export_plugins,
private ilTestHTMLGenerator  $html_generator,
private array  $selected_files,
private QuestionInfoService  $questioninfo 
)

Definition at line 37 of file class.ilTestExportGUI.php.

References XapiProxy\$plugin, ILIAS\MetaData\Repository\Validation\Data\__construct(), ilExportGUI\addFormat(), and ILIAS\Repository\lng().

47  {
48  parent::__construct($parent_gui, null);
49 
50  $this->addFormat('xml', $this->lng->txt('ass_create_export_file'));
51  $this->addFormat('xmlres', $this->lng->txt('ass_create_export_file_with_results'), $this, 'createTestExportWithResults');
52  $this->addFormat('csv', $this->lng->txt('ass_create_export_test_results'), $this, 'createTestResultsExport');
53  $this->addFormat('arc', $this->lng->txt('ass_create_export_test_archive'), $this, 'createTestArchiveExport');
54  foreach ($active_export_plugins as $plugin) {
55  $plugin->setTest($this->obj);
56  $this->addFormat(
57  $plugin->getFormat(),
58  $plugin->getFormatLabel(),
59  $plugin,
60  'export'
61  );
62  }
63  }
__construct(VocabulariesInterface $vocabularies)
addFormat(string $a_key, string $a_txt="", object $a_call_obj=null, string $a_call_func="")
+ Here is the call graph for this function:

Member Function Documentation

◆ buildExportTableGUI()

ilTestExportGUI::buildExportTableGUI ( )
protected
Returns
ilTestExportTableGUI

Definition at line 68 of file class.ilTestExportGUI.php.

Referenced by listExportFiles().

69  {
70  $table = new ilTestExportTableGUI($this, 'listExportFiles', $this->obj);
71  return $table;
72  }
+ Here is the caller graph for this function:

◆ createTestArchiveExport()

ilTestExportGUI::createTestArchiveExport ( )

Definition at line 111 of file class.ilTestExportGUI.php.

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ilTestEvaluation\getAllActivesPasses(), ilFileUtils\ilTempnam(), ILIAS\Repository\lng(), and ilFileUtils\makeDirParents().

112  {
113  if ($this->access->checkAccess('write', '', $this->obj->getRefId())) {
114  // prepare generation before contents are processed (for mathjax)
115 
116  $evaluation = new ilTestEvaluation($this->db, $this->obj->getTestId());
117  $allActivesPasses = $evaluation->getAllActivesPasses();
118  $participantData = new ilTestParticipantData($this->db, $this->lng);
119  $participantData->setActiveIdsFilter(array_keys($allActivesPasses));
120  $participantData->load($this->obj->getTestId());
121 
122  $archiveService = new ilTestArchiveService(
123  $this->obj,
124  $this->lng,
125  $this->obj_cache,
126  $this->html_generator
127  );
128  $archiveService->setParticipantData($participantData);
129  $archiveService->archivePassesByActives($allActivesPasses);
130 
131  $test_id = $this->obj->getId();
132  $test_ref = $this->obj->getRefId();
133  $archive_exp = new ilTestArchiver($test_id, $test_ref);
134 
135  $scoring = new ilTestScoring($this->obj, $this->db);
136  $best_solution = $scoring->calculateBestSolutionForTest();
137 
138  $tmpFileName = ilFileUtils::ilTempnam();
139  if (!is_dir($tmpFileName)) {
140  ilFileUtils::makeDirParents($tmpFileName);
141  }
142 
143  $archive_exp->handInTestBestSolution($best_solution);
144 
145  $archive_exp->updateTestArchive();
146  $archive_exp->compressTestArchive();
147  } else {
148  $this->tpl->setOnScreenMessage('info', 'cannot_export_archive', true);
149  }
150  $this->ctrl->redirectByClass('iltestexportgui');
151  }
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
Class ilTestScoring.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Class ilTestArchiver.
+ Here is the call graph for this function:

◆ createTestExportWithResults()

ilTestExportGUI::createTestExportWithResults ( )

Create test export file.

Definition at line 77 of file class.ilTestExportGUI.php.

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

78  {
79  if (!$this->access->checkAccess('write', '', $this->obj->getRefId())) {
80  $this->tpl->setOnScreenMessage('info', 'cannot_export_archive', true);
81  $this->ctrl->redirectByClass(self::class);
82  }
83 
84  $this->ctrl->setParameterByClass(self::class, 'export_results', 1);
85  (new ilExport())->exportObject($this->obj->getType(), $this->obj->getId());
86  $this->tpl->setOnScreenMessage('success', $this->lng->txt('exp_file_created'), true);
87  $this->ctrl->redirectByClass('iltestexportgui');
88  }
Export.
+ Here is the call graph for this function:

◆ createTestResultsExport()

ilTestExportGUI::createTestResultsExport ( )

Definition at line 90 of file class.ilTestExportGUI.php.

References ILIAS\Repository\access(), ILIAS\Repository\ctrl(), ILIAS\Repository\lng(), and ILIAS\Repository\logger().

91  {
92  if (!$this->access->checkAccess('write', '', $this->obj->getRefId())) {
93  $this->tpl->setOnScreenMessage('info', 'cannot_export_archive', true);
94  $this->ctrl->redirectByClass(self::class);
95  }
96 
97  $export_factory = new ilTestExportFactory(
98  $this->obj,
99  $this->lng,
100  $this->logger,
101  $this->tree,
102  $this->component_repository,
103  $this->questioninfo
104  );
105  $test_exp = $export_factory->getExporter('results');
106  $test_exp->buildExportFile();
107  $this->tpl->setOnScreenMessage('success', $this->lng->txt('exp_file_created'), true);
108  $this->ctrl->redirectByClass('iltestexportgui');
109  }
+ Here is the call graph for this function:

◆ delete()

ilTestExportGUI::delete ( )

Definition at line 278 of file class.ilTestExportGUI.php.

References ILIAS\Repository\ctrl(), ilFileUtils\delDir(), ILIAS\Survey\Mode\getId(), ilExportGUI\getParentGUI(), and ILIAS\Repository\lng().

278  : void
279  {
280  $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
281  $archiveDir = $archiver->getZipExportDirectory();
282 
283  $export_dir = $this->obj->getExportDirectory();
284  foreach ($this->selected_files as $file) {
285  $file = basename($file);
286  $dir = substr($file, 0, strlen($file) - 4);
287 
288  if (!strlen($file) || !strlen($dir)) {
289  continue;
290  }
291 
292  $exp_file = $export_dir . '/' . $file;
293  $arc_file = $archiveDir . '/' . $file;
294  $exp_dir = $export_dir . '/' . $dir;
295  if (@is_file($exp_file)) {
296  unlink($exp_file);
297  }
298  if (@is_file($arc_file)) {
299  unlink($arc_file);
300  }
301  if (@is_dir($exp_dir)) {
302  ilFileUtils::delDir($exp_dir);
303  }
304  }
305  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_deleted_export_files'), true);
306  $this->ctrl->redirect($this, 'listExportFiles');
307  }
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
Class ilTestArchiver.
+ Here is the call graph for this function:

◆ download()

ilTestExportGUI::download ( )

Definition at line 249 of file class.ilTestExportGUI.php.

References $filename, ILIAS\Repository\ctrl(), ilFileDelivery\deliverFileLegacy(), ILIAS\Survey\Mode\getId(), ilExportGUI\getParentGUI(), and ILIAS\Repository\lng().

249  : void
250  {
251  if ($this->selected_files === []) {
252  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_checkbox'), true);
253  $this->ctrl->redirect($this, 'listExportFiles');
254  }
255 
256  if (count($this->selected_files) > 1) {
257  $this->tpl->setOnScreenMessage('info', $this->lng->txt('select_max_one_item'), true);
258  $this->ctrl->redirect($this, 'listExportFiles');
259  }
260 
261  $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
262 
263  $filename = basename($this->selected_files[0]);
264  $exportFile = $this->obj->getExportDirectory() . '/' . $filename;
265  $archiveFile = $archiver->getZipExportDirectory() . '/' . $filename;
266 
267  if (file_exists($exportFile)) {
269  }
270 
271  if (file_exists($archiveFile)) {
273  }
274 
275  $this->ctrl->redirect($this, 'listExportFiles');
276  }
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
$filename
Definition: buildRTE.php:78
Class ilTestArchiver.
+ Here is the call graph for this function:

◆ getExportTypeFromFileName()

ilTestExportGUI::getExportTypeFromFileName ( string  $export_file)
private

Definition at line 240 of file class.ilTestExportGUI.php.

References ILIAS\Repository\lng().

Referenced by listExportFiles().

241  {
242  $extension = strtoupper(pathinfo($export_file, PATHINFO_EXTENSION));
243  if (in_array($extension, ['XLSX', 'CSV', 'XLS'])) {
244  return $this->lng->txt('results');
245  }
246  return $extension;
247  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listExportFiles()

ilTestExportGUI::listExportFiles ( )

Definition at line 153 of file class.ilTestExportGUI.php.

References Vendor\Package\$c, $data, Vendor\Package\$f, buildExportTableGUI(), ILIAS\Repository\ctrl(), ilExportGUI\getCustomColumns(), ilExportGUI\getCustomMultiCommands(), getExportTypeFromFileName(), ilExportGUI\getFormats(), ILIAS\Survey\Mode\getId(), ilExportGUI\getParentGUI(), ILIAS\Repository\lng(), ilSelectInputGUI\setOptions(), and ILIAS\Repository\toolbar().

153  : void
154  {
155  $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
156 
157  if (count($this->getFormats()) > 1) {
158  foreach ($this->getFormats() as $f) {
159  $options[$f['key']] = $f['txt'];
160  }
161  $si = new ilSelectInputGUI($this->lng->txt('type'), 'format');
162  $si->setOptions($options);
163  $this->toolbar->addInputItem($si, true);
164  $this->toolbar->addFormButton($this->lng->txt('exp_create_file'), 'createExportFile');
165  } else {
166  $format = $this->getFormats()[0];
167  $this->toolbar->addFormButton(
168  $this->lng->txt('exp_create_file')
169  . ' (' . $format['txt'] . ')',
170  'create_' . $format['key']
171  );
172  }
173 
174  $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
175  $archive_dir = $archiver->getZipExportDirectory();
176  $archive_files = [];
177 
178  if (file_exists($archive_dir) && is_dir($archive_dir)) {
179  $archive_files = scandir($archive_dir);
180  }
181 
182  $export_dir = $this->obj->getExportDirectory();
183  $export_files = $this->obj->getExportFiles($export_dir);
184  $data = [];
185  if (count($export_files) > 0) {
186  foreach ($export_files as $exp_file) {
187  $file_arr = explode('__', $exp_file);
188  if ($file_arr[0] == $exp_file) {
189  continue;
190  }
191 
192  array_push(
193  $data,
194  [
195  'file' => $exp_file,
196  'size' => filesize($export_dir . '/' . $exp_file),
197  'timestamp' => $file_arr[0],
198  'type' => $this->getExportTypeFromFileName($exp_file)
199  ]
200  );
201  }
202  }
203 
204  if (count($archive_files) > 0) {
205  foreach ($archive_files as $exp_file) {
206  if ($exp_file == '.' || $exp_file == '..') {
207  continue;
208  }
209  $file_arr = explode('_', $exp_file);
210 
211  $data[] = [
212  'file' => $exp_file,
213  'size' => filesize($archive_dir . '/' . $exp_file),
214  'timestamp' => $file_arr[4],
215  'type' => $this->getExportTypeFromFileName($exp_file)
216  ];
217  }
218  }
219 
220  $table = $this->buildExportTableGUI();
221  $table->setSelectAllCheckbox('file');
222  foreach ($this->getCustomColumns() as $c) {
223  $table->addCustomColumn($c['txt'], $c['obj'], $c['func']);
224  }
225 
226  foreach ($this->getCustomMultiCommands() as $c) {
227  $table->addCustomMultiCommand($c['txt'], 'multi_' . $c['func']);
228  }
229 
230  $table->resetFormats();
231  foreach ($this->formats as $format) {
232  $table->addFormat($format['key']);
233  }
234 
235  $table->setData($data);
236  $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_manual_feedback_export_info'), true);
237  $this->tpl->setContent($table->getHTML());
238  }
This class represents a selection list property in a property form.
setOptions(array $a_options)
getExportTypeFromFileName(string $export_file)
Class ilTestArchiver.
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: