ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilTestExportGUI.php
Go to the documentation of this file.
1<?php
2
32{
33 private \ILIAS\Test\InternalRequestService $testrequest;
34
35 public function __construct($a_parent_gui, $a_main_obj = null)
36 {
37 global $DIC;
38 $component_factory = $DIC["component.factory"];
39 $this->testrequest = $DIC->test()->internal()->request();
40 parent::__construct($a_parent_gui, $a_main_obj);
41
42 #$this->addFormat('xml', $a_parent_gui->lng->txt('ass_create_export_file'), $this, 'createTestExport');
43 $this->addFormat('xml', $DIC->language()->txt('ass_create_export_file'));
44 $this->addFormat('xmlres', $DIC->language()->txt('ass_create_export_file_with_results'), $this, 'createTestExportWithResults');
45 $this->addFormat('csv', $DIC->language()->txt('ass_create_export_test_results'), $this, 'createTestResultsExport');
46 $this->addFormat('arc', $DIC->language()->txt('ass_create_export_test_archive'), $this, 'createTestArchiveExport');
47 foreach ($component_factory->getActivePluginsInSlot("texp") as $plugin) {
48 $plugin->setTest($this->obj);
49 $this->addFormat(
50 $plugin->getFormat(),
51 $plugin->getFormatLabel(),
52 $plugin,
53 'export'
54 );
55 }
56 }
57
62 {
63 $table = new ilTestExportTableGUI($this, 'listExportFiles', $this->obj);
64 return $table;
65 }
66
70 public function createTestExportWithResults()
71 {
76 global $DIC;
77 $ilAccess = $DIC['ilAccess'];
78 $lng = $DIC['lng'];
79 $ilCtrl = $DIC['ilCtrl'];
80
81 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
82 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
83 $ilCtrl->redirectByClass('iltestexportgui');
84 }
85
86 $expFactory = new ilTestExportFactory($this->obj);
87 $test_exp = $expFactory->getExporter('xml');
88 $test_exp->setResultExportingEnabledForTestExport(true);
89 $test_exp->buildExportFile();
90 $this->tpl->setOnScreenMessage('success', $lng->txt('exp_file_created'), true);
91 $ilCtrl->redirectByClass('iltestexportgui');
92 }
93
97 public function createTestResultsExport()
98 {
103 global $DIC;
104 $ilAccess = $DIC['ilAccess'];
105 $lng = $DIC['lng'];
106 $ilCtrl = $DIC['ilCtrl'];
107
108 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
109 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
110 $ilCtrl->redirectByClass('iltestexportgui');
111 }
112
113 $expFactory = new ilTestExportFactory($this->obj);
114 $test_exp = $expFactory->getExporter('results');
115 $test_exp->buildExportFile();
116 $this->tpl->setOnScreenMessage('success', $lng->txt('exp_file_created'), true);
117 $ilCtrl->redirectByClass('iltestexportgui');
118 }
119
120 public function createTestArchiveExport()
121 {
122 global $DIC;
123 $ilAccess = $DIC['ilAccess'];
124 $ilCtrl = $DIC['ilCtrl'];
125 $ilDB = $DIC['ilDB'];
126 $lng = $DIC['lng'];
127
128 if ($ilAccess->checkAccess("write", "", $this->obj->getRefId())) {
129 // prepare generation before contents are processed (for mathjax)
131
132 $evaluation = new ilTestEvaluation($ilDB, $this->obj->getTestId());
133 $allActivesPasses = $evaluation->getAllActivesPasses();
134 $participantData = new ilTestParticipantData($ilDB, $lng);
135 $participantData->setActiveIdsFilter(array_keys($allActivesPasses));
136 $participantData->load($this->obj->getTestId());
137
138 $archiveService = new ilTestArchiveService($this->obj);
139 $archiveService->setParticipantData($participantData);
140 $archiveService->archivePassesByActives($allActivesPasses);
141
142 $test_id = $this->obj->getId();
143 $test_ref = $this->obj->getRefId();
144 $archive_exp = new ilTestArchiver($test_id, $test_ref);
145
146 $scoring = new ilTestScoring($this->obj);
147 $best_solution = $scoring->calculateBestSolutionForTest();
148
149 $tmpFileName = ilFileUtils::ilTempnam();
150 if (!is_dir($tmpFileName)) {
151 ilFileUtils::makeDirParents($tmpFileName);
152 }
153
154 $directory_name = realpath($tmpFileName);
155 $file_name = $directory_name . DIRECTORY_SEPARATOR . 'Best_Solution.pdf';
156
157 $generator = new ilTestPDFGenerator();
158 $generator->generatePDF($best_solution, ilTestPDFGenerator::PDF_OUTPUT_FILE, $file_name, PDF_USER_RESULT);
159 $archive_exp->handInTestBestSolution($best_solution, $file_name);
160 ilFileUtils::delDir($directory_name);
161
162 $archive_exp->updateTestArchive();
163 $archive_exp->compressTestArchive();
164 } else {
165 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
166 }
167 $ilCtrl->redirectByClass('iltestexportgui');
168 }
169
170 public function listExportFiles(): void
171 {
172 global $DIC;
173 $ilAccess = $DIC['ilAccess'];
174 $tpl = $DIC['tpl'];
175 $ilToolbar = $DIC['ilToolbar'];
176 $ilCtrl = $DIC['ilCtrl'];
177 $lng = $DIC['lng'];
178
179 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
180 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
181 $ilCtrl->redirectByClass(ilObjTestGUI::class);
182 }
183
184 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
185
186 if (count($this->getFormats()) > 1) {
187 foreach ($this->getFormats() as $f) {
188 $options[$f["key"]] = $f["txt"];
189 }
190 $si = new ilSelectInputGUI($lng->txt("type"), "format");
191 $si->setOptions($options);
192 $ilToolbar->addInputItem($si, true);
193 $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
194 } else {
195 $format = $this->getFormats();
196 $format = $format[0];
197 $ilToolbar->addFormButton($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", "create_" . $format["key"]);
198 }
199
200 $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
201 $archive_dir = $archiver->getZipExportDirectory();
202 $archive_files = array();
203
204 if (file_exists($archive_dir) && is_dir($archive_dir)) {
205 $archive_files = scandir($archive_dir);
206 }
207
208 $export_dir = $this->obj->getExportDirectory();
209 $export_files = $this->obj->getExportFiles($export_dir);
210 $data = array();
211 if (count($export_files) > 0) {
212 foreach ($export_files as $exp_file) {
213 $file_arr = explode("__", $exp_file);
214 if ($file_arr[0] == $exp_file) {
215 continue;
216 }
217
218 array_push($data, array(
219 'file' => $exp_file,
220 'size' => filesize($export_dir . "/" . $exp_file),
221 'timestamp' => $file_arr[0],
222 'type' => $this->getExportTypeFromFileName($exp_file)
223 ));
224 }
225 }
226
227 if (count($archive_files) > 0) {
228 foreach ($archive_files as $exp_file) {
229 if ($exp_file == '.' || $exp_file == '..') {
230 continue;
231 }
232 $file_arr = explode("_", $exp_file);
233
234 $data[] = [
235 'file' => $exp_file,
236 'size' => filesize($archive_dir . "/" . $exp_file),
237 'timestamp' => $file_arr[4],
238 'type' => $this->getExportTypeFromFileName($exp_file)
239 ];
240 }
241 }
242
243 $table = $this->buildExportTableGUI();
244 $table->setSelectAllCheckbox("file");
245 foreach ($this->getCustomColumns() as $c) {
246 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
247 }
248
249 foreach ($this->getCustomMultiCommands() as $c) {
250 $table->addCustomMultiCommand($c["txt"], "multi_" . $c["func"]);
251 }
252
253 $table->resetFormats();
254 foreach ($this->formats as $format) {
255 $table->addFormat($format['key']);
256 }
257
258 $table->setData($data);
259 $this->tpl->setOnScreenMessage('info', $lng->txt('no_manual_feedback_export_info'), true);
260 $tpl->setContent($table->getHTML());
261 }
262
263 private function getExportTypeFromFileName(string $export_file)
264 {
265 $extension = strtoupper(pathinfo($export_file, PATHINFO_EXTENSION));
266 if (in_array($extension, ['XLSX', 'CSV', 'XLS'])) {
267 return $this->lng->txt('results');
268 }
269 return $extension;
270 }
271
272 public function download(): void
273 {
278 global $DIC;
279 $ilAccess = $DIC['ilAccess'];
280 $lng = $DIC['lng'];
281 $ilCtrl = $DIC['ilCtrl'];
282 $file = array();
283
284 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
285 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
286 $ilCtrl->redirectByClass(ilObjTestGUI::class);
287 }
288
289 if ($this->testrequest->isset('file') && $this->testrequest->raw('file')) {
290 $file = array($this->testrequest->raw('file'));
291 }
292
293 if ($file === array()) {
294 $this->tpl->setOnScreenMessage('info', $lng->txt('no_checkbox'), true);
295 $ilCtrl->redirect($this, 'listExportFiles');
296 }
297
298 if (count($file) > 1) {
299 $this->tpl->setOnScreenMessage('info', $lng->txt('select_max_one_item'), true);
300 $ilCtrl->redirect($this, 'listExportFiles');
301 }
302
303 $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
304
305 $filename = basename($file[0]);
306 $exportFile = $this->obj->getExportDirectory() . '/' . $filename;
307 $archiveFile = $archiver->getZipExportDirectory() . '/' . $filename;
308
309 if (file_exists($exportFile)) {
311 }
312
313 if (file_exists($archiveFile)) {
315 }
316
317 $ilCtrl->redirect($this, 'listExportFiles');
318 }
319
323 public function delete(): void
324 {
329 global $DIC;
330 $ilAccess = $DIC['ilAccess'];
331 $lng = $DIC['lng'];
332 $ilCtrl = $DIC['ilCtrl'];
333
334 if (!$ilAccess->checkAccess('write', '', $this->obj->getRefId())) {
335 $this->tpl->setOnScreenMessage('info', "cannot_export_archive", true);
336 $ilCtrl->redirectByClass(ilObjTestGUI::class);
337 }
338
339 $archiver = new ilTestArchiver($this->getParentGUI()->getTestObject()->getId());
340 $archiveDir = $archiver->getZipExportDirectory();
341
342 $export_dir = $this->obj->getExportDirectory();
343 foreach ($_POST['file'] as $file) {
344 $file = basename($file);
345 $dir = substr($file, 0, strlen($file) - 4);
346
347 if (!strlen($file) || !strlen($dir)) {
348 continue;
349 }
350
351 $exp_file = $export_dir . '/' . $file;
352 $arc_file = $archiveDir . '/' . $file;
353 $exp_dir = $export_dir . '/' . $dir;
354 if (@is_file($exp_file)) {
355 unlink($exp_file);
356 }
357 if (@is_file($arc_file)) {
358 unlink($arc_file);
359 }
360 if (@is_dir($exp_dir)) {
361 ilFileUtils::delDir($exp_dir);
362 }
363 }
364 $this->tpl->setOnScreenMessage('success', $lng->txt('msg_deleted_export_files'), true);
365 $ilCtrl->redirect($this, 'listExportFiles');
366 }
367}
$filename
Definition: buildRTE.php:78
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFormat(string $a_key, string $a_txt="", object $a_call_obj=null, string $a_call_func="")
download()
Download file.
ilLanguage $lng
ilGlobalTemplateInterface $tpl
static deliverFileLegacy(string $a_file, ?string $a_filename=null, ?string $a_mime=null, ?bool $isInline=false, ?bool $removeAfterDelivery=false, ?bool $a_exit_after=true)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareGenerationRequest(string $service, string $purpose)
Prepare the content processing for a PDF generation request This function should be called as in a re...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Test InternalRequestService $testrequest
__construct($a_parent_gui, $a_main_obj=null)
getExportTypeFromFileName(string $export_file)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
const PDF_USER_RESULT
PDF Purposes.
setContent(string $a_html)
Sets content for standard template.
$format
Definition: metadata.php:235
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc