ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilDclRecordEditGUI Class Reference
+ Collaboration diagram for ilDclRecordEditGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $parent_obj, int $table_id, int $tableview_id)
 
 executeCommand ()
 
 getRecord ()
 
 create ()
 Create new record gui. More...
 
 edit ()
 Record edit gui. More...
 
 confirmDelete ()
 Delete confirmation. More...
 
 cancelDelete ()
 Cancel deletion. More...
 
 delete ()
 Remove record. More...
 
 getRecordData (int $record_id=0)
 Return All fields and values from a record ID. More...
 
 initForm ()
 init Form @move move parts to RecordRepresentationGUI More...
 
 setFormValues ()
 Set values from object to form. More...
 
 cancelUpdate ()
 Cancel Update. More...
 
 cancelSave ()
 Cancel Save. More...
 
 save ()
 
 getForm ()
 

Data Fields

const REDIRECT_RECORD_LIST = 1
 Possible redirects after saving/updating a record - use GET['redirect'] to set constants. More...
 
const REDIRECT_DETAIL = 2
 

Protected Member Functions

 rebuildUploadsForFileHash (bool $has_ilfilehash)
 
 checkAndPerformRedirect (bool $force_redirect=false)
 Checks to what view (table or detail) should be redirected and performs redirect. More...
 
 accessDenied ()
 
 sendFailure (string $message)
 
 cleanupTempFiles ()
 

Protected Attributes

int $tableview_id = null
 
int $record_id = null
 
int $table_id = 1
 
ilDclTable $table
 
ilObjDataCollectionGUI $parent_obj
 
ilDclBaseRecordModel $record
 
ilCtrl $ctrl
 
ilGlobalPageTemplate $tpl
 
ilLanguage $lng
 
ilObjUser $user
 
ilDclPropertyFormGUI $form
 
ilDclTableView $tableview
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilDclRecordEditGUI::__construct ( ilObjDataCollectionGUI  $parent_obj,
int  $table_id,
int  $tableview_id 
)

Definition at line 46 of file class.ilDclRecordEditGUI.php.

47 {
48 global $DIC;
49
50 $this->http = $DIC->http();
51 $this->refinery = $DIC->refinery();
52
53 $this->ctrl = $DIC['ilCtrl'];
54 $this->tpl = $DIC['tpl'];
55 $this->lng = $DIC['lng'];
56 $this->user = $DIC['ilUser'];
57 $this->parent_obj = $parent_obj;
58 $this->http = $DIC->http();
59 $this->refinery = $DIC->refinery();
60 $this->tableview_id = $tableview_id;
61 $this->table_id = $table_id;
62
63 if ($this->http->wrapper()->query()->has('record_id')) {
64 $this->record_id = $this->http->wrapper()->query()->retrieve(
65 'record_id',
66 $this->refinery->kindlyTo()->int()
67 );
68 }
69 if ($this->http->wrapper()->post()->has('record_id')) {
70 $this->record_id = $this->http->wrapper()->post()->retrieve(
71 'record_id',
72 $this->refinery->kindlyTo()->int()
73 );
74 }
75 $this->tableview = ilDclTableView::findOrGetInstance($this->tableview_id);
76 }
ilObjDataCollectionGUI $parent_obj
static findOrGetInstance($primary_key, array $add_constructor_args=[])
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

References $DIC, $parent_obj, $table_id, $tableview_id, ILIAS\Repository\ctrl(), ilDclTableView\findOrGetInstance(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ accessDenied()

ilDclRecordEditGUI::accessDenied ( )
protected

Definition at line 720 of file class.ilDclRecordEditGUI.php.

720 : 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::class, 'listRecords');
725 } else {
726 echo $this->lng->txt('dcl_msg_no_perm_edit');
727 exit();
728 }
729 }
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References ILIAS\Repository\ctrl(), exit, and ILIAS\Repository\lng().

Referenced by delete(), getRecord(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cancelDelete()

ilDclRecordEditGUI::cancelDelete ( )

Cancel deletion.

Definition at line 225 of file class.ilDclRecordEditGUI.php.

225 : void
226 {
227 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
228 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ cancelSave()

ilDclRecordEditGUI::cancelSave ( )

Cancel Save.

Definition at line 404 of file class.ilDclRecordEditGUI.php.

404 : void
405 {
406 $this->cancelUpdate();
407 }

References cancelUpdate().

+ Here is the call graph for this function:

◆ cancelUpdate()

ilDclRecordEditGUI::cancelUpdate ( )

Cancel Update.

Definition at line 396 of file class.ilDclRecordEditGUI.php.

396 : void
397 {
398 $this->checkAndPerformRedirect(true);
399 }
checkAndPerformRedirect(bool $force_redirect=false)
Checks to what view (table or detail) should be redirected and performs redirect.

References checkAndPerformRedirect().

Referenced by cancelSave().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkAndPerformRedirect()

ilDclRecordEditGUI::checkAndPerformRedirect ( bool  $force_redirect = false)
protected

Checks to what view (table or detail) should be redirected and performs redirect.

Definition at line 697 of file class.ilDclRecordEditGUI.php.

697 : 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) {
706 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'record_id', $this->record_id);
707 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'table_id', $this->table_id);
708 $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'tableview_id', $this->tableview_id);
709 $this->ctrl->redirectByClass(ilDclDetailedViewGUI::class, "renderRecord");
710 break;
712 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
713 break;
714 }
715 }
716 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
717 }
718 }
const REDIRECT_RECORD_LIST
Possible redirects after saving/updating a record - use GET['redirect'] to set constants.

References ILIAS\Repository\ctrl(), ILIAS\FileDelivery\http(), REDIRECT_DETAIL, REDIRECT_RECORD_LIST, and ILIAS\Repository\refinery().

Referenced by cancelUpdate(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cleanupTempFiles()

ilDclRecordEditGUI::cleanupTempFiles ( )
protected

Definition at line 762 of file class.ilDclRecordEditGUI.php.

762 : void
763 {
764 $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
765 if ($has_ilfilehash) {
766 $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string());
767 $this->form->cleanupTempFiles($ilfilehash);
768 }
769 }
form(?array $class_path, string $cmd, string $submit_caption="")

References ILIAS\Repository\form(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by edit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmDelete()

ilDclRecordEditGUI::confirmDelete ( )

Delete confirmation.

Exceptions
ilDclException

Definition at line 197 of file class.ilDclRecordEditGUI.php.

197 : void
198 {
199 $conf = new ilConfirmationGUI();
200 $conf->setFormAction($this->ctrl->getFormAction($this));
201 $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_record'));
202 $record = ilDclCache::getRecordCache($this->record_id);
203
204 $all_fields = $this->table->getRecordFields();
205 $record_data = "";
206 foreach ($all_fields as $field) {
207 $field_record = ilDclCache::getRecordFieldCache($record, $field);
208
209 $record_representation = ilDclCache::getRecordRepresentation($field_record);
210 if ($record_representation->getConfirmationHTML() != false) {
211 $record_data .= $field->getTitle() . ": " . $record_representation->getConfirmationHTML() . "<br />";
212 }
213 }
214 $conf->addItem('record_id', (string) $record->getId(), $record_data);
215 $conf->addHiddenItem('table_id', (string) $this->table_id);
216 $conf->addHiddenItem('tableview_id', (string) $this->tableview_id);
217 $conf->setConfirm($this->lng->txt('delete'), 'delete');
218 $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete');
219 $this->tpl->setContent($conf->getHTML());
220 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRecordCache(?int $record_id)
static getRecordFieldCache(object $record, object $field)
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
ilDclBaseRecordModel $record

References $record, ILIAS\Repository\ctrl(), ilDclBaseRecordModel\getId(), ilDclCache\getRecordCache(), ilDclCache\getRecordFieldCache(), ilDclCache\getRecordRepresentation(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ create()

ilDclRecordEditGUI::create ( )

Create new record gui.

Definition at line 173 of file class.ilDclRecordEditGUI.php.

173 : void
174 {
175 global $DIC;
176 $DIC->help()->setSubScreenId('create');
177 $this->initForm();
178 $this->tpl->setContent($this->form->getHTML());
179 }
initForm()
init Form @move move parts to RecordRepresentationGUI

References $DIC, ILIAS\Repository\form(), and initForm().

+ Here is the call graph for this function:

◆ delete()

ilDclRecordEditGUI::delete ( )

Remove record.

Definition at line 233 of file class.ilDclRecordEditGUI.php.

233 : void
234 {
235 $record = ilDclCache::getRecordCache($this->record_id);
236
237 if (!$this->table->hasPermissionToDeleteRecord($this->parent_obj->getRefId(), $record)) {
238 $this->accessDenied();
239
240 return;
241 }
242
243 $record->doDelete();
244 $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_record_deleted"), true);
245 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
246 }
doDelete(bool $omit_notification=false)

References $record, accessDenied(), ILIAS\Repository\ctrl(), ilDclBaseRecordModel\doDelete(), ilDclCache\getRecordCache(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ edit()

ilDclRecordEditGUI::edit ( )

Record edit gui.

Definition at line 184 of file class.ilDclRecordEditGUI.php.

184 : void
185 {
186 $this->initForm();
187 $this->cleanupTempFiles();
188
189 $this->setFormValues();
190 $this->tpl->setContent($this->form->getHTML());
191 }
setFormValues()
Set values from object to form.

References cleanupTempFiles(), ILIAS\Repository\form(), initForm(), and setFormValues().

+ Here is the call graph for this function:

◆ executeCommand()

ilDclRecordEditGUI::executeCommand ( )

Definition at line 135 of file class.ilDclRecordEditGUI.php.

135 : void
136 {
137 $this->getRecord();
138
139 $cmd = $this->ctrl->getCmd();
140 $this->$cmd();
141 }

References ILIAS\Repository\ctrl(), and getRecord().

+ Here is the call graph for this function:

◆ getForm()

ilDclRecordEditGUI::getForm ( )

Definition at line 771 of file class.ilDclRecordEditGUI.php.

772 {
773 return $this->form;
774 }
Class ilDclPropertyFormGUI @ilCtrl_Calls ilDclPropertyFormGUI: ilFormPropertyDispatchGUI.
ilDclPropertyFormGUI $form

References $form.

◆ getRecord()

ilDclRecordEditGUI::getRecord ( )

Definition at line 143 of file class.ilDclRecordEditGUI.php.

143 : void
144 {
145 $hasMode = $this->http->wrapper()->query()->has('mode');
146 if ($hasMode) {
147 $mode = $this->http->wrapper()->query()->retrieve('mode', $this->refinery->kindlyTo()->string());
148
149 $this->ctrl->saveParameter($this, 'mode');
150 $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, "mode", $mode);
151 }
152 $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, 'tableview_id', $this->tableview_id);
153 $this->ctrl->saveParameter($this, 'redirect');
154 if ($this->record_id) {
155 $this->record = ilDclCache::getRecordCache($this->record_id);
156 if (!($this->record->hasPermissionToEdit($this->parent_obj->getRefId()) and $this->record->hasPermissionToView($this->parent_obj->getRefId())) && !$this->record->hasPermissionToDelete($this->parent_obj->getRefId())) {
157 $this->accessDenied();
158 }
159 $this->table = $this->record->getTable();
160 $this->table_id = $this->table->getId();
161 } else {
162 $this->table = ilDclCache::getTableCache($this->table_id);
163 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
165 $this->accessDenied();
166 }
167 }
168 }
static getTableCache(?int $table_id=null)
static hasAddRecordAccess(int $ref, ?int $user_id=0)

References accessDenied(), ILIAS\Repository\ctrl(), ilDclCache\getRecordCache(), ilDclCache\getTableCache(), ilObjDataCollectionAccess\hasAddRecordAccess(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecordData()

ilDclRecordEditGUI::getRecordData ( int  $record_id = 0)

Return All fields and values from a record ID.

If this method is requested over AJAX, data is returned in JSON format

Parameters
int$record_id
Returns
array

Definition at line 254 of file class.ilDclRecordEditGUI.php.

254 : array
255 {
256 $get_record_id = $this->http->wrapper()->query()->retrieve('record_id', $this->refinery->kindlyTo()->int());
257
258 $record_id = ($record_id) ?: $get_record_id;
259 $return = [];
260 if ($record_id) {
262 $return = $record->getRecordFieldValues();
263 }
264 if ($this->ctrl->isAsynch()) {
265 echo json_encode($return);
266 exit();
267 }
268
269 return $return;
270 }

References $record, $record_id, ILIAS\Repository\ctrl(), exit, ilDclCache\getRecordCache(), ilDclBaseRecordModel\getRecordFieldValues(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ initForm()

ilDclRecordEditGUI::initForm ( )

init Form @move move parts to RecordRepresentationGUI

Definition at line 276 of file class.ilDclRecordEditGUI.php.

276 : void
277 {
278 $this->form = new ilDclPropertyFormGUI();
279 $prefix = ($this->ctrl->isAsynch()) ? 'dclajax' : 'dcl'; // Used by datacolleciton.js to select input elements
280 $this->form->setId($prefix . $this->table_id . $this->record_id);
281
282 $hidden_prop = new ilHiddenInputGUI("table_id");
283 $hidden_prop->setValue((string) $this->table_id);
284 $this->form->addItem($hidden_prop);
285 $hidden_prop = new ilHiddenInputGUI("tableview_id");
286 $hidden_prop->setValue((string) $this->tableview_id);
287 $this->form->addItem($hidden_prop);
288 if ($this->record_id) {
289 $hidden_prop = new ilHiddenInputGUI("record_id");
290 $hidden_prop->setValue((string) $this->record_id);
291 $this->form->addItem($hidden_prop);
292 }
293
294 $this->ctrl->setParameter($this, "record_id", $this->record_id);
295 $this->form->setFormAction($this->ctrl->getFormAction($this));
296 $allFields = $this->table->getRecordFields();
297 $inline_css = '';
298 foreach ($allFields as $field) {
299 $field_setting = $field->getViewSetting($this->tableview_id);
300 if ($field_setting->isVisibleInForm(!$this->record_id)) {
301 $item = ilDclCache::getFieldRepresentation($field)->getInputField($this->form, $this->record_id);
302 if ($item === null) {
303 continue; // Fields calculating values at runtime, e.g. ilDclFormulaFieldModel do not have input
304 }
305
306 if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLocked(!$this->record_id)) {
307 $item->setDisabled(true);
308 }
309
310 $item->setRequired($field_setting->isRequired(!$this->record_id));
311 $default_value = null;
312
313 // If creation mode
314 if (!$this->record_id) {
315 $default_value = ilDclTableViewBaseDefaultValue::findSingle(
316 $field_setting->getFieldObject()->getDatatypeId(),
317 $field_setting->getId()
318 );
319
320 if ($default_value !== null) {
321 if ($item instanceof ilDclCheckboxInputGUI) {
322 $item->setChecked((bool) $default_value->getValue());
323 } else {
324 $item->setValue((string) $default_value->getValue());
325 }
326 }
327 }
328 $this->form->addItem($item);
329 }
330 }
331
332 $this->tpl->addInlineCss($inline_css);
333
334 // Add possibility to change the owner in edit mode
335 if ($this->record_id) {
336 $field_setting = $this->tableview->getFieldSetting('owner');
337 if ($field_setting->isVisibleEdit()) {
338 $ownerField = $this->table->getField('owner');
339 $inputfield = ilDclCache::getFieldRepresentation($ownerField)->getInputField($this->form);
340
341 if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLockedEdit()) {
342 $inputfield->setDisabled(true);
343 } else {
344 $inputfield->setRequired(true);
345 }
346
347 $this->form->addItem($inputfield);
348 }
349 }
350
351 // save and cancel commands
352 if ($this->record_id) {
353 $this->form->setTitle($this->lng->txt("dcl_update_record"));
354 $this->form->addCommandButton("save", $this->lng->txt("dcl_update_record"));
355 if (!$this->ctrl->isAsynch()) {
356 $this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
357 }
358 } else {
359 $this->form->setTitle($this->lng->txt("dcl_add_new_record"));
360 $this->form->addCommandButton("save", $this->lng->txt("save"));
361 if (!$this->ctrl->isAsynch()) {
362 $this->form->addCommandButton("cancelSave", $this->lng->txt("cancel"));
363 }
364 }
365 $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id);
366 $this->ctrl->setParameter($this, "table_id", $this->table_id);
367 $this->ctrl->setParameter($this, "record_id", $this->record_id);
368 }
static getFieldRepresentation(ilDclBaseFieldModel $field)
This class represents a hidden form property in a property form.
static hasWriteAccess(int $ref, ?int $user_id=0)

References ILIAS\Repository\ctrl(), ILIAS\Repository\form(), ilDclCache\getFieldRepresentation(), ilObjDataCollectionAccess\hasWriteAccess(), and ILIAS\Repository\lng().

Referenced by create(), edit(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rebuildUploadsForFileHash()

ilDclRecordEditGUI::rebuildUploadsForFileHash ( bool  $has_ilfilehash)
protected

Definition at line 78 of file class.ilDclRecordEditGUI.php.

78 : string
79 {
80 $hash = "";
81 if ($has_ilfilehash) {
82 // temporary store fileuploads (reuse code from ilPropertyFormGUI)
83 $hash = $this->http->wrapper()->post()->retrieve(
84 'ilfilehash',
85 $this->refinery->kindlyTo()->string()
86 );
87 foreach ($_FILES as $field => $data) {
88 if (is_array($data["tmp_name"])) {
89 foreach ($data["tmp_name"] as $idx => $upload) {
90 if (is_array($upload)) {
91 foreach ($upload as $idx2 => $file) {
92 if ($file && is_uploaded_file($file)) {
93 $file_name = $data["name"][$idx][$idx2];
94 $file_type = $data["type"][$idx][$idx2];
95 $this->form->keepTempFileUpload(
96 $hash,
97 $field,
98 $file,
99 $file_name,
100 $file_type,
101 $idx,
102 $idx2
103 );
104 }
105 }
106 } else {
107 if ($upload && is_uploaded_file($upload)) {
108 $file_name = $data["name"][$idx];
109 $file_type = $data["type"][$idx];
110 $this->form->keepTempFileUpload(
111 $hash,
112 $field,
113 $upload,
114 $file_name,
115 $file_type,
116 $idx
117 );
118 }
119 }
120 }
121 } else {
122 $this->form->keepTempFileUpload(
123 $hash,
124 $field,
125 $data["tmp_name"],
126 $data["name"],
127 $data["type"]
128 );
129 }
130 }
131 }
132 return $hash;
133 }
$data
Definition: storeScorm.php:45

References $data, ILIAS\Repository\form(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilDclRecordEditGUI::save ( )

Definition at line 487 of file class.ilDclRecordEditGUI.php.

487 : void
488 {
489 global $DIC;
490 $ilAppEventHandler = $DIC['ilAppEventHandler'];
491
492 $this->initForm();
493 $this->setFormValues();
494
495 // if save confirmation is enabled: Temporary file-uploads need to be handled
496 $has_save_confirmed = $this->http->wrapper()->post()->has('save_confirmed');
497 $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
498 $has_record_id = isset($this->record_id);
499 $table_has_save_confirmation = $this->table->getSaveConfirmation();
500
501 $ilfilehash = $has_ilfilehash ? $this->http->wrapper()->post()->retrieve(
502 'ilfilehash',
503 $this->refinery->kindlyTo()->string()
504 ) : '';
506
507
508 if ($table_has_save_confirmation
509 && $has_save_confirmed
510 && $has_ilfilehash
511 && !$has_record_id
512 && !$this->ctrl->isAsynch()
513 ) {
514 $has_empty_fileuploads = $this->http->wrapper()->post()->has('empty_fileuploads');
515
516 //handle empty fileuploads, since $_FILES has to have an entry for each fileuploadGUI
517 if ($has_empty_fileuploads) {
518 $empty_fileuploads = $this->http->wrapper()->post()->retrieve(
519 'empty_fileuploads',
520 $this->refinery->kindlyTo()->string()
521 );
522 if (json_decode($empty_fileuploads)) {
523 $_FILES = $_FILES + json_decode($empty_fileuploads, true);
524 }
525 }
526 }
527
528 $valid = $this->form->checkInput();
529
530 $create_mode = ($this->record_id == null);
531 $date_obj = new ilDateTime(time(), IL_CAL_UNIX);
532
533 $record_obj = ilDclCache::getRecordCache($this->record_id);
534 $unchanged_obj = $record_obj;
535 $record_obj->setTableId($this->table_id);
536 $record_obj->setLastUpdate($date_obj);
537 $record_obj->setLastEditBy($this->user->getId());
538
539 if (ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) || $create_mode) {
540 $all_fields = $this->table->getRecordFields();
541 } else {
542 $all_fields = $this->table->getEditableFields(!$this->record_id);
543 }
544
545 // Check if we can create this record.
546 if ($valid) {
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->getMessage());
554 }
555 }
556 }
557
558 if (!$valid) {
559 // Form not valid...
560 //TODO: URL title flushes on invalid form
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(),
572 $this->table_id
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((int) $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((int) $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 = [
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->sendRecordNotification(ilDclNotificationType::RECORD_CREATE, $record_obj);
658 } else {
659 $dispatchEventData['prev_record'] = $unchanged_obj;
660 }
661
662 $record_obj->doUpdate($create_mode);
663
664 $ilAppEventHandler->raise(
665 'components/ILIAS/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
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::class, "listRecords");
691 }
692 }
const IL_CAL_UNIX
@classDescription Date and time handling
static rebuildTempFileByHash(string $hash)
rebuildUploadsForFileHash(bool $has_ilfilehash)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
static _lookupId(string|array $a_user_str)
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.

References $DIC, Vendor\Package\$e, $table_id, ilObjUser\_lookupId(), accessDenied(), checkAndPerformRedirect(), ILIAS\Repository\ctrl(), ilDclBaseRecordModel\doCreate(), ilDclBaseRecordModel\doUpdate(), exit, ILIAS\Repository\form(), ilDclBaseRecordModel\getId(), ilDclCache\getRecordCache(), ilUtil\getSystemMessageHTML(), ilObjDataCollectionAccess\hasPermissionToAddRecord(), ilDclBaseRecordModel\hasPermissionToEdit(), ilObjDataCollectionAccess\hasWriteAccess(), ILIAS\FileDelivery\http(), IL_CAL_UNIX, initForm(), ILIAS\Repository\lng(), ilDclPropertyFormGUI\rebuildTempFileByHash(), rebuildUploadsForFileHash(), ILIAS\Repository\refinery(), sendFailure(), ilDclBaseRecordModel\setCreateDate(), setFormValues(), ilDclBaseRecordModel\setLastEditBy(), ilDclBaseRecordModel\setLastUpdate(), ilDclBaseRecordModel\setOwner(), ilDclBaseRecordModel\setRecordFieldValue(), ilDclBaseRecordModel\setRecordFieldValueFromForm(), ilDclBaseRecordModel\setTableId(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ sendFailure()

ilDclRecordEditGUI::sendFailure ( string  $message)
protected

Definition at line 731 of file class.ilDclRecordEditGUI.php.

731 : 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 }

References $message, ILIAS\Repository\ctrl(), exit, ilDclBaseRecordModel\fillRecordFieldFormInput(), ILIAS\Repository\form(), ilDclBaseRecordModel\getId(), ilDclCache\getRecordCache(), and ilUtil\getSystemMessageHTML().

Referenced by save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFormValues()

ilDclRecordEditGUI::setFormValues ( )

Set values from object to form.

Definition at line 373 of file class.ilDclRecordEditGUI.php.

373 : bool
374 {
375 //Get Record-Values
376 $record_obj = ilDclCache::getRecordCache($this->record_id);
377 if ($record_obj->getId()) {
378 //Get Table Field Definitions
379 $allFields = $this->table->getFields();
380 foreach ($allFields as $field) {
381 if ($field->getDatatypeId() !== ilDclDatatype::INPUTFORMAT_NONE &&
382 $field->getViewSetting($this->tableview_id)->isVisibleEdit()) {
383 $record_obj->fillRecordFieldFormInput($field->getId(), $this->form);
384 }
385 }
386 } else {
387 $this->form->setValuesByPost();
388 }
389
390 return true;
391 }

References ILIAS\Repository\form(), ilDclCache\getRecordCache(), and ilDclDatatype\INPUTFORMAT_NONE.

Referenced by edit(), and save().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ctrl

ilCtrl ilDclRecordEditGUI::$ctrl
protected

Definition at line 37 of file class.ilDclRecordEditGUI.php.

◆ $form

ilDclPropertyFormGUI ilDclRecordEditGUI::$form
protected

Definition at line 41 of file class.ilDclRecordEditGUI.php.

Referenced by getForm().

◆ $http

ILIAS HTTP Services ilDclRecordEditGUI::$http
protected

Definition at line 43 of file class.ilDclRecordEditGUI.php.

◆ $lng

ilLanguage ilDclRecordEditGUI::$lng
protected

Definition at line 39 of file class.ilDclRecordEditGUI.php.

◆ $parent_obj

ilObjDataCollectionGUI ilDclRecordEditGUI::$parent_obj
protected

Definition at line 35 of file class.ilDclRecordEditGUI.php.

Referenced by __construct().

◆ $record

ilDclBaseRecordModel ilDclRecordEditGUI::$record
protected

Definition at line 36 of file class.ilDclRecordEditGUI.php.

Referenced by confirmDelete(), delete(), and getRecordData().

◆ $record_id

int ilDclRecordEditGUI::$record_id = null
protected

Definition at line 32 of file class.ilDclRecordEditGUI.php.

Referenced by getRecordData().

◆ $refinery

ILIAS Refinery Factory ilDclRecordEditGUI::$refinery
protected

Definition at line 44 of file class.ilDclRecordEditGUI.php.

◆ $table

ilDclTable ilDclRecordEditGUI::$table
protected

Definition at line 34 of file class.ilDclRecordEditGUI.php.

◆ $table_id

int ilDclRecordEditGUI::$table_id = 1
protected

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

Referenced by __construct(), and save().

◆ $tableview

ilDclTableView ilDclRecordEditGUI::$tableview
protected

Definition at line 42 of file class.ilDclRecordEditGUI.php.

◆ $tableview_id

int ilDclRecordEditGUI::$tableview_id = null
protected

Definition at line 31 of file class.ilDclRecordEditGUI.php.

Referenced by __construct().

◆ $tpl

ilGlobalPageTemplate ilDclRecordEditGUI::$tpl
protected

Definition at line 38 of file class.ilDclRecordEditGUI.php.

◆ $user

ilObjUser ilDclRecordEditGUI::$user
protected

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

◆ REDIRECT_DETAIL

const ilDclRecordEditGUI::REDIRECT_DETAIL = 2

◆ REDIRECT_RECORD_LIST

const ilDclRecordEditGUI::REDIRECT_RECORD_LIST = 1

Possible redirects after saving/updating a record - use GET['redirect'] to set constants.

Definition at line 28 of file class.ilDclRecordEditGUI.php.

Referenced by checkAndPerformRedirect().


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