ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDataCollectionRecordListGUI Class Reference

Class ilDataCollectionField. More...

+ Collaboration diagram for ilDataCollectionRecordListGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $a_parent_obj, $table_id)
 Constructor. More...
 
 executeCommand ()
 execute command More...
 
 listRecords ()
 List Records. More...
 
 exportExcel ()
 
 showImportExcel ($form=null)
 
 importExcel ()
 
 endImport ($i, $warnings)
 
 getReferenceFromValue ($field, $value)
 
 doTableSwitch ()
 doTableSwitch More...
 
 applyFilter ()
 
 resetFilter ()
 
 sendFile ()
 

Protected Attributes

 $max_imports = 100
 
 $supported_import_datatypes
 

Private Member Functions

 importRecords ($file, $simulate=false)
 
 getExcelCharForInteger ($int)
 
 checkImportType ($field, &$warnings)
 
 getImportFieldsFromTitles ($titles, &$warnings)
 
 recordBelongsToCollection (ilDataCollectionRecord $record)
 

Private Attributes

 $table_obj
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

Constructor.

Parameters
object$a_parent_obj
int$table_id

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

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

41  {
42  global $ilCtrl;
43  $this->main_table_id = $a_parent_obj->object->getMainTableId();
44  $this->table_id = $table_id;
45  if($this->table_id == NULL)
46  $this->table_id = $_GET["table_id"];
47  $this->obj_id = $a_parent_obj->obj_id;
48  $this->parent_obj = $a_parent_obj;
49  $this->table_obj = ilDataCollectionCache::getTableCache($table_id);
50  $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui", "table_id", $table_id);
51 
52  return;
53  }
$_GET["client_id"]
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

Member Function Documentation

◆ applyFilter()

ilDataCollectionRecordListGUI::applyFilter ( )

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

References $ilCtrl, and listRecords().

375  {
376  global $ilCtrl;
377 
378  $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
379  $table->resetOffset();
380  $table->writeFilterToSession();
381  $this->listRecords();
382  }
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

◆ checkImportType()

ilDataCollectionRecordListGUI::checkImportType (   $field,
$warnings 
)
private
Parameters
$fieldilDataCollectionField
$warningsarray

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

References $lng, and $supported_import_datatypes.

Referenced by getImportFieldsFromTitles().

325  {
326  global $lng;
327  if(in_array($field->getDatatypeId(), $this->supported_import_datatypes))
328  return true;
329  else{
330  $warnings[] = $field->getTitle().": ".$lng->txt("dcl_not_supported_in_import");
331  return false;
332  }
333  }
global $lng
Definition: privfeed.php:40
+ Here is the caller graph for this function:

◆ doTableSwitch()

ilDataCollectionRecordListGUI::doTableSwitch ( )

doTableSwitch

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

References $_POST, and $ilCtrl.

364  {
365  global $ilCtrl;
366 
367  $ilCtrl->setParameterByClass("ilObjDataCollectionGUI", "table_id", $_POST['table_id']);
368  $ilCtrl->redirect($this, "listRecords");
369  }
$_POST['username']
Definition: cron.php:12
global $ilCtrl
Definition: ilias.php:18

◆ endImport()

ilDataCollectionRecordListGUI::endImport (   $i,
  $warnings 
)

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

References $ilCtrl, $lng, and $tpl.

Referenced by importRecords().

275  {
276  global $tpl, $lng, $ilCtrl;
277  $output = new ilTemplate("tpl.dcl_import_terminated.html",true, true, "Modules/DataCollection");
278  $output->setVariable("IMPORT_TERMINATED", $lng->txt("dcl_import_terminated").": ".$i);
279  foreach($warnings as $warning){
280  $output->setCurrentBlock("warnings");
281  $output->setVariable("WARNING", $warning);
282  $output->parseCurrentBlock();
283  }
284  if(!count($warnings)){
285  $output->setCurrentBlock("warnings");
286  $output->setVariable("WARNING", $lng->txt("dcl_no_warnings"));
287  $output->parseCurrentBlock();
288  }
289  $output->setVariable("BACK_LINK", $ilCtrl->getLinkTargetByClass("ilDataCollectionRecordListGUI", "listRecords"));
290  $output->setVariable("BACK", $lng->txt("back"));
291  $tpl->setContent($output->get());
292  }
global $ilCtrl
Definition: ilias.php:18
special template class to simplify handling of ITX/PEAR
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
global $lng
Definition: privfeed.php:40
+ Here is the caller graph for this function:

◆ executeCommand()

ilDataCollectionRecordListGUI::executeCommand ( )

execute command

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

References $cmd, $ilCtrl, and $tpl.

59  {
60  global $tpl, $ilCtrl;
61 
62  $cmd = $ilCtrl->getCmd();
63 
64  switch($cmd)
65  {
66  default:
67  $this->$cmd();
68  break;
69  }
70  }
$cmd
Definition: sahs_server.php:35
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl

◆ exportExcel()

ilDataCollectionRecordListGUI::exportExcel ( )

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

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

149  {
150  global $ilCtrl, $lng;
151  if(!($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id))){
152  echo $lng->txt("access_denied");
153  exit;
154  }
155 
156  require_once('./Modules/DataCollection/classes/class.ilDataCollectionRecordListTableGUI.php');
157  $list = new ilDataCollectionRecordListTableGUI($this, $ilCtrl->getCmd(), $this->table_obj);
158  $list->setRecordData($this->table_obj->getRecordsByFilter($list->getFilter()));
159  $list->setExternalSorting(true);
160  $list->exportData(ilTable2GUI::EXPORT_EXCEL, true);
161  }
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 309 of file class.ilDataCollectionRecordListGUI.php.

Referenced by getImportFieldsFromTitles(), and importRecords().

309  {
310  $char = "";
311  $rng = range("A", "Z");
312  while($int > 0){
313  $diff = $int % 26;
314  $char = $rng[$diff-1].$char;
315  $int -= $char;
316  $int /= 26;
317  }
318  return $char;
319  }
+ Here is the caller graph for this function:

◆ getImportFieldsFromTitles()

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

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

References $lng, checkImportType(), and getExcelCharForInteger().

Referenced by importRecords().

339  {
340  global $lng;
341  $fields = $this->table_obj->getRecordFields();
342  $import_fields = array();
343  foreach($fields as $field){
344  if($this->checkImportType($field, $warnings)){
345  foreach($titles as $key => $value)
346  {
347  if($value == $field->getTitle())
348  $import_fields[$key] = $field;
349  }
350  }
351  }
352  foreach($titles as $key => $value)
353  {
354  if(!isset($import_fields[$key]))
355  $warnings[] = "(1, ".$this->getExcelCharForInteger($key).") \"".$value."\" ".$lng->txt("dcl_row_not_found");
356  }
357  return $import_fields;
358  }
global $lng
Definition: privfeed.php:40
+ 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 299 of file class.ilDataCollectionRecordListGUI.php.

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

Referenced by importRecords().

299  {
300  $field = ilDataCollectionCache::getFieldCache($field->getFieldRef());
301  $table = ilDataCollectionCache::getTableCache($field->getTableId());
302  $record_id = 0;
303  foreach($table->getRecords() as $record)
304  if($record->getRecordField($field->getId())->getValue() == $value)
305  $record_id = $record->getId();
306  return $record_id;
307  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importExcel()

ilDataCollectionRecordListGUI::importExcel ( )

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

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

199  {
200  global $lng;
201 
202  if(!($this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id))){
203  echo $lng->txt("access_denied");
204  exit;
205  }
206  $form = $this->initForm();
207  if($form->checkInput()){
208  $file = $form->getInput("import_file");
209  $file_location = $file["tmp_name"];
210  $simulate = $form->getInput("simulate");
211  $this->importRecords($file_location, $simulate);
212  }else{
213  $this->showImportExcel($form);
214  }
215  }
print $file
exit
Definition: login.php:54
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ importRecords()

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

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

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

Referenced by importExcel().

217  {
218  global $ilUser, $lng;
219  include_once("./Modules/DataCollection/libs/ExcelReader/excel_reader2.php");
220 
221  $warnings = array();
222  try{
223  $excel = new Spreadsheet_Excel_Reader($file);
224  }catch (Exception $e){
225  $warnings[] = $lng->txt("dcl_file_not_readable");
226  }
227  if(count($warnings)){
228  $this->endImport(0, $warnings);
229  return;
230  }
231  $field_names = array();
232  for($i = 1; $i <= $excel->colcount(); $i++)
233  $field_names[$i] = $excel->val(1, $i);
234  $fields = $this->getImportFieldsFromTitles($field_names, $warnings);
235 
236 
237  for($i = 2; $i <= $excel->rowcount(); $i++){
238  $record = new ilDataCollectionRecord();
239  $record->setTableId($this->table_obj->getId());
240  $record->setOwner($ilUser->getId());
241  $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
242  $record->setCreateDate($date_obj->get(IL_CAL_DATETIME));
243  $record->setTableId($this->table_id);
244  if(!$simulate)
245  $record->doCreate();
246  foreach($fields as $col => $field){
247  $value = $excel->val($i, $col);
248  try{
249  if($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE){
250  $old = $value;
251  $value = $this->getReferenceFromValue($field, $value);
252  if(!$value) $warnings[] = "(".$i.", ".$this->getExcelCharForInteger($col).") ".$lng->txt("dcl_no_such_reference")." ".$old;
253  } else if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_DATETIME) {
254  $value = array(
255  'date' => date('Y-m-d', strtotime($value)),
256  'time' => '',
257  );
258  }
259  $field->checkValidity($value, $record->getId());
260  if(!$simulate) $record->setRecordFieldValue($field->getId(), $value);
262  $warnings[] = "(".$i.", ".$this->getExcelCharForInteger($col).") ".$e;
263  }
264  }
265  if(!$simulate)
266  $record->doUpdate();
267  if($i - 1 > $this->max_imports){
268  $warnings[] = $lng->txt("dcl_max_import").($excel->rowcount() - 1)." > ".$this->max_imports;
269  break;
270  }
271  }
272  $this->endImport($i - 2, $warnings);
273  }
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listRecords()

ilDataCollectionRecordListGUI::listRecords ( )

List Records.

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

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

Referenced by applyFilter(), and resetFilter().

78  {
79  global $ilTabs, $tpl, $lng, $ilCtrl, $ilToolbar;
80 
81  // Show tables
82  require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
83  if(ilObjDataCollection::_hasWriteAccess($this->parent_obj->ref_id))
84  $tables = $this->parent_obj->object->getTables();
85  else
86  $tables = $this->parent_obj->object->getVisibleTables();
87 
88 
89  foreach($tables as $table)
90  {
91  $options[$table->getId()] = $table->getTitle();
92  }
93 
94  $tpl->addCss("./Modules/DataCollection/css/dcl_reference_hover.css");
95 
96  if(count($options) > 0){
97  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
98  $table_selection = new ilSelectInputGUI('', 'table_id');
99  $table_selection->setOptions($options);
100  $table_selection->setValue($this->table_id);
101 
102  $ilToolbar->setFormAction($ilCtrl->getFormActionByClass("ilDataCollectionRecordListGUI", "doTableSwitch"));
103  $ilToolbar->addText($lng->txt("dcl_table"));
104  $ilToolbar->addInputItem($table_selection);
105  $ilToolbar->addFormButton($lng->txt('change'),'doTableSwitch');
106  $ilToolbar->addSeparator();
107  }
108  if(($this->table_obj->getExportEnabled() || $this->table_obj->hasPermissionToFields($this->parent_obj->ref_id)) && count($this->table_obj->getExportableFields()))
109  $ilToolbar->addButton($lng->txt('dcl_export_table_excel'), $ilCtrl->getFormActionByClass("ildatacollectionrecordlistgui", "exportExcel"));
110 
111  if($this->table_obj->hasPermissionToAddRecord($this->parent_obj->ref_id) && $this->table_obj->hasCustomFields()){
112  $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui","record_id", null);
113  $ilToolbar->addButton($lng->txt("dcl_import_records .xls"), $ilCtrl->getFormActionByClass("ildatacollectionrecordlistgui", "showImportExcel"));
114  $ilToolbar->addButton($lng->txt("dcl_add_new_record"), $ilCtrl->getFormActionByClass("ildatacollectionrecordeditgui", "create"),
115  "", "", "", "", "submit emphsubmit"); // #11502
116  }
117 
118  // requested not to implement this way...
119  //$tpl->addJavaScript("Modules/DataCollection/js/fastTableSwitcher.js");
120  $tpl->addJavaScript("Modules/DataCollection/js/datacollection.js");
121 
122  if(count($this->table_obj->getRecordFields()) == 0){
123  ilUtil::sendInfo($lng->txt("dcl_no_fields_yet")." ".($this->table_obj->hasPermissionToFields($this->parent_obj->ref_id)?$lng->txt("dcl_create_fields"):""));
124  }
125 
126  $list = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
127  $list->setExternalSegmentation(true);
128  $list->setExternalSorting(true);
129  $list->determineLimit();
130  $list->determineOffsetAndOrder();
131  $data = $this->table_obj->getPartialRecords($list->getOrderField(), $list->getOrderDirection(), $list->getLimit(), $list->getOffset(), $list->getFilter());
132  $records = $data['records'];
133  $total = $data['total'];
134  $list->setMaxCount($total);
135  $list->setRecordData($records);
136 
137  $tpl->getStandardTemplate();
138  $tpl->setPermanentLink("dcl", $this->parent_obj->ref_id);
139  if ($desc = $this->table_obj->getDescription()) {
140  $desc = "<div class='ilDclTableDescription'>{$desc}</div>";
141  }
142  $tpl->setContent($desc . $list->getHTML());
143  }
This class represents a selection list property in a property form.
$records
Definition: simple_test.php:22
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!is_array($argv)) $options
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recordBelongsToCollection()

ilDataCollectionRecordListGUI::recordBelongsToCollection ( ilDataCollectionRecord  $record)
private

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

References ilDataCollectionRecord\getTable().

Referenced by sendFile().

422  {
423  $table = $record->getTable();
424  $obj_id = $this->parent_obj->object->getId();
425  $obj_id_rec = $table->getCollectionObject()->getId();
426 
427  return $obj_id == $obj_id_rec;
428  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetFilter()

ilDataCollectionRecordListGUI::resetFilter ( )

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

References $ilCtrl, and listRecords().

388  {
389  global $ilCtrl;
390 
391  $table = new ilDataCollectionRecordListTableGUI($this, "listRecords", $this->table_obj);
392  $table->resetOffset();
393  $table->resetFilter();
394  $this->listRecords();
395  }
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

◆ sendFile()

ilDataCollectionRecordListGUI::sendFile ( )

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

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

401  {
402  global $ilAccess;
403  //need read access to receive file
404  if($ilAccess->checkAccess("read", "", $this->parent_obj->ref_id))
405  {
406  $rec_id = $_GET['record_id'];
407  $record = ilDataCollectionCache::getRecordCache($rec_id);
408  $field_id = $_GET['field_id'];
409  $file_obj = new ilObjFile($record->getRecordFieldValue($field_id), false);
410  if(!$this->recordBelongsToCollection($record, $this->parent_obj->ref_id))
411  {
412  return;
413  }
414  ilUtil::deliverFile($file_obj->getFile(), $file_obj->getTitle());
415  }
416  }
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 163 of file class.ilDataCollectionRecordListGUI.php.

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

Referenced by importExcel().

163  {
164  global $tpl;
165  if(!$form)
166  $form = $this->initForm();
167  $tpl->setContent($form->getHTML());
168  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $max_imports

ilDataCollectionRecordListGUI::$max_imports = 100
protected

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

◆ $supported_import_datatypes

◆ $table_obj

ilDataCollectionRecordListGUI::$table_obj
private

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

Referenced by exportExcel().


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