ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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('xmlres', $a_parent_gui->lng->txt('ass_create_export_file_with_results'), $this, 'createTestExportWithResults');
28 $this->addFormat('csv', $a_parent_gui->lng->txt('ass_create_export_test_results'), $this, 'createTestResultsExport');
29 $this->addFormat( 'arc', $a_parent_gui->lng->txt( 'ass_create_export_test_archive' ), $this, 'createTestArchiveExport');
30 $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, 'Test', 'texp');
31 foreach($pl_names as $pl)
32 {
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 createTestExport()
61 {
66 global $lng, $ilCtrl;
67
68 require_once 'Modules/Test/classes/class.ilTestExport.php';
69 $test_exp = new ilTestExport($this->obj, 'xml');
70 $test_exp->buildExportFile();
71 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
72 $ilCtrl->redirectByClass('iltestexportgui');
73 }
74
78 public function createTestExportWithResults()
79 {
84 global $lng, $ilCtrl;
85
86 require_once 'Modules/Test/classes/class.ilTestExport.php';
87 $test_exp = new ilTestExport($this->obj, 'xml');
88 $test_exp->setResultExportingEnabledForTestExport(true);
89 $test_exp->buildExportFile();
90 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
91 $ilCtrl->redirectByClass('iltestexportgui');
92 }
93
97 public function createTestResultsExport()
98 {
103 global $lng, $ilCtrl;
104
105 require_once 'Modules/Test/classes/class.ilTestExport.php';
106 $test_exp = new ilTestExport($this->obj, 'results');
107 $test_exp->buildExportFile();
108 ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
109 $ilCtrl->redirectByClass('iltestexportgui');
110 }
111
113 {
114 global $ilAccess, $ilCtrl, $ilDB, $lng;
115
116 if ($ilAccess->checkAccess("write", "", $this->obj->ref_id))
117 {
118 require_once 'Modules/Test/classes/class.ilTestEvaluation.php';
119 $evaluation = new ilTestEvaluation($ilDB, $this->obj->getTestId());
120 $allActivesPasses = $evaluation->getAllActivesPasses();
121
122 require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
123 $participantData = new ilTestParticipantData($ilDB, $lng);
124 $participantData->setActiveIds(array_keys($allActivesPasses));
125 $participantData->load($this->obj->getTestId());
126
127 require_once 'Modules/Test/classes/class.ilTestArchiveService.php';
128 $archiveService = new ilTestArchiveService($this->obj);
129 $archiveService->setParticipantData($participantData);
130 $archiveService->archivePassesByActives($allActivesPasses);
131
132 include_once("./Modules/Test/classes/class.ilTestArchiver.php");
133 $test_id = $this->obj->getId();
134 $archive_exp = new ilTestArchiver($test_id);
135
136 require_once './Modules/Test/classes/class.ilTestScoring.php';
137 $scoring = new ilTestScoring($this->obj);
138 $best_solution = $scoring->calculateBestSolutionForTest();
139
140 $tmpFileName = ilUtil::ilTempnam();
141 if(!is_dir($tmpFileName))
142 {
143 ilUtil::makeDirParents($tmpFileName);
144 }
145
146 $directory_name = realpath($tmpFileName);
147 $file_name = $directory_name . DIRECTORY_SEPARATOR . 'Best_Solution.pdf';
148
149 require_once './Modules/Test/classes/class.ilTestPDFGenerator.php';
150 $generator = new ilTestPDFGenerator();
151 $generator->generatePDF($best_solution, ilTestPDFGenerator::PDF_OUTPUT_FILE, $file_name);
152 $archive_exp->handInTestBestSolution($best_solution, $file_name);
153 ilUtil::delDir($directory_name);
154
155 $archive_exp->updateTestArchive();
156 $archive_exp->compressTestArchive();
157 }
158 else
159 {
160 ilUtil::sendInfo("cannot_export_archive", TRUE);
161 }
162 $ilCtrl->redirectByClass('iltestexportgui');
163 }
164
165 public function listExportFiles()
166 {
167 global $tpl, $ilToolbar, $ilCtrl, $lng;
168
169 $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
170
171 if(count($this->getFormats()) > 1)
172 {
173 foreach($this->getFormats() as $f)
174 {
175 $options[$f["key"]] = $f["txt"];
176 }
177 include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
178 $si = new ilSelectInputGUI($lng->txt("type"), "format");
179 $si->setOptions($options);
180 $ilToolbar->addInputItem($si, true);
181 $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
182 }
183 else
184 {
185 $format = $this->getFormats();
186 $format = $format[0];
187 $ilToolbar->addFormButton($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", "create_" . $format["key"]);
188 }
189
190 require_once 'class.ilTestArchiver.php';
191 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
192 $archive_dir = $archiver->getZipExportDirectory();
193 $archive_files = array();
194 if( file_exists($archive_dir) && is_dir($archive_dir) )
195 {
196 $archive_files = scandir($archive_dir);
197 }
198
199 $export_dir = $this->obj->getExportDirectory();
200 $export_files = $this->obj->getExportFiles($export_dir);
201 $data = array();
202 if(count($export_files) > 0)
203 {
204 foreach($export_files as $exp_file)
205 {
206 $file_arr = explode("__", $exp_file);
207 array_push($data, array(
208 'file' => $exp_file,
209 'size' => filesize($export_dir . "/" . $exp_file),
210 'timestamp' => $file_arr[0]
211 ));
212 }
213 }
214
215 if(count($archive_files) > 0)
216 {
217 foreach($archive_files as $exp_file)
218 {
219 if ($exp_file == '.' || $exp_file == '..')
220 {
221 continue;
222 }
223 $file_arr = explode("_", $exp_file);
224 array_push($data, array(
225 'file' => $exp_file,
226 'size' => filesize($archive_dir."/".$exp_file),
227 'timestamp' => $file_arr[4]
228 ));
229 }
230 }
231
232 $table = $this->buildExportTableGUI();
233 $table->setSelectAllCheckbox("file");
234 foreach($this->getCustomColumns() as $c)
235 {
236 $table->addCustomColumn($c["txt"], $c["obj"], $c["func"]);
237 }
238
239 foreach($this->getCustomMultiCommands() as $c)
240 {
241 $table->addCustomMultiCommand($c["txt"], "multi_".$c["func"]);
242 }
243
244 $table->setData($data);
245 $tpl->setContent($table->getHTML());
246 }
247
248 public function download()
249 {
254 global $lng, $ilCtrl;
255
256 if(isset($_GET['file']) && $_GET['file'])
257 {
258 $_POST['file'] = array($_GET['file']);
259 }
260
261 if(!isset($_POST['file']))
262 {
263 ilUtil::sendInfo($lng->txt('no_checkbox'), true);
264 $ilCtrl->redirect($this, 'listExportFiles');
265 }
266
267 if(count($_POST['file']) > 1)
268 {
269 ilUtil::sendInfo($lng->txt('select_max_one_item'), true);
270 $ilCtrl->redirect($this, 'listExportFiles');
271 }
272
273 require_once 'class.ilTestArchiver.php';
274 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
275
276 $filename = basename($_POST["file"][0]);
277 $exportFile = $this->obj->getExportDirectory().'/'.$filename;
278 $archiveFile = $archiver->getZipExportDirectory().'/'.$filename;
279
280 if( file_exists($exportFile) )
281 {
282 ilUtil::deliverFile($exportFile, $filename);
283 }
284
285 if( file_exists($archiveFile) )
286 {
287 ilUtil::deliverFile($archiveFile, $filename);
288 }
289
290 $ilCtrl->redirect($this, 'listExportFiles');
291 }
292
296 public function delete()
297 {
302 global $lng, $ilCtrl;
303
304 require_once 'class.ilTestArchiver.php';
305 $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
306 $archiveDir = $archiver->getZipExportDirectory();
307
308 $export_dir = $this->obj->getExportDirectory();
309 foreach($_POST['file'] as $file)
310 {
311 $file = basename($file);
312 $dir = substr($file, 0, strlen($file) - 4);
313
314 if( !strlen($file) || !strlen($dir) )
315 {
316 continue;
317 }
318
319 $exp_file = $export_dir.'/'.$file;
320 $arc_file = $archiveDir.'/'.$file;
321 $exp_dir = $export_dir.'/'.$dir;
322 if(@is_file($exp_file))
323 {
324 unlink($exp_file);
325 }
326 if(@is_file($arc_file))
327 {
328 unlink($arc_file);
329 }
330 if(@is_dir($exp_dir))
331 {
332 ilUtil::delDir($exp_dir);
333 }
334 }
335 ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
336 $ilCtrl->redirect($this, 'listExportFiles');
337 }
338}
print $file
global $tpl
Definition: ilias.php:8
$filename
Definition: buildRTE.php:89
$_GET["client_id"]
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 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.
Export class for tests.
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.
$_POST['username']
Definition: cron.php:12
$data
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
global $ilDB
if(!is_array($argv)) $options