ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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...
 
 getReferenceFromValue ($field, $value)
 
 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...
 
 getExcelCharForInteger ($int)
 
 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.

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

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
+ Here is the call graph for this function:

Member Function Documentation

◆ applyFilter()

ilDataCollectionRecordListGUI::applyFilter ( )
protected

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

493  {
494  $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
495  $table->resetOffset();
496  $table->writeFilterToSession();
497  $this->ctrl->redirect($this, 'listRecords');
498  // $this->listRecords();
499  }

◆ checkImportType()

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

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

References $lng, and $supported_import_datatypes.

Referenced by getImportFieldsFromTitles().

435  {
436  global $lng;
437  if (in_array($field->getDatatypeId(), $this->supported_import_datatypes)) {
438  return true;
439  } else {
440  $warnings[] = $field->getTitle() . ": " . $lng->txt("dcl_not_supported_in_import");
441 
442  return false;
443  }
444  }
global $lng
Definition: privfeed.php:40
+ Here is the caller graph for this function:

◆ doTableSwitch()

ilDataCollectionRecordListGUI::doTableSwitch ( )

doTableSwitch

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

References $_POST, and $ilCtrl.

485  {
486  global $ilCtrl;
487 
488  $ilCtrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
489  $ilCtrl->redirect($this, "listRecords");
490  }
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18

◆ endImport()

ilDataCollectionRecordListGUI::endImport (   $i,
  $warnings 
)

End import.

Parameters
$i
$warnings

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

References $ilCtrl, $lng, and $tpl.

Referenced by importRecords().

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

◆ executeCommand()

ilDataCollectionRecordListGUI::executeCommand ( )

execute command

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

References $cmd, $data, $ilCtrl, $lng, $options, $records, $total, $tpl, ilObjDataCollection\_hasWriteAccess(), ilLinkButton\getInstance(), ilDataCollectionLinkButton\getInstance(), and ilUtil\sendInfo().

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

◆ exportExcel()

ilDataCollectionRecordListGUI::exportExcel ( )

Export DC as Excel sheet.

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

References $ilCtrl, $lng, $table_obj, exit, ilTable2GUI\EXPORT_EXCEL, and ilDataCollectionRecordListTableGUI\setRecordData().

210  {
211  global $ilCtrl, $lng;
212  if (!($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id))) {
213  echo $lng->txt("access_denied");
214  exit;
215  }
216 
217  require_once('./Modules/DataCollection/classes/class.ilDataCollectionRecordListTableGUI.php');
218  $list = new ilDataCollectionRecordListTableGUI($this, $ilCtrl->getCmd(), $this->table_obj);
219  $list->setRecordData($this->table_obj->getRecordsByFilter($list->getFilter()));
220  $list->setExternalSorting(true);
221  if (!$list->dataExists()) {
222  $this->ctrl->redirect($this->parent_obj);
223  }
224 
225  $list->exportData(ilTable2GUI::EXPORT_EXCEL, true);
226  }
exit
Definition: login.php:54
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ getExcelCharForInteger()

ilDataCollectionRecordListGUI::getExcelCharForInteger (   $int)
private

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

Referenced by getImportFieldsFromTitles(), and importRecords().

415  {
416  $char = "";
417  $rng = range("A", "Z");
418  while ($int > 0) {
419  $diff = $int % 26;
420  $char = $rng[$diff - 1] . $char;
421  $int -= $char;
422  $int /= 26;
423  }
424 
425  return $char;
426  }
+ Here is the caller graph for this function:

◆ getImportFieldsFromTitles()

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

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

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

Referenced by importRecords().

453  {
454  global $lng;
455  $fields = $this->table_obj->getRecordFields();
456  $import_fields = array();
457  foreach ($fields as $field) {
458  if ($this->checkImportType($field, $warnings)) {
459  foreach ($titles as $key => $value) {
460  if (!ilStr::isUtf8($value)) {
461  $value = utf8_encode($value);
462  }
463  if ($value == $field->getTitle()) {
464  $import_fields[$key] = $field;
465  }
466  }
467  }
468  }
469  foreach ($titles as $key => $value) {
471  if (in_array($value, $std_field_titles)) {
472  $warnings[] = "(1, " . $this->getExcelCharForInteger($key) . ") \"" . $value . "\" " . $lng->txt("dcl_std_field_not_importable");
473  } elseif (!isset($import_fields[$key])) {
474  $warnings[] = "(1, " . $this->getExcelCharForInteger($key) . ") \"" . $value . "\" " . $lng->txt("dcl_row_not_found");
475  }
476  }
477 
478  return $import_fields;
479  }
global $lng
Definition: privfeed.php:40
static isUtf8($a_str)
Check whether string is utf-8.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getReferenceFromValue()

ilDataCollectionRecordListGUI::getReferenceFromValue (   $field,
  $value 
)
Parameters
$fieldilDataCollectionField
$value
Returns
int

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

References ilDataCollectionCache\getFieldCache(), and ilDataCollectionCache\getTableCache().

Referenced by importRecords().

401  {
402  $field = ilDataCollectionCache::getFieldCache($field->getFieldRef());
403  $table = ilDataCollectionCache::getTableCache($field->getTableId());
404  $record_id = 0;
405  foreach ($table->getRecords() as $record) {
406  if ($record->getRecordField($field->getId())->getValue() == $value) {
407  $record_id = $record->getId();
408  }
409  }
410 
411  return $record_id;
412  }
+ 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 272 of file class.ilDataCollectionRecordListGUI.php.

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

272  {
273  global $lng;
274 
275  if (!($this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id))) {
276  echo $lng->txt("access_denied");
277  exit;
278  }
279  $form = $this->initForm();
280  if ($form->checkInput()) {
281  $file = $form->getInput("import_file");
282  $file_location = $file["tmp_name"];
283  $simulate = $form->getInput("simulate");
284  $this->importRecords($file_location, $simulate);
285  } else {
286  $this->showImportExcel($form);
287  }
288  }
print $file
exit
Definition: login.php:54
importRecords($file, $simulate=false)
Import records from Excel file.
global $lng
Definition: privfeed.php:40
+ 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 297 of file class.ilDataCollectionRecordListGUI.php.

References $file, $ilUser, $lng, endImport(), getExcelCharForInteger(), getImportFieldsFromTitles(), getReferenceFromValue(), IL_CAL_DATETIME, IL_CAL_UNIX, ilDataCollectionDatatype\INPUTFORMAT_DATETIME, ilDataCollectionDatatype\INPUTFORMAT_REFERENCE, and ilStr\isUtf8().

Referenced by importExcel().

297  {
298  global $ilUser, $lng;
299  include_once("./Modules/DataCollection/libs/ExcelReader/excel_reader2.php");
300 
301  $warnings = array();
302  try {
303  $excel = new Spreadsheet_Excel_Reader($file);
304  } catch (Exception $e) {
305  $warnings[] = $lng->txt("dcl_file_not_readable");
306  }
307  if (count($warnings)) {
308  $this->endImport(0, $warnings);
309 
310  return;
311  }
312  $field_names = array();
313  for ($i = 1; $i <= $excel->colcount(); $i ++) {
314  $field_names[$i] = $excel->val(1, $i);
315  }
316  $fields = $this->getImportFieldsFromTitles($field_names, $warnings);
317 
318  for ($i = 2; $i <= $excel->rowcount(); $i ++) {
319  $record = new ilDataCollectionRecord();
320  $record->setTableId($this->table_obj->getId());
321  $record->setOwner($ilUser->getId());
322  $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
323  $record->setCreateDate($date_obj->get(IL_CAL_DATETIME));
324  $record->setTableId($this->table_id);
325  if (!$simulate) {
326  $record->doCreate();
327  }
328  foreach ($fields as $col => $field) {
329  $value = $excel->val($i, $col);
330  try {
331  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
332  $old = $value;
333  $value = $this->getReferenceFromValue($field, $value);
334  if (!$value) {
335  $warnings[] = "(" . $i . ", " . $this->getExcelCharForInteger($col) . ") " . $lng->txt("dcl_no_such_reference") . " "
336  . $old;
337  }
338  } else {
339  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
340  $value = array(
341  'date' => date('Y-m-d', strtotime($value)),
342  'time' => '00:00:00',
343  );
344  }
345  }
346  $field->checkValidity($value, $record->getId());
347  if (!$simulate) {
348  if (!ilStr::isUtf8($value)) {
349  $value = utf8_encode($value);
350  }
351  $record->setRecordFieldValue($field->getId(), $value);
352  }
353  } catch (ilDataCollectionInputException $e) {
354  $warnings[] = "(" . $i . ", " . $this->getExcelCharForInteger($col) . ") " . $e;
355  }
356  }
357  if (!$simulate) {
358  $record->doUpdate();
359  }
360  if ($i - 1 > $this->max_imports) {
361  $warnings[] = $lng->txt("dcl_max_import") . ($excel->rowcount() - 1) . " > " . $this->max_imports;
362  break;
363  }
364  }
365  $this->endImport($i - 2, $warnings);
366  }
print $file
const IL_CAL_DATETIME
const IL_CAL_UNIX
Class ilDataCollectionRecord.
Date and time handling
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
static isUtf8($a_str)
Check whether string is utf-8.
+ 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 598 of file class.ilDataCollectionRecordListGUI.php.

References $_GET, $ilCtrl, $lng, and ilDataCollectionRecord\getTable().

Referenced by sendFile().

598  {
599  $table = $record->getTable();
600  $obj_id = $this->parent_obj->object->getId();
601  $obj_id_rec = $table->getCollectionObject()->getId();
602 
603  return $obj_id == $obj_id_rec;
604  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetFilter()

ilDataCollectionRecordListGUI::resetFilter ( )
protected

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

502  {
503  $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
504  $table->resetOffset();
505  $table->resetFilter();
506  $this->ctrl->redirect($this, 'listRecords');
507  // $this->listRecords();
508  }

◆ sendFile()

ilDataCollectionRecordListGUI::sendFile ( )

send File to User

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

References $_GET, $_POST, $ilCtrl, $lng, $tpl, ilUtil\deliverFile(), ilDataCollectionCache\getRecordCache(), recordBelongsToCollection(), ilUtil\sendInfo(), and ilUtil\sendSuccess().

514  {
515  global $ilAccess;
516  //need read access to receive file
517  if ($ilAccess->checkAccess("read", "", $this->parent_obj->ref_id)) {
518  $rec_id = $_GET['record_id'];
519  $record = ilDataCollectionCache::getRecordCache($rec_id);
520  $field_id = $_GET['field_id'];
521  $file_obj = new ilObjFile($record->getRecordFieldValue($field_id), false);
522  if (!$this->recordBelongsToCollection($record, $this->parent_obj->ref_id)) {
523  return;
524  }
525  ilUtil::deliverFile($file_obj->getFile(), $file_obj->getTitle());
526  }
527  }
static getRecordCache($record_id=0)
recordBelongsToCollection(ilDataCollectionRecord $record)
$_GET["client_id"]
Class ilObjFile.
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
+ Here is the call graph for this function:

◆ showImportExcel()

ilDataCollectionRecordListGUI::showImportExcel (   $form = NULL)

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

References $file, $ilCtrl, $lng, $tpl, and ilFormPropertyGUI\setInfo().

Referenced by importExcel().

229  {
230  global $tpl;
231  if (!$form) {
232  $form = $this->initForm();
233  }
234  $tpl->setContent($form->getHTML());
235  }
global $tpl
Definition: ilias.php:8
+ Here is the call graph for this function:
+ 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.

Referenced by exportExcel().

◆ MODE_MANAGE

const ilDataCollectionRecordListGUI::MODE_MANAGE = 2

◆ MODE_VIEW

const ilDataCollectionRecordListGUI::MODE_VIEW = 1

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


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