ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilTestExportGUI.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/Export/classes/class.ilExportGUI.php';
5
19{
20 public function __construct($a_parent_gui, $a_main_obj = null)
21 {
22 global $ilPluginAdmin;
23
24 parent::__construct($a_parent_gui, $a_main_obj);
25
26 #$this->addFormat('xml', $a_parent_gui->lng->txt('ass_create_export_file'), $this, 'createTestExport');
27 $this->addFormat('xml', $a_parent_gui->lng->txt('ass_create_export_file'));
28 $this->addFormat('xmlres', $a_parent_gui->lng->txt('ass_create_export_file_with_results'), $this, 'createTestExportWithResults');
29 $this->addFormat('csv', $a_parent_gui->lng->txt('ass_create_export_test_results'), $this, 'createTestResultsExport');
30 $this->addFormat('arc', $a_parent_gui->lng->txt('ass_create_export_test_archive'), $this, 'createTestArchiveExport');
31 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, 'Test', 'texp');
32 foreach ($pl_names as $pl) {
36 $plugin = ilPluginAdmin::getPluginObject(IL_COMP_MODULE, 'Test', 'texp', $pl);
37 $plugin->setTest($this->obj);
38 $this->addFormat(
39 $plugin->getFormat(),
40 $plugin->getFormatLabel(),
41 $plugin,
42 'export'
43 );
44 }
45 }
46
50 protected function buildExportTableGUI()
51 {
52 require_once 'Modules/Test/classes/tables/class.ilTestExportTableGUI.php';
53 $table = new ilTestExportTableGUI($this, 'listExportFiles', $this->obj);
54 return $table;
55 }
56
60 public function createTestExportWithResults()
61 {
66 global $lng, $ilCtrl;
67
68 require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
69 $expFactory = new ilTestExportFactory($this->obj);
70 $test_exp = $expFactory->getExporter('xml');
71 $test_exp->setResultExportingEnabledForTestExport(true);
72 $test_exp->buildExportFile();
73 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
74 $ilCtrl->redirectByClass('iltestexportgui');
75 }
76
80 public function createTestResultsExport()
81 {
86 global $lng, $ilCtrl;
87
88 require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
89 $expFactory = new ilTestExportFactory($this->obj);
90 $test_exp = $expFactory->getExporter('results');
91 $test_exp->buildExportFile();
92 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
93 $ilCtrl->redirectByClass('iltestexportgui');
94 }
95
96 public function createTestArchiveExport()
97 {
98 global $ilAccess, $ilCtrl, $ilDB, $lng;
99
100 if ($ilAccess->checkAccess("write", "", $this->obj->ref_id)) {
101 // prepare generation before contents are processed (for mathjax)
102 require_once 'Services/PDFGeneration/classes/class.ilPDFGeneration.php';
104
105 require_once 'Modules/Test/classes/class.ilTestEvaluation.php';
106 $evaluation = new ilTestEvaluation($ilDB, $this->obj->getTestId());
107 $allActivesPasses = $evaluation->getAllActivesPasses();
108
109 require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
110 $participantData = new ilTestParticipantData($ilDB, $lng);
111 $participantData->setActiveIds(array_keys($allActivesPasses));
112 $participantData->load($this->obj->getTestId());
113
114 require_once 'Modules/Test/classes/class.ilTestArchiveService.php';
115 $archiveService = new ilTestArchiveService($this->obj);
116 $archiveService->setParticipantData($participantData);
117 $archiveService->archivePassesByActives($allActivesPasses);
118
119 include_once("./Modules/Test/classes/class.ilTestArchiver.php");
120 $test_id = $this->obj->getId();
121 $archive_exp = new ilTestArchiver($test_id);
122
123 require_once './Modules/Test/classes/class.ilTestScoring.php';
124 $scoring = new ilTestScoring($this->obj);
125 $best_solution = $scoring->calculateBestSolutionForTest();
126
127 $tmpFileName = ilUtil::ilTempnam();
128 if (!is_dir($tmpFileName)) {
129 ilUtil::makeDirParents($tmpFileName);
130 }
131
132 $directory_name = realpath($tmpFileName);
133 $file_name = $directory_name . DIRECTORY_SEPARATOR . 'Best_Solution.pdf';
134
135 require_once './Modules/Test/classes/class.ilTestPDFGenerator.php';
136 $generator = new ilTestPDFGenerator();
137 $generator->generatePDF($best_solution, ilTestPDFGenerator::PDF_OUTPUT_FILE, $file_name, PDF_USER_RESULT);
138 $archive_exp->handInTestBestSolution($best_solution, $file_name);
139 ilUtil::delDir($directory_name);
140
141 $archive_exp->updateTestArchive();
142 $archive_exp->compressTestArchive();
143 } else {
144 ilUtil::sendInfo("cannot_export_archive", true);
145 }
146 $ilCtrl->redirectByClass('iltestexportgui');
147 }
148
149 public function listExportFiles()
150 {
151 global $tpl, $ilToolbar, $ilCtrl, $lng;
152
153 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
154
155 if (count($this->getFormats()) > 1) {
156 foreach ($this->getFormats() as $f) {
157 $options[$f["key"]] = $f["txt"];
158 }
159 include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
160 $si = new ilSelectInputGUI($lng->txt("type"), "format");
161 $si->setOptions($options);
162 $ilToolbar->addInputItem($si, true);
163 $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
164 } else {
165 $format = $this->getFormats();
166 $format = $format[0];
167 $ilToolbar->addFormButton($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", "create_" . $format["key"]);
168 }
169
170 require_once 'class.ilTestArchiver.php';
171 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
172 $archive_dir = $archiver->getZipExportDirectory();
173 $archive_files = array();
174 if (file_exists($archive_dir) && is_dir($archive_dir)) {
175 $archive_files = scandir($archive_dir);
176 }
177
178 $export_dir = $this->obj->getExportDirectory();
179 $export_files = $this->obj->getExportFiles($export_dir);
180 $data = array();
181 if (count($export_files) > 0) {
182 foreach ($export_files as $exp_file) {
183 $file_arr = explode("__", $exp_file);
184 array_push($data, array(
185 'file' => $exp_file,
186 'size' => filesize($export_dir . "/" . $exp_file),
187 'timestamp' => $file_arr[0]
188 ));
189 }
190 }
191
192 if (count($archive_files) > 0) {
193 foreach ($archive_files as $exp_file) {
194 if ($exp_file == '.' || $exp_file == '..') {
195 continue;
196 }
197 $file_arr = explode("_", $exp_file);
198 array_push($data, array(
199 'file' => $exp_file,
200 'size' => filesize($archive_dir . "/" . $exp_file),
201 'timestamp' => $file_arr[4]
202 ));
203 }
204 }
205
206 $table = $this->buildExportTableGUI();
207 $table->setSelectAllCheckbox("file");
208 foreach ($this->getCustomColumns() as $c) {
209 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
210 }
211
212 foreach ($this->getCustomMultiCommands() as $c) {
213 $table->addCustomMultiCommand($c["txt"], "multi_" . $c["func"]);
214 }
215
216 $table->setData($data);
217 $tpl->setContent($table->getHTML());
218 }
219
220 public function download()
221 {
226 global $lng, $ilCtrl;
227
228 if (isset($_GET['file']) && $_GET['file']) {
229 $_POST['file'] = array($_GET['file']);
230 }
231
232 if (!isset($_POST['file'])) {
233 ilUtil::sendInfo($lng->txt('no_checkbox'), true);
234 $ilCtrl->redirect($this, 'listExportFiles');
235 }
236
237 if (count($_POST['file']) > 1) {
238 ilUtil::sendInfo($lng->txt('select_max_one_item'), true);
239 $ilCtrl->redirect($this, 'listExportFiles');
240 }
241
242 require_once 'class.ilTestArchiver.php';
243 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
244
245 $filename = basename($_POST["file"][0]);
246 $exportFile = $this->obj->getExportDirectory() . '/' . $filename;
247 $archiveFile = $archiver->getZipExportDirectory() . '/' . $filename;
248
249 if (file_exists($exportFile)) {
250 ilUtil::deliverFile($exportFile, $filename);
251 }
252
253 if (file_exists($archiveFile)) {
254 ilUtil::deliverFile($archiveFile, $filename);
255 }
256
257 $ilCtrl->redirect($this, 'listExportFiles');
258 }
259
263 public function delete()
264 {
269 global $lng, $ilCtrl;
270
271 require_once 'class.ilTestArchiver.php';
272 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
273 $archiveDir = $archiver->getZipExportDirectory();
274
275 $export_dir = $this->obj->getExportDirectory();
276 foreach ($_POST['file'] as $file) {
277 $file = basename($file);
278 $dir = substr($file, 0, strlen($file) - 4);
279
280 if (!strlen($file) || !strlen($dir)) {
281 continue;
282 }
283
284 $exp_file = $export_dir . '/' . $file;
285 $arc_file = $archiveDir . '/' . $file;
286 $exp_dir = $export_dir . '/' . $dir;
287 if (@is_file($exp_file)) {
288 unlink($exp_file);
289 }
290 if (@is_file($arc_file)) {
291 unlink($arc_file);
292 }
293 if (@is_dir($exp_dir)) {
294 ilUtil::delDir($exp_dir);
295 }
296 }
297 ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
298 $ilCtrl->redirect($this, 'listExportFiles');
299 }
300}
$tpl
Definition: ilias.php:10
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_MODULE
Export User Interface Class.
addFormat($a_key, $a_txt="", $a_call_obj=null, $a_call_func="")
Add formats.
getParentGUI()
get parent gui
getCustomColumns()
Get custom columns.
__construct($a_parent_gui, $a_main_obj=null)
Constuctor.
getFormats()
Get formats.
getCustomMultiCommands()
Get custom multi commands.
download()
Download file.
static prepareGeneration()
Prepare the PDF generation This initializes the purpose for MathJax rendering It has to be called bef...
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
This class represents a selection list property in a property form.
Class ilTestArchiver.
Export User Interface Class.
listExportFiles()
List export files.
Class ilTestPDFGenerator.
Class ilTestScoring.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
const PDF_USER_RESULT
PDF Purposes.
$format
Definition: metadata.php:141
global $lng
Definition: privfeed.php:17
if(empty($password)) $table
Definition: pwgen.php:24
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $ilDB