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