ILIAS  release_8 Revision v8.24
ilDclRecordEditGUI Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ 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 ()
 Save record. More...
 
 searchObjects ()
 This function is only used by the ajax request if searching for ILIAS references. More...
 
 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)
 
 parseSearchResults (array $a_res)
 Parse search results. More...
 
 cleanupTempFiles ()
 Cleanup temp-files. More...
 

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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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 }
ilObjDataCollectionGUI $parent_obj
static findOrGetInstance($primary_key, array $add_constructor_args=array())
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.

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', 'listRecords');
725 } else {
726 echo $this->lng->txt('dcl_msg_no_perm_edit');
727 exit();
728 }
729 }
exit
Definition: login.php:28

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 222 of file class.ilDclRecordEditGUI.php.

222 : void
223 {
224 $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
225 }

References ILIAS\Repository\ctrl().

+ Here is the call graph for this function:

◆ cancelSave()

ilDclRecordEditGUI::cancelSave ( )

Cancel Save.

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

407 : void
408 {
409 $this->cancelUpdate();
410 }

References cancelUpdate().

+ Here is the call graph for this function:

◆ cancelUpdate()

ilDclRecordEditGUI::cancelUpdate ( )

Cancel Update.

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

399 : void
400 {
401 $this->checkAndPerformRedirect(true);
402 }
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', '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;
712 $this->ctrl->redirectByClass("ildclrecordlistgui", "listRecords");
713 break;
714 }
715 }
716 $this->ctrl->redirectByClass("ildclrecordlistgui", "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

Cleanup temp-files.

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

833 : 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 }
form( $class_path, string $cmd)

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 194 of file class.ilDclRecordEditGUI.php.

194 : 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 }
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 172 of file class.ilDclRecordEditGUI.php.

172 : void
173 {
174 $this->initForm();
175 $this->tpl->setContent($this->form->getHTML());
176 }
initForm()
init Form @move move parts to RecordRepresentationGUI

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

+ Here is the call graph for this function:

◆ delete()

ilDclRecordEditGUI::delete ( )

Remove record.

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

230 : 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 }
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 181 of file class.ilDclRecordEditGUI.php.

181 : void
182 {
183 $this->initForm();
184 $this->cleanupTempFiles();
185
186 $this->setFormValues();
187 $this->tpl->setContent($this->form->getHTML());
188 }
setFormValues()
Set values from object to form.
cleanupTempFiles()
Cleanup temp-files.

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

+ Here is the call graph for this function:

◆ executeCommand()

ilDclRecordEditGUI::executeCommand ( )

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

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

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

+ Here is the call graph for this function:

◆ getForm()

ilDclRecordEditGUI::getForm ( )

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

843 {
844 return $this->form;
845 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilDclPropertyFormGUI $form

References $form.

◆ getRecord()

ilDclRecordEditGUI::getRecord ( )

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

142 : 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 }
static getTableCache(int $table_id=null)
static hasAddRecordAccess(int $ref, ?int $user_id=0)
$ref_id
Definition: ltiauth.php:67

References $ref_id, 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 251 of file class.ilDclRecordEditGUI.php.

251 : 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) {
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 }

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 275 of file class.ilDclRecordEditGUI.php.

275 : 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 }
static getFieldRepresentation(ilDclBaseFieldModel $field)
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 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:

◆ parseSearchResults()

ilDclRecordEditGUI::parseSearchResults ( array  $a_res)
protected

Parse search results.

Parameters
ilObject[]$a_res
Returns
array

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

815 : 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 }
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
$rows
Definition: xhr_table.php:10

References $rows, ilObject\_lookupDescription(), and ilObject\_lookupTitle().

Referenced by searchObjects().

+ 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 77 of file class.ilDclRecordEditGUI.php.

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

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 ( )

Save record.

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

488 : 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(),
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($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
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 }
const IL_CAL_UNIX
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static rebuildTempFileByHash(string $hash)
rebuildUploadsForFileHash(bool $has_ilfilehash)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupId($a_user_str)
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
$valid

References $DIC, Vendor\Package\$e, $ref_id, $valid, 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:

◆ searchObjects()

ilDclRecordEditGUI::searchObjects ( )

This function is only used by the ajax request if searching for ILIAS references.

It builds the html for the search results.

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

765 : 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');
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);
801 }
802 $html .= $tpl->get();
803 }
804
805 echo $html;
806 exit;
807 }
ilGlobalPageTemplate $tpl
parseSearchResults(array $a_res)
Parse search results.
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.
Creates a path for a start and endnode.
special template class to simplify handling of ITX/PEAR
const ROOT_FOLDER_ID
Definition: constants.php:32
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$results

References $path, $res, $results, $tpl, exit, ilGlobalPageTemplate\get(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ilGlobalPageTemplate\parseCurrentBlock(), parseSearchResults(), ilQueryParser\QP_COMBINATION_AND, ILIAS\Repository\refinery(), ROOT_FOLDER_ID, ilGlobalPageTemplate\setCurrentBlock(), and ilGlobalPageTemplate\setVariable().

+ 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 }
$message
Definition: xapiexit.php:32

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 376 of file class.ilDclRecordEditGUI.php.

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

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 33 of file class.ilDclRecordEditGUI.php.

◆ $form

ilDclPropertyFormGUI ilDclRecordEditGUI::$form
protected

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

Referenced by getForm().

◆ $http

ILIAS HTTP Services ilDclRecordEditGUI::$http
protected

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

◆ $lng

ilLanguage ilDclRecordEditGUI::$lng
protected

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

◆ $parent_obj

ilObjDataCollectionGUI ilDclRecordEditGUI::$parent_obj
protected

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

Referenced by __construct().

◆ $record

◆ $record_id

int ilDclRecordEditGUI::$record_id = null
protected

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

Referenced by getRecordData().

◆ $refinery

ILIAS Refinery Factory ilDclRecordEditGUI::$refinery
protected

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

◆ $table

ilDclTable ilDclRecordEditGUI::$table
protected

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

◆ $table_id

int ilDclRecordEditGUI::$table_id = 1
protected

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

Referenced by __construct().

◆ $tableview

ilDclTableView ilDclRecordEditGUI::$tableview
protected

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

◆ $tableview_id

int ilDclRecordEditGUI::$tableview_id = null
protected

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

Referenced by __construct().

◆ $tpl

ilGlobalPageTemplate ilDclRecordEditGUI::$tpl
protected

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

Referenced by searchObjects().

◆ $user

ilObjUser ilDclRecordEditGUI::$user
protected

Definition at line 36 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 24 of file class.ilDclRecordEditGUI.php.

Referenced by checkAndPerformRedirect().


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