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.

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 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.

References $lng, and $supported_import_datatypes.

Referenced by getImportFieldsFromTitles().

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

◆ doTableSwitch()

ilDataCollectionRecordListGUI::doTableSwitch ( )

doTableSwitch

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

References $_POST, and $ilCtrl.

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
global $ilCtrl
Definition: ilias.php:18

◆ endImport()

ilDataCollectionRecordListGUI::endImport (   $i,
  $warnings 
)

End import.

Parameters
$i
$warnings

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

References $ilCtrl, $lng, and $tpl.

Referenced by importRecords().

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
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(), ilDataCollectionCache\getTableCache(), and ilUtil\sendInfo().

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
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 215 of file class.ilDataCollectionRecordListGUI.php.

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

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
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ getImportFieldsFromTitles()

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

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

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

Referenced by importRecords().

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  }
const PROPERTYID_URL
LINK OR EMAIL!
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:

◆ importExcel()

ilDataCollectionRecordListGUI::importExcel ( )

Import Data from Excel sheet.

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

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

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
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 302 of file class.ilDataCollectionRecordListGUI.php.

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

Referenced by importExcel().

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  }
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 565 of file class.ilDataCollectionRecordListGUI.php.

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

Referenced by sendFile().

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  }
+ 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.

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

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)
$_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 234 of file class.ilDataCollectionRecordListGUI.php.

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

Referenced by importExcel().

234  {
235  global $tpl;
236  if (!$form) {
237  $form = $this->initForm();
238  }
239  $tpl->setContent($form->getHTML());
240  }
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: