ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once 'Services/Export/classes/class.ilExportGUI.php';
5 
19 {
20  public function __construct($a_parent_gui, $a_main_obj = null)
21  {
22  global $DIC;
23  $ilPluginAdmin = $DIC['ilPluginAdmin'];
24 
25  parent::__construct($a_parent_gui, $a_main_obj);
26 
27  #$this->addFormat('xml', $a_parent_gui->lng->txt('ass_create_export_file'), $this, 'createTestExport');
28  $this->addFormat('xml', $a_parent_gui->lng->txt('ass_create_export_file'));
29  $this->addFormat('xmlres', $a_parent_gui->lng->txt('ass_create_export_file_with_results'), $this, 'createTestExportWithResults');
30  $this->addFormat('csv', $a_parent_gui->lng->txt('ass_create_export_test_results'), $this, 'createTestResultsExport');
31  $this->addFormat('arc', $a_parent_gui->lng->txt('ass_create_export_test_archive'), $this, 'createTestArchiveExport');
32  $pl_names = $ilPluginAdmin->getActivePluginsForSlot(IL_COMP_MODULE, 'Test', 'texp');
33  foreach ($pl_names as $pl) {
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 $DIC;
68  $lng = $DIC['lng'];
69  $ilCtrl = $DIC['ilCtrl'];
70 
71  require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
72  $expFactory = new ilTestExportFactory($this->obj);
73  $test_exp = $expFactory->getExporter('xml');
74  $test_exp->setResultExportingEnabledForTestExport(true);
75  $test_exp->buildExportFile();
76  ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
77  $ilCtrl->redirectByClass('iltestexportgui');
78  }
79 
83  public function createTestResultsExport()
84  {
89  global $DIC;
90  $lng = $DIC['lng'];
91  $ilCtrl = $DIC['ilCtrl'];
92 
93  require_once 'Modules/Test/classes/class.ilTestExportFactory.php';
94  $expFactory = new ilTestExportFactory($this->obj);
95  $test_exp = $expFactory->getExporter('results');
96  $test_exp->buildExportFile();
97  ilUtil::sendSuccess($lng->txt('exp_file_created'), true);
98  $ilCtrl->redirectByClass('iltestexportgui');
99  }
100 
101  public function createTestArchiveExport()
102  {
103  global $DIC;
104  $ilAccess = $DIC['ilAccess'];
105  $ilCtrl = $DIC['ilCtrl'];
106  $ilDB = $DIC['ilDB'];
107  $lng = $DIC['lng'];
108 
109  if ($ilAccess->checkAccess("write", "", $this->obj->ref_id)) {
110  // prepare generation before contents are processed (for mathjax)
112 
113  require_once 'Modules/Test/classes/class.ilTestEvaluation.php';
114  $evaluation = new ilTestEvaluation($ilDB, $this->obj->getTestId());
115  $allActivesPasses = $evaluation->getAllActivesPasses();
116 
117  require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
118  $participantData = new ilTestParticipantData($ilDB, $lng);
119  $participantData->setActiveIdsFilter(array_keys($allActivesPasses));
120  $participantData->load($this->obj->getTestId());
121 
122  require_once 'Modules/Test/classes/class.ilTestArchiveService.php';
123  $archiveService = new ilTestArchiveService($this->obj);
124  $archiveService->setParticipantData($participantData);
125  $archiveService->archivePassesByActives($allActivesPasses);
126 
127  include_once("./Modules/Test/classes/class.ilTestArchiver.php");
128  $test_id = $this->obj->getId();
129  $archive_exp = new ilTestArchiver($test_id);
130 
131  require_once './Modules/Test/classes/class.ilTestScoring.php';
132  $scoring = new ilTestScoring($this->obj);
133  $best_solution = $scoring->calculateBestSolutionForTest();
134 
135  $tmpFileName = ilUtil::ilTempnam();
136  if (!is_dir($tmpFileName)) {
137  ilUtil::makeDirParents($tmpFileName);
138  }
139 
140  $directory_name = realpath($tmpFileName);
141  $file_name = $directory_name . DIRECTORY_SEPARATOR . 'Best_Solution.pdf';
142 
143  require_once './Modules/Test/classes/class.ilTestPDFGenerator.php';
144  $generator = new ilTestPDFGenerator();
145  $generator->generatePDF($best_solution, ilTestPDFGenerator::PDF_OUTPUT_FILE, $file_name, PDF_USER_RESULT);
146  $archive_exp->handInTestBestSolution($best_solution, $file_name);
147  ilUtil::delDir($directory_name);
148 
149  $archive_exp->updateTestArchive();
150  $archive_exp->compressTestArchive();
151  } else {
152  ilUtil::sendInfo("cannot_export_archive", true);
153  }
154  $ilCtrl->redirectByClass('iltestexportgui');
155  }
156 
157  public function listExportFiles()
158  {
159  global $DIC;
160  $tpl = $DIC['tpl'];
161  $ilToolbar = $DIC['ilToolbar'];
162  $ilCtrl = $DIC['ilCtrl'];
163  $lng = $DIC['lng'];
164 
165  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
166 
167  if (count($this->getFormats()) > 1) {
168  foreach ($this->getFormats() as $f) {
169  $options[$f["key"]] = $f["txt"];
170  }
171  include_once 'Services/Form/classes/class.ilSelectInputGUI.php';
172  $si = new ilSelectInputGUI($lng->txt("type"), "format");
173  $si->setOptions($options);
174  $ilToolbar->addInputItem($si, true);
175  $ilToolbar->addFormButton($lng->txt("exp_create_file"), "createExportFile");
176  } else {
177  $format = $this->getFormats();
178  $format = $format[0];
179  $ilToolbar->addFormButton($lng->txt("exp_create_file") . " (" . $format["txt"] . ")", "create_" . $format["key"]);
180  }
181 
182  require_once 'class.ilTestArchiver.php';
183  $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
184  $archive_dir = $archiver->getZipExportDirectory();
185  $archive_files = array();
186  if (file_exists($archive_dir) && is_dir($archive_dir)) {
187  $archive_files = scandir($archive_dir);
188  }
189 
190  $export_dir = $this->obj->getExportDirectory();
191  $export_files = $this->obj->getExportFiles($export_dir);
192  $data = array();
193  if (count($export_files) > 0) {
194  foreach ($export_files as $exp_file) {
195  $file_arr = explode("__", $exp_file);
196  if($file_arr[0] == $exp_file) continue;
197 
198  array_push($data, array(
199  'file' => $exp_file,
200  'size' => filesize($export_dir . "/" . $exp_file),
201  'timestamp' => $file_arr[0]
202  ));
203  }
204  }
205 
206  if (count($archive_files) > 0) {
207  foreach ($archive_files as $exp_file) {
208  if ($exp_file == '.' || $exp_file == '..') {
209  continue;
210  }
211  $file_arr = explode("_", $exp_file);
212  array_push($data, array(
213  'file' => $exp_file,
214  'size' => filesize($archive_dir . "/" . $exp_file),
215  'timestamp' => $file_arr[4]
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->setData($data);
231  $tpl->setContent($table->getHTML());
232  }
233 
234  public function download()
235  {
240  global $DIC;
241  $lng = $DIC['lng'];
242  $ilCtrl = $DIC['ilCtrl'];
243 
244  if (isset($_GET['file']) && $_GET['file']) {
245  $_POST['file'] = array($_GET['file']);
246  }
247 
248  if (!isset($_POST['file'])) {
249  ilUtil::sendInfo($lng->txt('no_checkbox'), true);
250  $ilCtrl->redirect($this, 'listExportFiles');
251  }
252 
253  if (count($_POST['file']) > 1) {
254  ilUtil::sendInfo($lng->txt('select_max_one_item'), true);
255  $ilCtrl->redirect($this, 'listExportFiles');
256  }
257 
258  require_once 'class.ilTestArchiver.php';
259  $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
260 
261  $filename = basename($_POST["file"][0]);
262  $exportFile = $this->obj->getExportDirectory() . '/' . $filename;
263  $archiveFile = $archiver->getZipExportDirectory() . '/' . $filename;
264 
265  if (file_exists($exportFile)) {
266  ilUtil::deliverFile($exportFile, $filename);
267  }
268 
269  if (file_exists($archiveFile)) {
270  ilUtil::deliverFile($archiveFile, $filename);
271  }
272 
273  $ilCtrl->redirect($this, 'listExportFiles');
274  }
275 
279  public function delete()
280  {
285  global $DIC;
286  $lng = $DIC['lng'];
287  $ilCtrl = $DIC['ilCtrl'];
288 
289  require_once 'class.ilTestArchiver.php';
290  $archiver = new ilTestArchiver($this->getParentGUI()->object->getId());
291  $archiveDir = $archiver->getZipExportDirectory();
292 
293  $export_dir = $this->obj->getExportDirectory();
294  foreach ($_POST['file'] as $file) {
295  $file = basename($file);
296  $dir = substr($file, 0, strlen($file) - 4);
297 
298  if (!strlen($file) || !strlen($dir)) {
299  continue;
300  }
301 
302  $exp_file = $export_dir . '/' . $file;
303  $arc_file = $archiveDir . '/' . $file;
304  $exp_dir = $export_dir . '/' . $dir;
305  if (@is_file($exp_file)) {
306  unlink($exp_file);
307  }
308  if (@is_file($arc_file)) {
309  unlink($arc_file);
310  }
311  if (@is_dir($exp_dir)) {
312  ilUtil::delDir($exp_dir);
313  }
314  }
315  ilUtil::sendSuccess($lng->txt('msg_deleted_export_files'), true);
316  $ilCtrl->redirect($this, 'listExportFiles');
317  }
318 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
$format
Definition: metadata.php:141
Export User Interface Class.
download()
Download file.
This class represents a selection list property in a property form.
Class ilTestPDFGenerator.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
$tpl
Definition: ilias.php:10
const PDF_USER_RESULT
PDF Purposes.
addFormat($a_key, $a_txt="", $a_call_obj=null, $a_call_func="")
Add formats.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getCustomColumns()
Get custom columns.
Export User Interface Class.
$lng
getZipExportDirectory()
Return the export directory, where zips are placed.
const IL_COMP_MODULE
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
Class ilTestScoring.
getFormats()
Get formats.
$filename
Definition: buildRTE.php:89
getCustomMultiCommands()
Get custom multi commands.
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Class ilTestArchiver.
global $ilDB
if(empty($password)) $table
Definition: pwgen.php:24
__construct($a_parent_gui, $a_main_obj=null)
Constuctor.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
$_POST["username"]
static prepareGenerationRequest($service, $purpose)
Prepare the content processing for a PDF generation request This function should be called as in a re...
getParentGUI()
get parent gui
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
$data
Definition: bench.php:6