ILIAS  release_8 Revision v8.23
class.ilDclRecordEditGUI.php
Go to the documentation of this file.
1 <?php
2 
20 {
24  public const REDIRECT_RECORD_LIST = 1;
25  public const REDIRECT_DETAIL = 2;
26 
27  protected ?int $tableview_id = null;
28  protected ?int $record_id = null;
29  protected int $table_id = 1;
30  protected ilDclTable $table;
33  protected ilCtrl $ctrl;
35  protected ilLanguage $lng;
36  protected ilObjUser $user;
41 
45  public function __construct(ilObjDataCollectionGUI $parent_obj, int $table_id, int $tableview_id)
46  {
47  global $DIC;
48 
49  $this->http = $DIC->http();
50  $this->refinery = $DIC->refinery();
51 
52  $this->ctrl = $DIC['ilCtrl'];
53  $this->tpl = $DIC['tpl'];
54  $this->lng = $DIC['lng'];
55  $this->user = $DIC['ilUser'];
56  $this->parent_obj = $parent_obj;
57  $this->http = $DIC->http();
58  $this->refinery = $DIC->refinery();
59  $this->tableview_id = $tableview_id;
60  $this->table_id = $table_id;
61 
62  if ($this->http->wrapper()->query()->has('record_id')) {
63  $this->record_id = $this->http->wrapper()->query()->retrieve(
64  'record_id',
65  $this->refinery->kindlyTo()->int()
66  );
67  }
68  if ($this->http->wrapper()->post()->has('record_id')) {
69  $this->record_id = $this->http->wrapper()->post()->retrieve(
70  'record_id',
71  $this->refinery->kindlyTo()->int()
72  );
73  }
74  $this->tableview = ilDclTableView::findOrGetInstance($this->tableview_id);
75  }
76 
77  protected function rebuildUploadsForFileHash(bool $has_ilfilehash): string
78  {
79  $hash = "";
80  if ($has_ilfilehash) {
81  // temporary store fileuploads (reuse code from ilPropertyFormGUI)
82  $hash = $this->http->wrapper()->post()->retrieve(
83  'ilfilehash',
84  $this->refinery->kindlyTo()->string()
85  );
86  foreach ($_FILES as $field => $data) {
87  if (is_array($data["tmp_name"])) {
88  foreach ($data["tmp_name"] as $idx => $upload) {
89  if (is_array($upload)) {
90  foreach ($upload as $idx2 => $file) {
91  if ($file && is_uploaded_file($file)) {
92  $file_name = $data["name"][$idx][$idx2];
93  $file_type = $data["type"][$idx][$idx2];
94  $this->form->keepTempFileUpload(
95  $hash,
96  $field,
97  $file,
98  $file_name,
99  $file_type,
100  $idx,
101  $idx2
102  );
103  }
104  }
105  } else {
106  if ($upload && is_uploaded_file($upload)) {
107  $file_name = $data["name"][$idx];
108  $file_type = $data["type"][$idx];
109  $this->form->keepTempFileUpload(
110  $hash,
111  $field,
112  $upload,
113  $file_name,
114  $file_type,
115  $idx
116  );
117  }
118  }
119  }
120  } else {
121  $this->form->keepTempFileUpload(
122  $hash,
123  $field,
124  $data["tmp_name"],
125  $data["name"],
126  $data["type"]
127  );
128  }
129  }
130  }
131  return $hash;
132  }
133 
134  public function executeCommand(): void
135  {
136  $this->getRecord();
137 
138  $cmd = $this->ctrl->getCmd();
139  $this->$cmd();
140  }
141 
142  public function getRecord(): void
143  {
144  $hasMode = $this->http->wrapper()->query()->has('mode');
145  if ($hasMode) {
146  $mode = $this->http->wrapper()->query()->retrieve('mode', $this->refinery->kindlyTo()->string());
147 
148  $this->ctrl->saveParameter($this, 'mode');
149  $this->ctrl->setParameterByClass("ildclrecordlistgui", "mode", $mode);
150  }
151  $this->ctrl->setParameterByClass('ildclrecordlistgui', 'tableview_id', $this->tableview_id);
152  $this->ctrl->saveParameter($this, 'redirect');
153  if ($this->record_id) {
154  $this->record = ilDclCache::getRecordCache($this->record_id);
155  if (!($this->record->hasPermissionToEdit($this->parent_obj->getRefId()) and $this->record->hasPermissionToView($this->parent_obj->getRefId())) && !$this->record->hasPermissionToDelete($this->parent_obj->getRefId())) {
156  $this->accessDenied();
157  }
158  $this->table = $this->record->getTable();
159  $this->table_id = $this->table->getId();
160  } else {
161  $this->table = ilDclCache::getTableCache($this->table_id);
162  $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
164  $this->accessDenied();
165  }
166  }
167  }
168 
172  public function create(): void
173  {
174  $this->initForm();
175  $this->tpl->setContent($this->form->getHTML());
176  }
177 
181  public function edit(): void
182  {
183  $this->initForm();
184  $this->cleanupTempFiles();
185 
186  $this->setFormValues();
187  $this->tpl->setContent($this->form->getHTML());
188  }
189 
194  public function confirmDelete(): void
195  {
196  $conf = new ilConfirmationGUI();
197  $conf->setFormAction($this->ctrl->getFormAction($this));
198  $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_record'));
199  $record = ilDclCache::getRecordCache($this->record_id);
200 
201  $all_fields = $this->table->getRecordFields();
202  $record_data = "";
203  foreach ($all_fields as $field) {
204  $field_record = ilDclCache::getRecordFieldCache($record, $field);
205 
206  $record_representation = ilDclCache::getRecordRepresentation($field_record);
207  if ($record_representation->getConfirmationHTML() !== false) {
208  $record_data .= $field->getTitle() . ": " . $record_representation->getConfirmationHTML() . "<br />";
209  }
210  }
211  $conf->addItem('record_id', $record->getId(), $record_data);
212  $conf->addHiddenItem('table_id', $this->table_id);
213  $conf->addHiddenItem('tableview_id', $this->tableview_id);
214  $conf->setConfirm($this->lng->txt('delete'), 'delete');
215  $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
216  $this->tpl->setContent($conf->getHTML());
217  }
218 
222  public function cancelDelete(): void
223  {
224  $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
225  }
226 
230  public function delete(): void
231  {
232  $record = ilDclCache::getRecordCache($this->record_id);
233 
234  if (!$this->table->hasPermissionToDeleteRecord($this->parent_obj->getRefId(), $record)) {
235  $this->accessDenied();
236 
237  return;
238  }
239 
240  $record->doDelete();
241  $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_record_deleted"), true);
242  $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
243  }
244 
251  public function getRecordData(int $record_id = 0): array
252  {
253  $get_record_id = $this->http->wrapper()->query()->retrieve('record_id', $this->refinery->kindlyTo()->int());
254 
255  $record_id = ($record_id) ?: $get_record_id;
256  $return = array();
257  if ($record_id) {
258  $record = ilDclCache::getRecordCache((int) $record_id);
259  if (is_object($record)) {
260  $return = $record->getRecordFieldValues();
261  }
262  }
263  if ($this->ctrl->isAsynch()) {
264  echo json_encode($return);
265  exit();
266  }
267 
268  return $return;
269  }
270 
275  public function initForm(): void
276  {
277  $this->form = new ilDclPropertyFormGUI();
278  $prefix = ($this->ctrl->isAsynch()) ? 'dclajax' : 'dcl'; // Used by datacolleciton.js to select input elements
279  $this->form->setId($prefix . $this->table_id . $this->record_id);
280 
281  $hidden_prop = new ilHiddenInputGUI("table_id");
282  $hidden_prop->setValue($this->table_id);
283  $this->form->addItem($hidden_prop);
284  $hidden_prop = new ilHiddenInputGUI("tableview_id");
285  $hidden_prop->setValue($this->tableview_id);
286  $this->form->addItem($hidden_prop);
287  if ($this->record_id) {
288  $hidden_prop = new ilHiddenInputGUI("record_id");
289  $hidden_prop->setValue($this->record_id);
290  $this->form->addItem($hidden_prop);
291  }
292 
293  $this->ctrl->setParameter($this, "record_id", $this->record_id);
294  $this->form->setFormAction($this->ctrl->getFormAction($this));
295  $allFields = $this->table->getRecordFields();
296  $inline_css = '';
297  foreach ($allFields as $field) {
298  $field_setting = $field->getViewSetting($this->tableview_id);
299  if ($field_setting->isVisibleInForm(!$this->record_id)) {
300  $item = ilDclCache::getFieldRepresentation($field)->getInputField($this->form, $this->record_id);
301  if ($item === null) {
302  continue; // Fields calculating values at runtime, e.g. ilDclFormulaFieldModel do not have input
303  }
304 
305  if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLocked(!$this->record_id)) {
306  $item->setDisabled(true);
307  }
308 
309  $item->setRequired($field_setting->isRequired(!$this->record_id));
310  $default_value = null;
311 
312  // If creation mode
313  if (!$this->record_id) {
314  $default_value = ilDclTableViewBaseDefaultValue::findSingle(
315  $field_setting->getFieldObject()->getDatatypeId(),
316  $field_setting->getId()
317  );
318 
319  if ($default_value !== null) {
320  if ($item instanceof ilDclCheckboxInputGUI) {
321  $item->setChecked($default_value->getValue());
322  } else {
323  $item->setValue($default_value->getValue());
324  }
325  } else {
326  if ($item instanceof ilDclTextInputGUI) {
327  $item->setValue("");
328  }
329  }
330  }
331  $this->form->addItem($item);
332  }
333  }
334 
335  $this->tpl->addInlineCss($inline_css);
336 
337  // Add possibility to change the owner in edit mode
338  if ($this->record_id) {
339  $field_setting = $this->tableview->getFieldSetting('owner');
340  if ($field_setting->isVisibleEdit()) {
341  $ownerField = $this->table->getField('owner');
342  $inputfield = ilDclCache::getFieldRepresentation($ownerField)->getInputField($this->form);
343 
344  if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLockedEdit()) {
345  $inputfield->setDisabled(true);
346  } else {
347  $inputfield->setRequired(true);
348  }
349 
350  $this->form->addItem($inputfield);
351  }
352  }
353 
354  // save and cancel commands
355  if ($this->record_id) {
356  $this->form->setTitle($this->lng->txt("dcl_update_record"));
357  $this->form->addCommandButton("save", $this->lng->txt("dcl_update_record"));
358  if (!$this->ctrl->isAsynch()) {
359  $this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
360  }
361  } else {
362  $this->form->setTitle($this->lng->txt("dcl_add_new_record"));
363  $this->form->addCommandButton("save", $this->lng->txt("save"));
364  if (!$this->ctrl->isAsynch()) {
365  $this->form->addCommandButton("cancelSave", $this->lng->txt("cancel"));
366  }
367  }
368  $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id);
369  $this->ctrl->setParameter($this, "table_id", $this->table_id);
370  $this->ctrl->setParameter($this, "record_id", $this->record_id);
371  }
372 
376  public function setFormValues(): bool
377  {
378  //Get Record-Values
379  $record_obj = ilDclCache::getRecordCache($this->record_id);
380  if ($record_obj->getId()) {
381  //Get Table Field Definitions
382  $allFields = $this->table->getFields();
383  foreach ($allFields as $field) {
384  if ($field->getDatatypeId() !== ilDclDatatype::INPUTFORMAT_NONE &&
385  $field->getViewSetting($this->tableview_id)->isVisibleEdit()) {
386  $record_obj->fillRecordFieldFormInput($field->getId(), $this->form);
387  }
388  }
389  } else {
390  $this->form->setValuesByPost();
391  }
392 
393  return true;
394  }
395 
399  public function cancelUpdate(): void
400  {
401  $this->checkAndPerformRedirect(true);
402  }
403 
407  public function cancelSave(): void
408  {
409  $this->cancelUpdate();
410  }
411 
417  public function saveConfirmation(ilDclBaseRecordModel $record_obj, string $filehash): void
418  {
419  $permission = ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId());
420  if ($permission) {
421  $all_fields = $this->table->getRecordFields();
422  } else {
423  $all_fields = $this->table->getEditableFields(!$this->record_id);
424  }
425 
426  $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
427  $record_obj->setTableId($this->table_id);
428  $record_obj->setLastUpdate($date_obj);
429  $record_obj->setLastEditBy($this->user->getId());
430 
431  $confirmation = new ilConfirmationGUI();
432  $confirmation->setFormAction($this->ctrl->getFormAction($this));
433  $header_text = $this->lng->txt('dcl_confirm_storing_records');
434  if (!$permission && !ilObjDataCollectionAccess::hasEditAccess($this->parent_obj->getRefId())
435  && !$this->table->getEditByOwner()
436  && !$this->table->getEditPerm()
437  ) {
438  $header_text .= " " . $this->lng->txt('dcl_confirm_storing_records_no_permission');
439  }
440  $confirmation->setHeaderText($header_text);
441 
442  $confirmation->setCancel($this->lng->txt('dcl_edit_record'), 'edit');
443  $confirmation->setConfirm($this->lng->txt('dcl_save_record'), 'save');
444 
445  $record_data = "";
446 
447  $empty_fileuploads = array();
448  foreach ($all_fields as $field) {
449  $record_field = $record_obj->getRecordField($field->getId());
451  $record_field->addHiddenItemsToConfirmation($confirmation);
452 
453  if (($record_field instanceof ilDclFileuploadRecordFieldModel || $record_field instanceof ilDclMobRecordFieldModel)
454  && $record_field->getValue() == null
455  ) {
456  $empty_fileuploads['field_' . $field->getId()] = [
457  "name" => "",
458  "type" => "",
459  "tmp_name" => "",
460  "error" => 4,
461  "size" => 0
462  ];
463  }
464  $record_representation = ilDclFieldFactory::getRecordRepresentationInstance($record_field);
465 
466  if ($record_representation->getConfirmationHTML() !== false) {
467  $record_data .= $field->getTitle() . ": " . $record_representation->getConfirmationHTML() . "<br />";
468  }
469  }
470 
471  $confirmation->addHiddenItem('ilfilehash', $filehash);
472  $confirmation->addHiddenItem('empty_fileuploads', htmlspecialchars(json_encode($empty_fileuploads)));
473  $confirmation->addHiddenItem('table_id', $this->table_id);
474  $confirmation->addHiddenItem('tableview_id', $this->tableview_id);
475  $confirmation->addItem('save_confirmed', 1, $record_data);
476 
477  if ($this->ctrl->isAsynch()) {
478  echo $confirmation->getHTML();
479  exit();
480  } else {
481  $this->tpl->setContent($confirmation->getHTML());
482  }
483  }
484 
488  public function save(): void
489  {
490  global $DIC;
491  $ilAppEventHandler = $DIC['ilAppEventHandler'];
492 
493  $this->initForm();
494  $this->setFormValues();
495 
496  // if save confirmation is enabled: Temporary file-uploads need to be handled
497  $has_save_confirmed = $this->http->wrapper()->post()->has('save_confirmed');
498  $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
499  $has_record_id = isset($this->record_id);
500  $table_has_save_confirmation = $this->table->getSaveConfirmation();
501 
502  $ilfilehash = $has_ilfilehash ? $this->http->wrapper()->post()->retrieve(
503  'ilfilehash',
504  $this->refinery->kindlyTo()->string()
505  ) : '';
507 
508 
509  if ($table_has_save_confirmation
510  && $has_save_confirmed
511  && $has_ilfilehash
512  && !$has_record_id
513  && !$this->ctrl->isAsynch()
514  ) {
515  $has_empty_fileuploads = $this->http->wrapper()->post()->has('empty_fileuploads');
516 
517  //handle empty fileuploads, since $_FILES has to have an entry for each fileuploadGUI
518  if ($has_empty_fileuploads) {
519  $empty_fileuploads = $this->http->wrapper()->post()->retrieve(
520  'empty_fileuploads',
521  $this->refinery->kindlyTo()->string()
522  );
523  if (json_decode($empty_fileuploads)) {
524  $_FILES = $_FILES + json_decode($empty_fileuploads, true);
525  }
526  }
527  }
528 
529  $valid = $this->form->checkInput();
530 
531  $create_mode = ($this->record_id == null);
532  $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
533 
534  $record_obj = ilDclCache::getRecordCache($this->record_id);
535  $unchanged_obj = $record_obj;
536  $record_obj->setTableId($this->table_id);
537  $record_obj->setLastUpdate($date_obj);
538  $record_obj->setLastEditBy($this->user->getId());
539 
540  if (ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) || $create_mode) {
541  $all_fields = $this->table->getRecordFields();
542  } else {
543  $all_fields = $this->table->getEditableFields(!$this->record_id);
544  }
545 
546  // Check if we can create this record.
547  foreach ($all_fields as $field) {
548  try {
549  $field->checkValidityFromForm($this->form, $this->record_id);
550  } catch (ilDclInputException $e) {
551  $valid = false;
552  $item = $this->form->getItemByPostVar('field_' . $field->getId());
553  $item->setAlert($e);
554  }
555  }
556 
557  if (!$valid) {
558  // Form not valid...
559  //TODO: URL title flushes on invalid form
561  $hash = $this->rebuildUploadsForFileHash($has_ilfilehash);
562  $this->form->setValuesByPost();
563  $this->tpl->setContent($this->form->getHTML());
564  $this->sendFailure($this->lng->txt('form_input_not_valid'));
565 
566  return;
567  }
568 
569  if ($create_mode) {
571  $this->parent_obj->getRefId(),
573  ))) {
574  $this->accessDenied();
575 
576  return;
577  }
578 
579  // when save_confirmation is enabled, not yet confirmed and we have not an async-request => prepare for displaying confirmation
580  if ($table_has_save_confirmation && $this->form->getInput('save_confirmed') == null && !$this->ctrl->isAsynch()) {
581  $hash = $this->rebuildUploadsForFileHash($has_ilfilehash);
582 
583  //edit values, they are valid we already checked them above
584  foreach ($all_fields as $field) {
585  $record_obj->setRecordFieldValueFromForm($field->getId(), $this->form);
586  }
587 
588  $this->saveConfirmation($record_obj, $hash);
589 
590  return;
591  }
592 
593  $record_obj->setOwner($this->user->getId());
594  $record_obj->setCreateDate($date_obj);
595  $record_obj->setTableId($this->table_id);
596  $record_obj->doCreate();
597 
598  $this->record_id = $record_obj->getId();
599  } else {
600  if (!$record_obj->hasPermissionToEdit($this->parent_obj->getRefId())) {
601  $this->accessDenied();
602 
603  return;
604  }
605  }
606 
607  //edit values, they are valid we already checked them above
608  foreach ($all_fields as $field) {
609  $field_setting = $field->getViewSetting($this->tableview_id);
610 
611  if ($field_setting->isVisibleInForm($create_mode) &&
612  (!$field_setting->isLocked($create_mode) || ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()))) {
613  // set all visible fields
614  $record_obj->setRecordFieldValueFromForm($field->getId(), $this->form);
615  } elseif ($create_mode) {
616  // set default values when creating
617  $default_value = ilDclTableViewBaseDefaultValue::findSingle(
618  $field_setting->getFieldObject()->getDatatypeId(),
619  $field_setting->getId()
620  );
621  if ($default_value !== null) {
622  $record_obj->setRecordFieldValue($field->getId(), $default_value->getValue());
623  }
624  }
625  }
626 
627  // Do we need to set a new owner for this record?
628  if (!$create_mode && $this->tableview->getFieldSetting('owner')->isVisibleEdit()) {
629  if ($this->http->wrapper()->post()->has('field_owner')) {
630  $field_owner = $this->http->wrapper()->post()->retrieve(
631  'field_owner',
632  $this->refinery->kindlyTo()->string()
633  );
634  $owner_id = ilObjUser::_lookupId($field_owner);
635  if (!$owner_id) {
636  $this->sendFailure($this->lng->txt('user_not_known'));
637 
638  return;
639  }
640  $record_obj->setOwner($owner_id);
641  }
642  }
643 
644  $dispatchEvent = "update";
645 
646  $dispatchEventData = array(
647  'dcl' => $this->parent_obj->getDataCollectionObject(),
648  'table_id' => $this->table_id,
649  'record_id' => $record_obj->getId(),
650  'record' => $record_obj,
651  );
652 
653  if ($create_mode) {
654  $dispatchEvent = "create";
655  $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
656  $objDataCollection = new ilObjDataCollection($ref_id);
657  $objDataCollection->sendNotification("new_record", $this->table_id, $record_obj->getId());
658  } else {
659  $dispatchEventData['prev_record'] = $unchanged_obj;
660  }
661 
662  $record_obj->doUpdate($create_mode);
663 
664  $ilAppEventHandler->raise(
665  'Modules/DataCollection',
666  $dispatchEvent . 'Record',
667  $dispatchEventData
668  );
669 
670  $this->ctrl->setParameter($this, "table_id", $this->table_id);
671  $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id);
672  $this->ctrl->setParameter($this, "record_id", $this->record_id);
673 
674  if (!$this->ctrl->isAsynch()) {
675  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
676  }
677 
678  $this->checkAndPerformRedirect();
679  if ($this->ctrl->isAsynch()) {
680  // If ajax request, return the form in edit mode again
681  $this->record_id = $record_obj->getId();
682  $this->initForm();
683  $this->setFormValues();
685  $this->lng->txt('msg_obj_modified'),
686  'success'
687  ) . $this->form->getHTML();
688  exit();
689  } else {
690  $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
691  }
692  }
693 
697  protected function checkAndPerformRedirect(bool $force_redirect = false): void
698  {
699  $hasRedirect = $this->http->wrapper()->query()->has('redirect');
700 
701  if ($force_redirect || ($hasRedirect && !$this->ctrl->isAsynch())) {
702  if ($hasRedirect) {
703  $redirect = $this->http->wrapper()->query()->retrieve('redirect', $this->refinery->kindlyTo()->int());
704  switch ($redirect) {
705  case self::REDIRECT_DETAIL:
706  $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'record_id', $this->record_id);
707  $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'table_id', $this->table_id);
708  $this->ctrl->setParameterByClass('ilDclDetailedViewGUI', 'tableview_id', $this->tableview_id);
709  $this->ctrl->redirectByClass("ilDclDetailedViewGUI", "renderRecord");
710  break;
711  case self::REDIRECT_RECORD_LIST:
712  $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
713  break;
714  }
715  }
716  $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
717  }
718  }
719 
720  protected function accessDenied(): void
721  {
722  if (!$this->ctrl->isAsynch()) {
723  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_no_perm_edit'), true);
724  $this->ctrl->redirectByClass('ildclrecordlistgui', 'listRecords');
725  } else {
726  echo $this->lng->txt('dcl_msg_no_perm_edit');
727  exit();
728  }
729  }
730 
731  protected function sendFailure(string $message): void
732  {
733  $keep = !$this->ctrl->isAsynch();
734  $this->form->setValuesByPost();
735  if ($this->ctrl->isAsynch()) {
736  echo ilUtil::getSystemMessageHTML($message, 'failure') . $this->form->getHTML();
737  exit();
738  } else {
739  $this->tpl->setOnScreenMessage('failure', $message, $keep);
740 
741  // Fill locked fields on edit mode - otherwise they are empty (workaround)
742  if (isset($this->record_id) && $this->record_id) {
743  $record_obj = ilDclCache::getRecordCache($this->record_id);
744  if ($record_obj->getId()) {
745  //Get Table Field Definitions
746  $allFields = $this->table->getFields();
747  foreach ($allFields as $field) {
748  $field_setting = $field->getViewSetting($this->tableview_id);
749  if (
750  $field_setting->isLockedEdit() &&
751  $field_setting->isVisibleEdit()
752  ) {
753  $record_obj->fillRecordFieldFormInput($field->getId(), $this->form);
754  }
755  }
756  }
757  }
758  $this->tpl->setContent($this->form->getHTML());
759  }
760  }
761 
765  public function searchObjects(): void
766  {
767  $search = $this->http->wrapper()->post()->retrieve('search_for', $this->refinery->kindlyTo()->string());
768  $dest = $this->http->wrapper()->post()->retrieve('dest', $this->refinery->kindlyTo()->string());
769  $html = "";
770  $query_parser = new ilQueryParser($search);
771  $query_parser->setMinWordLength(1);
772  $query_parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
773  $query_parser->parse();
774  if (!$query_parser->validate()) {
775  $html .= $query_parser->getMessage() . "<br />";
776  }
777 
778  // only like search since fulltext does not support search with less than 3 characters
779  $object_search = new ilLikeObjectSearch($query_parser);
780  $res = $object_search->performSearch();
781  //$res->setRequiredPermission('copy');
782  $res->filter(ROOT_FOLDER_ID, true);
783 
784  if (!count($results = $res->getResultsByObjId())) {
785  $html .= $this->lng->txt('dcl_no_search_results_found_for') . ' ' . $search . "<br />";
786  }
788 
789  foreach ($results as $entry) {
790  $tpl = new ilTemplate("tpl.dcl_tree.html", true, true, "Modules/DataCollection");
791  foreach ((array) $entry['refs'] as $reference) {
792  $path = new ilPathGUI();
793  $tpl->setCurrentBlock('result');
794  $tpl->setVariable(
795  'RESULT_PATH',
796  $path->getPath(ROOT_FOLDER_ID, (int) $reference) . " ยป " . $entry['title']
797  );
798  $tpl->setVariable('RESULT_REF', $reference);
799  $tpl->setVariable('FIELD_ID', $dest);
800  $tpl->parseCurrentBlock();
801  }
802  $html .= $tpl->get();
803  }
804 
805  echo $html;
806  exit;
807  }
808 
809 
815  protected function parseSearchResults(array $a_res): array
816  {
817  $rows = array();
818  foreach ($a_res as $obj_id => $references) {
819  $r = array();
820  $r['title'] = ilObject::_lookupTitle($obj_id);
821  $r['desc'] = ilObject::_lookupDescription($obj_id);
822  $r['obj_id'] = $obj_id;
823  $r['refs'] = $references;
824  $rows[] = $r;
825  }
826 
827  return $rows;
828  }
829 
833  protected function cleanupTempFiles(): void
834  {
835  $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
836  if ($has_ilfilehash) {
837  $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string());
838  $this->form->cleanupTempFiles($ilfilehash);
839  }
840  }
841 
842  public function getForm(): ilDclPropertyFormGUI
843  {
844  return $this->form;
845  }
846 }
setFormValues()
Set values from object to form.
Creates a path for a start and endnode.
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:28
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
cleanupTempFiles()
Cleanup temp-files.
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
const ROOT_FOLDER_ID
Definition: constants.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjDataCollectionGUI $parent_obj, int $table_id, int $tableview_id)
static hasAddRecordAccess(int $ref, ?int $user_id=0)
$valid
doUpdate(bool $omit_notification=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
ilDclBaseRecordModel $record
static _lookupId($a_user_str)
ilGlobalPageTemplate $tpl
ILIAS Refinery Factory $refinery
static rebuildTempFileByHash(string $hash)
create()
Create new record gui.
setRecordFieldValue($field_id, $value)
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getFieldRepresentation(ilDclBaseFieldModel $field)
setRecordFieldValueFromForm(int $field_id, ilPropertyFormGUI $form)
Set a field value.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static findOrGetInstance($primary_key, array $add_constructor_args=array())
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
static _lookupTitle(int $obj_id)
static getTableCache(int $table_id=null)
ILIAS HTTP Services $http
searchObjects()
This function is only used by the ajax request if searching for ILIAS references. ...
rebuildUploadsForFileHash(bool $has_ilfilehash)
initForm()
init Form move parts to RecordRepresentationGUI
const REDIRECT_RECORD_LIST
Possible redirects after saving/updating a record - use GET[&#39;redirect&#39;] to set constants.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
confirmDelete()
Delete confirmation.
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
$results
static hasWriteAccess(int $ref, ?int $user_id=0)
form( $class_path, string $cmd)
static _lookupDescription(int $obj_id)
ilDclPropertyFormGUI $form
cancelDelete()
Cancel deletion.
getRecordData(int $record_id=0)
Return All fields and values from a record ID.
$rows
Definition: xhr_table.php:10
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
static getRecordCache(?int $record_id)
setCreateDate(ilDateTime $a_datetime)
parseSearchResults(array $a_res)
Parse search results.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLastUpdate(ilDateTime $a_datetime)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
$message
Definition: xapiexit.php:32
static getRecordFieldCache(object $record, object $field)
checkAndPerformRedirect(bool $force_redirect=false)
Checks to what view (table or detail) should be redirected and performs redirect. ...
static hasEditAccess(int $ref, ?int $user_id=0)
doDelete(bool $omit_notification=false)
fillRecordFieldFormInput($field_id, ilPropertyFormGUI $form)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilObjDataCollectionGUI $parent_obj