ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilDataCollectionRecordListGUI Class Reference

Class ilDataCollectionRecordListGUI. More...

+ Collaboration diagram for ilDataCollectionRecordListGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $a_parent_obj, $table_id)
 
 executeCommand ()
 execute command More...
 
 exportExcel ()
 Export DC as Excel sheet. More...
 
 showImportExcel ($form=NULL)
 
 importExcel ()
 Import Data from Excel sheet. More...
 
 endImport ($i, $warnings)
 End import. More...
 
 doTableSwitch ()
 doTableSwitch More...
 
 sendFile ()
 send File to User More...
 

Data Fields

const MODE_VIEW = 1
 
const MODE_MANAGE = 2
 

Protected Member Functions

 applyFilter ()
 
 resetFilter ()
 

Protected Attributes

 $mode = self::MODE_VIEW
 
 $max_imports = 100
 
 $supported_import_datatypes
 
 $table_obj
 
 $ctrl
 

Static Protected Attributes

static $available_modes = array( self::MODE_VIEW, self::MODE_MANAGE )
 

Private Member Functions

 importRecords ($file, $simulate=false)
 Import records from Excel file. More...
 
 checkImportType ($field, &$warnings)
 
 getImportFieldsFromTitles ($titles, &$warnings)
 
 recordBelongsToCollection (ilDataCollectionRecord $record)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDataCollectionRecordListGUI::__construct ( ilObjDataCollectionGUI  $a_parent_obj,
  $table_id 
)
Parameters
ilObjDataCollectionGUI$a_parent_obj
$table_id

Definition at line 64 of file class.ilDataCollectionRecordListGUI.php.

64 {
65 global $ilCtrl;
66 $this->ctrl = $ilCtrl;
67 $this->main_table_id = $a_parent_obj->object->getMainTableId();
68 $this->table_id = $table_id;
69 if ($this->table_id == NULL) {
70 $this->table_id = $_GET["table_id"];
71 }
72 $this->obj_id = $a_parent_obj->obj_id;
73 $this->parent_obj = $a_parent_obj;
74 $this->table_obj = ilDataCollectionCache::getTableCache($table_id);
75 $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui", "table_id", $table_id);
76 $this->mode = (isset($_GET['mode']) AND in_array($_GET['mode'], self::$available_modes)) ? (int)$_GET['mode'] : self::MODE_VIEW;
77 }
$_GET["client_id"]
global $ilCtrl
Definition: ilias.php:18

References $_GET, $ilCtrl, ilDataCollectionCache\getTableCache(), and MODE_VIEW.

+ Here is the call graph for this function:

Member Function Documentation

◆ applyFilter()

ilDataCollectionRecordListGUI::applyFilter ( )
protected

Definition at line 460 of file class.ilDataCollectionRecordListGUI.php.

460 {
461 $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
462 $table->resetOffset();
463 $table->writeFilterToSession();
464 $this->ctrl->redirect($this, 'listRecords');
465 // $this->listRecords();
466 }

◆ checkImportType()

ilDataCollectionRecordListGUI::checkImportType (   $field,
$warnings 
)
private
Parameters
ilDataCollectionField$field
array$warnings
Returns
bool

Definition at line 398 of file class.ilDataCollectionRecordListGUI.php.

398 {
399 global $lng;
400 if (in_array($field->getDatatypeId(), $this->supported_import_datatypes)) {
401 return true;
402 } else {
403 $warnings[] = $field->getTitle() . ": " . $lng->txt("dcl_not_supported_in_import");
404
405 return false;
406 }
407 }
global $lng
Definition: privfeed.php:40

References $lng.

Referenced by getImportFieldsFromTitles().

+ Here is the caller graph for this function:

◆ doTableSwitch()

ilDataCollectionRecordListGUI::doTableSwitch ( )

doTableSwitch

Definition at line 452 of file class.ilDataCollectionRecordListGUI.php.

452 {
453 global $ilCtrl;
454
455 $ilCtrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
456 $ilCtrl->redirect($this, "listRecords");
457 }
$_POST['username']
Definition: cron.php:12

References $_POST, and $ilCtrl.

◆ endImport()

ilDataCollectionRecordListGUI::endImport (   $i,
  $warnings 
)

End import.

Parameters
$i
$warnings

Definition at line 372 of file class.ilDataCollectionRecordListGUI.php.

372 {
373 global $tpl, $lng, $ilCtrl;
374 $output = new ilTemplate("tpl.dcl_import_terminated.html", true, true, "Modules/DataCollection");
375 $output->setVariable("IMPORT_TERMINATED", $lng->txt("dcl_import_terminated") . ": " . $i);
376 foreach ($warnings as $warning) {
377 $output->setCurrentBlock("warnings");
378 $output->setVariable("WARNING", $warning);
379 $output->parseCurrentBlock();
380 }
381 if (!count($warnings)) {
382 $output->setCurrentBlock("warnings");
383 $output->setVariable("WARNING", $lng->txt("dcl_no_warnings"));
384 $output->parseCurrentBlock();
385 }
386 $output->setVariable("BACK_LINK", $ilCtrl->getLinkTargetByClass("ilDataCollectionRecordListGUI", "listRecords"));
387 $output->setVariable("BACK", $lng->txt("back"));
388 $tpl->setContent($output->get());
389 }
global $tpl
Definition: ilias.php:8
special template class to simplify handling of ITX/PEAR

References $ilCtrl, $lng, and $tpl.

Referenced by importRecords().

+ Here is the caller graph for this function:

◆ executeCommand()

ilDataCollectionRecordListGUI::executeCommand ( )

execute command

Definition at line 83 of file class.ilDataCollectionRecordListGUI.php.

83 {
84 global $ilCtrl;
85 $ilCtrl->saveParameter($this, 'mode');
86 $cmd = $this->ctrl->getCmd();
87
88 switch ($cmd) {
89 case 'listRecords':
90 $this->setSubTabs();
91 $this->listRecords();
92 break;
93 case 'confirmDeleteRecords':
94 $this->confirmDeleteRecords();
95 break;
96 case 'cancelDelete':
97 $this->setSubTabs();
98 $this->listRecords();
99 break;
100 case 'deleteRecords':
101 $this->deleteRecords();
102 break;
103 default:
104 $this->$cmd();
105 break;
106 }
107 }
$cmd
Definition: sahs_server.php:35

References $cmd, and $ilCtrl.

◆ exportExcel()

ilDataCollectionRecordListGUI::exportExcel ( )

Export DC as Excel sheet.

Definition at line 215 of file class.ilDataCollectionRecordListGUI.php.

215 {
216 global $ilCtrl, $lng;
217 if (!($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id))) {
218 echo $lng->txt("access_denied");
219 exit;
220 }
221
222 require_once('./Modules/DataCollection/classes/class.ilDataCollectionRecordListTableGUI.php');
223 $list = new ilDataCollectionRecordListTableGUI($this, $ilCtrl->getCmd(), $this->table_obj);
224 $list->setRecordData($this->table_obj->getRecordsByFilter($list->getFilter()));
225 $list->setExternalSorting(true);
226 if (!$list->dataExists()) {
227 $this->ctrl->redirect($this->parent_obj);
228 }
229
230 $list->exportData(ilTable2GUI::EXPORT_EXCEL, true);
231 }
exit
Definition: login.php:54

References $ilCtrl, $lng, exit, and ilTable2GUI\EXPORT_EXCEL.

◆ getImportFieldsFromTitles()

ilDataCollectionRecordListGUI::getImportFieldsFromTitles (   $titles,
$warnings 
)
private
Parameters
$titlesstring[]
$warnings
Returns
ilDataCollectionField[]

Definition at line 416 of file class.ilDataCollectionRecordListGUI.php.

416 {
417 global $lng;
418 $fields = $this->table_obj->getRecordFields();
419 $import_fields = array();
420 foreach ($fields as $field) {
421 if ($this->checkImportType($field, $warnings)) {
422 foreach ($titles as $key => $value) {
423 if (!is_array($value) && !ilStr::isUtf8($value)) {
424 $value = utf8_encode($value);
425 }
426 if ($value == $field->getTitle()) {
427 $import_fields[$key] = $field;
428 $properties = $field->getProperties();
429 if ($properties[ilDataCollectionField::PROPERTYID_URL] && $titles[$key+1] == $field->getTitle().'_title') {
430 unset($titles[$key+1]);
431 }
432 }
433 }
434 }
435 }
436 foreach ($titles as $key => $value) {
438 if (in_array($value, $std_field_titles)) {
439 $warnings[] = "(1, " . ilDataCollectionImporter::getExcelCharForInteger($key) . ") \"" . $value . "\" " . $lng->txt("dcl_std_field_not_importable");
440 } elseif (!isset($import_fields[$key])) {
441 $warnings[] = "(1, " . ilDataCollectionImporter::getExcelCharForInteger($key) . ") \"" . $value . "\" " . $lng->txt("dcl_row_not_found");
442 }
443 }
444
445 return $import_fields;
446 }
static isUtf8($a_str)
Check whether string is utf-8.

References $lng, ilDataCollectionStandardField\_getAllStandardFieldTitles(), checkImportType(), ilDataCollectionImporter\getExcelCharForInteger(), ilStr\isUtf8(), and ilDataCollectionField\PROPERTYID_URL.

Referenced by importRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importExcel()

ilDataCollectionRecordListGUI::importExcel ( )

Import Data from Excel sheet.

Definition at line 277 of file class.ilDataCollectionRecordListGUI.php.

277 {
278 global $lng;
279
280 if (!($this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id))) {
281 echo $lng->txt("access_denied");
282 exit;
283 }
284 $form = $this->initForm();
285 if ($form->checkInput()) {
286 $file = $form->getInput("import_file");
287 $file_location = $file["tmp_name"];
288 $simulate = $form->getInput("simulate");
289 $this->importRecords($file_location, $simulate);
290 } else {
291 $this->showImportExcel($form);
292 }
293 }
print $file
importRecords($file, $simulate=false)
Import records from Excel file.

References $file, $lng, exit, importRecords(), and showImportExcel().

+ Here is the call graph for this function:

◆ importRecords()

ilDataCollectionRecordListGUI::importRecords (   $file,
  $simulate = false 
)
private

Import records from Excel file.

Parameters
$file
bool$simulate

Definition at line 302 of file class.ilDataCollectionRecordListGUI.php.

302 {
303 global $ilUser, $lng;
304 include_once("./Modules/DataCollection/libs/ExcelReader/excel_reader2.php");
305
306 $warnings = array();
307 try {
308 $excel = new Spreadsheet_Excel_Reader($file);
309 } catch (Exception $e) {
310 $warnings[] = $lng->txt("dcl_file_not_readable");
311 }
312 if (count($warnings)) {
313 $this->endImport(0, $warnings);
314
315 return;
316 }
317 $field_names = array();
318 for ($i = 1; $i <= $excel->colcount(); $i ++) {
319 $field_names[$i] = $excel->val(1, $i);
320 }
321 $fields = $this->getImportFieldsFromTitles($field_names, $warnings);
322
323 for ($i = 2; $i <= $excel->rowcount(); $i ++) {
324 $record = new ilDataCollectionRecord();
325 $record->setTableId($this->table_obj->getId());
326 $record->setOwner($ilUser->getId());
327 $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
328 $record->setCreateDate($date_obj->get(IL_CAL_DATETIME));
329 $record->setTableId($this->table_id);
330 if (!$simulate) {
331 $record->doCreate();
332 }
333 foreach ($fields as $col => $field) {
334 try {
335 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
336 if (is_array($value) && isset($value['warning'])) {
337 $warnings[] = $value['warning'];
338 $value = '';
339 }
340
341 $field->checkValidity($value, $record->getId());
342 if (!$simulate) {
343 if (!is_array($value) && !ilStr::isUtf8($value)) {
344 $value = utf8_encode($value);
345 }
346 $record->setRecordFieldValue($field->getId(), $value);
347 }
348 } catch (ilDataCollectionInputException $e) {
349 $warnings[] = "(" . $i . ", " . ilDataCollectionImporter::getExcelCharForInteger($col) . ") " . $e;
350 }
351 }
352
353 if (!$simulate) {
354 $record->doUpdate();
355 }
356 if ($i - 1 > $this->max_imports) {
357 $warnings[] = $lng->txt("dcl_max_import") . ($excel->rowcount() - 1) . " > " . $this->max_imports;
358 break;
359 }
360 }
361
362 $this->endImport($i - 2, $warnings);
363 }
const IL_CAL_UNIX
const IL_CAL_DATETIME
Class ilDataCollectionRecord.
@classDescription Date and time handling
global $ilUser
Definition: imgupload.php:15

References $file, $ilUser, $lng, endImport(), ilDataCollectionImporter\getExcelCharForInteger(), getImportFieldsFromTitles(), IL_CAL_DATETIME, IL_CAL_UNIX, and ilStr\isUtf8().

Referenced by importExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recordBelongsToCollection()

ilDataCollectionRecordListGUI::recordBelongsToCollection ( ilDataCollectionRecord  $record)
private
Parameters
ilDataCollectionRecord$record
Returns
bool

Definition at line 565 of file class.ilDataCollectionRecordListGUI.php.

565 {
566 $table = $record->getTable();
567 $obj_id = $this->parent_obj->object->getId();
568 $obj_id_rec = $table->getCollectionObject()->getId();
569
570 return $obj_id == $obj_id_rec;
571 }

References ilDataCollectionRecord\getTable().

Referenced by sendFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetFilter()

ilDataCollectionRecordListGUI::resetFilter ( )
protected

Definition at line 469 of file class.ilDataCollectionRecordListGUI.php.

469 {
470 $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
471 $table->resetOffset();
472 $table->resetFilter();
473 $this->ctrl->redirect($this, 'listRecords');
474 // $this->listRecords();
475 }

◆ sendFile()

ilDataCollectionRecordListGUI::sendFile ( )

send File to User

Definition at line 481 of file class.ilDataCollectionRecordListGUI.php.

481 {
482 global $ilAccess;
483 //need read access to receive file
484 if ($ilAccess->checkAccess("read", "", $this->parent_obj->ref_id)) {
485 $rec_id = $_GET['record_id'];
486 $record = ilDataCollectionCache::getRecordCache($rec_id);
487 $field_id = $_GET['field_id'];
488 $file_obj = new ilObjFile($record->getRecordFieldValue($field_id), false);
489 if (!$this->recordBelongsToCollection($record, $this->parent_obj->ref_id)) {
490 return;
491 }
492 ilUtil::deliverFile($file_obj->getFile(), $file_obj->getTitle());
493 }
494 }
static getRecordCache($record_id=0)
recordBelongsToCollection(ilDataCollectionRecord $record)
Class ilObjFile.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.

References $_GET, ilUtil\deliverFile(), ilDataCollectionCache\getRecordCache(), and recordBelongsToCollection().

+ Here is the call graph for this function:

◆ showImportExcel()

ilDataCollectionRecordListGUI::showImportExcel (   $form = NULL)

Definition at line 234 of file class.ilDataCollectionRecordListGUI.php.

234 {
235 global $tpl;
236 if (!$form) {
237 $form = $this->initForm();
238 }
239 $tpl->setContent($form->getHTML());
240 }

References $tpl.

Referenced by importExcel().

+ Here is the caller graph for this function:

Field Documentation

◆ $available_modes

ilDataCollectionRecordListGUI::$available_modes = array( self::MODE_VIEW, self::MODE_MANAGE )
staticprotected

Definition at line 57 of file class.ilDataCollectionRecordListGUI.php.

◆ $ctrl

ilDataCollectionRecordListGUI::$ctrl
protected

Definition at line 53 of file class.ilDataCollectionRecordListGUI.php.

◆ $max_imports

ilDataCollectionRecordListGUI::$max_imports = 100
protected

Definition at line 35 of file class.ilDataCollectionRecordListGUI.php.

◆ $mode

ilDataCollectionRecordListGUI::$mode = self::MODE_VIEW
protected

Definition at line 31 of file class.ilDataCollectionRecordListGUI.php.

◆ $supported_import_datatypes

◆ $table_obj

ilDataCollectionRecordListGUI::$table_obj
protected

Definition at line 49 of file class.ilDataCollectionRecordListGUI.php.

◆ MODE_MANAGE

const ilDataCollectionRecordListGUI::MODE_MANAGE = 2

Definition at line 25 of file class.ilDataCollectionRecordListGUI.php.

◆ MODE_VIEW

const ilDataCollectionRecordListGUI::MODE_VIEW = 1

Definition at line 24 of file class.ilDataCollectionRecordListGUI.php.

Referenced by __construct().


The documentation for this class was generated from the following file: