ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
33 {
37 $plugin = ilPluginAdmin::getPluginObject(IL_COMP_MODULE, 'Test', 'texp', $pl);
38 $plugin->setTest($this->obj);
39 $this->addFormat(
40 $plugin->getFormat(),
41 $plugin->getFormatLabel(),
42 $plugin,
43 'export'
44 );
45 }
46 }
47
51 protected function buildExportTableGUI()
52 {
53 require_once 'Modules/Test/classes/tables/class.ilTestExportTableGUI.php';
54 $table = new ilTestExportTableGUI($this, 'listExportFiles', $this->obj);
55 return $table;
56 }
57
61 public function createTestExportWithResults()
62 {
67 global $lng, $ilCtrl;
68
69 require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
70 $expFactory = new ilTestExportFactory($this->obj);
71 $test_exp = $expFactory->getExporter('xml');
72 $test_exp->setResultExportingEnabledForTestExport(true);
73 $test_exp->buildExportFile();
74 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
75 $ilCtrl->redirectByClass('iltestexportgui');
76 }
77
81 public function createTestResultsExport()
82 {
87 global $lng, $ilCtrl;
88
89 require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
90 $expFactory = new ilTestExportFactory($this->obj);
91 $test_exp = $expFactory->getExporter('results');
92 $test_exp->buildExportFile();
93 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
94 $ilCtrl->redirectByClass('iltestexportgui');
95 }
96
98 {
99 global $ilAccess, $ilCtrl, $ilDB, $lng;
100
101 if ($ilAccess->checkAccess("write", "", $this->obj->ref_id))
102 {
103 // prepare generation before contents are processed (for mathjax)
104 require_once 'Services/PDFGeneration/classes/class.ilPDFGeneration.php';
106
107 require_once 'Modules/Test/classes/class.ilTestEvaluation.php';
108 $evaluation = new ilTestEvaluation($ilDB, $this->obj->getTestId());
109 $allActivesPasses = $evaluation->getAllActivesPasses();
110
111 require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
112 $participantData = new ilTestParticipantData($ilDB, $lng);
113 $participantData->setActiveIds(array_keys($allActivesPasses));
114 $participantData->load($this->obj->getTestId());
115
116 require_once 'Modules/Test/classes/class.ilTestArchiveService.php';
117 $archiveService = new ilTestArchiveService($this->obj);
118 $archiveService->setParticipantData($participantData);
119 $archiveService->archivePassesByActives($allActivesPasses);
120
121 include_once("./Modules/Test/classes/class.ilTestArchiver.php");
122 $test_id = $this->obj->getId();
123 $archive_exp = new ilTestArchiver($test_id);
124
125 require_once './Modules/Test/classes/class.ilTestScoring.php';
126 $scoring = new ilTestScoring($this->obj);
127 $best_solution = $scoring->calculateBestSolutionForTest();
128
129 $tmpFileName = ilUtil::ilTempnam();
130 if(!is_dir($tmpFileName))
131 {
132 ilUtil::makeDirParents($tmpFileName);
133 }
134
135 $directory_name = realpath($tmpFileName);
136 $file_name = $directory_name . DIRECTORY_SEPARATOR . 'Best_Solution.pdf';
137
138 require_once './Modules/Test/classes/class.ilTestPDFGenerator.php';
139 $generator = new ilTestPDFGenerator();
140 $generator->generatePDF($best_solution, ilTestPDFGenerator::PDF_OUTPUT_FILE, $file_name);
141 $archive_exp->handInTestBestSolution($best_solution, $file_name);
142 ilUtil::delDir($directory_name);
143
144 $archive_exp->updateTestArchive();
145 $archive_exp->compressTestArchive();
146 }
147 else
148 {
149 ilUtil::sendInfo("cannot_export_archive", TRUE);
150 }
151 $ilCtrl->redirectByClass('iltestexportgui');
152 }
153
154 public function listExportFiles()
155 {
156 global $tpl, $ilToolbar, $ilCtrl, $lng;
157
158 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
159
160 if(count($this->getFormats()) > 1)
161 {
162 foreach($this->getFormats() as $f)
163 {
164 $options[$f["key"]] = $f["txt"];
165 }
166 include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
167 $si = new ilSelectInputGUI($lng->txt("type"), "format");
168 $si->setOptions($options);
169 $ilToolbar->addInputItem($si, true);
170 $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
171 }
172 else
173 {
174 $format = $this->getFormats();
175 $format = $format[0];
176 $ilToolbar->addFormButton($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", "create_" . $format["key"]);
177 }
178
179 require_once 'class.ilTestArchiver.php';
180 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
181 $archive_dir = $archiver->getZipExportDirectory();
182 $archive_files = array();
183 if( file_exists($archive_dir) && is_dir($archive_dir) )
184 {
185 $archive_files = scandir($archive_dir);
186 }
187
188 $export_dir = $this->obj->getExportDirectory();
189 $export_files = $this->obj->getExportFiles($export_dir);
190 $data = array();
191 if(count($export_files) > 0)
192 {
193 foreach($export_files as $exp_file)
194 {
195 $file_arr = explode("__", $exp_file);
196 array_push($data, array(
197 'file' => $exp_file,
198 'size' => filesize($export_dir . "/" . $exp_file),
199 'timestamp' => $file_arr[0]
200 ));
201 }
202 }
203
204 if(count($archive_files) > 0)
205 {
206 foreach($archive_files as $exp_file)
207 {
208 if ($exp_file == '.' || $exp_file == '..')
209 {
210 continue;
211 }
212 $file_arr = explode("_", $exp_file);
213 array_push($data, array(
214 'file' => $exp_file,
215 'size' => filesize($archive_dir."/".$exp_file),
216 'timestamp' => $file_arr[4]
217 ));
218 }
219 }
220
221 $table = $this->buildExportTableGUI();
222 $table->setSelectAllCheckbox("file");
223 foreach($this->getCustomColumns() as $c)
224 {
225 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
226 }
227
228 foreach($this->getCustomMultiCommands() as $c)
229 {
230 $table->addCustomMultiCommand($c["txt"], "multi_".$c["func"]);
231 }
232
233 $table->setData($data);
234 $tpl->setContent($table->getHTML());
235 }
236
237 public function download()
238 {
243 global $lng, $ilCtrl;
244
245 if(isset($_GET['file']) && $_GET['file'])
246 {
247 $_POST['file'] = array($_GET['file']);
248 }
249
250 if(!isset($_POST['file']))
251 {
252 ilUtil::sendInfo($lng->txt('no_checkbox'), true);
253 $ilCtrl->redirect($this, 'listExportFiles');
254 }
255
256 if(count($_POST['file']) > 1)
257 {
258 ilUtil::sendInfo($lng->txt('select_max_one_item'), true);
259 $ilCtrl->redirect($this, 'listExportFiles');
260 }
261
262 require_once 'class.ilTestArchiver.php';
263 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
264
265 $filename = basename($_POST["file"][0]);
266 $exportFile = $this->obj->getExportDirectory().'/'.$filename;
267 $archiveFile = $archiver->getZipExportDirectory().'/'.$filename;
268
269 if( file_exists($exportFile) )
270 {
271 ilUtil::deliverFile($exportFile, $filename);
272 }
273
274 if( file_exists($archiveFile) )
275 {
276 ilUtil::deliverFile($archiveFile, $filename);
277 }
278
279 $ilCtrl->redirect($this, 'listExportFiles');
280 }
281
285 public function delete()
286 {
291 global $lng, $ilCtrl;
292
293 require_once 'class.ilTestArchiver.php';
294 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
295 $archiveDir = $archiver->getZipExportDirectory();
296
297 $export_dir = $this->obj->getExportDirectory();
298 foreach($_POST['file'] as $file)
299 {
300 $file = basename($file);
301 $dir = substr($file, 0, strlen($file) - 4);
302
303 if( !strlen($file) || !strlen($dir) )
304 {
305 continue;
306 }
307
308 $exp_file = $export_dir.'/'.$file;
309 $arc_file = $archiveDir.'/'.$file;
310 $exp_dir = $export_dir.'/'.$dir;
311 if(@is_file($exp_file))
312 {
313 unlink($exp_file);
314 }
315 if(@is_file($arc_file))
316 {
317 unlink($arc_file);
318 }
319 if(@is_dir($exp_dir))
320 {
321 ilUtil::delDir($exp_dir);
322 }
323 }
324 ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
325 $ilCtrl->redirect($this, 'listExportFiles');
326 }
327}
global $tpl
Definition: ilias.php:8
$_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 makeDirParents($a_dir)
Create a new directory and all parent directories.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $ilDB
if(!is_array($argv)) $options