19 declare(strict_types=1);
48 $this->
http = $DIC->http();
51 $this->
ctrl = $DIC[
'ilCtrl'];
52 $this->tpl = $DIC[
'tpl'];
53 $this->
lng = $DIC[
'lng'];
54 $this->
user = $DIC[
'ilUser'];
56 $this->
http = $DIC->http();
61 if ($this->
http->wrapper()->query()->has(
'record_id')) {
62 $this->record_id = $this->
http->wrapper()->query()->retrieve(
67 if ($this->
http->wrapper()->post()->has(
'record_id')) {
68 $this->record_id = $this->
http->wrapper()->post()->retrieve(
79 if ($has_ilfilehash) {
81 $hash = $this->
http->wrapper()->post()->retrieve(
83 $this->
refinery->kindlyTo()->string()
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(
105 if ($upload && is_uploaded_file($upload)) {
106 $file_name =
$data[
"name"][$idx];
107 $file_type =
$data[
"type"][$idx];
108 $this->
form->keepTempFileUpload(
120 $this->
form->keepTempFileUpload(
137 $cmd = $this->
ctrl->getCmd();
143 $hasMode = $this->
http->wrapper()->query()->has(
'mode');
145 $mode = $this->
http->wrapper()->query()->retrieve(
'mode', $this->
refinery->kindlyTo()->string());
147 $this->
ctrl->saveParameter($this,
'mode');
148 $this->
ctrl->setParameterByClass(ilDclRecordListGUI::class,
"mode", $mode);
150 $this->
ctrl->setParameterByClass(ilDclRecordListGUI::class,
'tableview_id', $this->tableview_id);
151 $this->
ctrl->saveParameter($this,
'redirect');
152 if ($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())) {
157 $this->table = $this->record->getTable();
158 $this->table_id = $this->table->getId();
161 $ref_id = $this->
http->wrapper()->query()->retrieve(
'ref_id', $this->
refinery->kindlyTo()->int());
174 $DIC->help()->setSubScreenId(
'create');
176 $this->tpl->setContent($this->
form->getHTML());
188 $this->tpl->setContent($this->
form->getHTML());
198 $conf->setFormAction($this->
ctrl->getFormAction($this));
199 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_record'));
202 $all_fields = $this->table->getRecordFields();
204 foreach ($all_fields as $field) {
208 if ($record_representation->getConfirmationHTML() !=
false) {
209 $record_data .= $field->getTitle() .
": " . $record_representation->getConfirmationHTML() .
"<br />";
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());
225 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
"listRecords");
231 public function delete():
void 235 if (!$this->table->hasPermissionToDeleteRecord($this->parent_obj->getRefId(),
$record)) {
242 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"dcl_record_deleted"),
true);
243 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
"listRecords");
254 $get_record_id = $this->
http->wrapper()->query()->retrieve(
'record_id', $this->
refinery->kindlyTo()->int());
262 if ($this->
ctrl->isAsynch()) {
263 echo json_encode($return);
277 $prefix = ($this->
ctrl->isAsynch()) ?
'dclajax' :
'dcl';
278 $this->
form->setId($prefix . $this->table_id . $this->record_id);
281 $hidden_prop->setValue((
string) $this->table_id);
282 $this->
form->addItem($hidden_prop);
284 $hidden_prop->setValue((
string) $this->tableview_id);
285 $this->
form->addItem($hidden_prop);
286 if ($this->record_id) {
288 $hidden_prop->setValue((
string) $this->record_id);
289 $this->
form->addItem($hidden_prop);
292 $this->
ctrl->setParameter($this,
"record_id", $this->record_id);
293 $this->
form->setFormAction($this->
ctrl->getFormAction($this));
294 $allFields = $this->table->getRecordFields();
296 foreach ($allFields as $field) {
297 $field_setting = $field->getViewSetting($this->tableview_id);
298 if ($field_setting->isVisibleInForm(!$this->record_id)) {
300 if ($item ===
null) {
305 $item->setDisabled(
true);
308 $item->setRequired($field_setting->isRequired(!$this->record_id));
309 $default_value =
null;
312 if (!$this->record_id) {
313 $default_value = ilDclTableViewBaseDefaultValue::findSingle(
314 $field_setting->getFieldObject()->getDatatypeId(),
315 $field_setting->getId()
318 if ($default_value !==
null) {
320 $item->setChecked((
bool) $default_value->getValue());
322 $item->setValue((
string) $default_value->getValue());
330 $this->
form->addItem($item);
334 $this->tpl->addInlineCss($inline_css);
337 if ($this->record_id) {
338 $field_setting = $this->tableview->getFieldSetting(
'owner');
339 if ($field_setting->isVisibleEdit()) {
340 $ownerField = $this->table->getField(
'owner');
344 $inputfield->setDisabled(
true);
346 $inputfield->setRequired(
true);
349 $this->
form->addItem($inputfield);
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"));
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"));
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);
379 if ($record_obj->getId()) {
381 $allFields = $this->table->getFields();
382 foreach ($allFields as $field) {
384 $field->getViewSetting($this->tableview_id)->isVisibleEdit()) {
385 $record_obj->fillRecordFieldFormInput($field->getId(),
$this->form);
389 $this->
form->setValuesByPost();
420 $all_fields = $this->table->getRecordFields();
422 $all_fields = $this->table->getEditableFields(!$this->record_id);
431 $confirmation->setFormAction($this->
ctrl->getFormAction($this));
432 $header_text = $this->
lng->txt(
'dcl_confirm_storing_records');
434 && !$this->table->getEditByOwner()
435 && !$this->table->getEditPerm()
437 $header_text .=
" " . $this->
lng->txt(
'dcl_confirm_storing_records_no_permission');
439 $confirmation->setHeaderText($header_text);
441 $confirmation->setCancel($this->
lng->txt(
'dcl_edit_record'),
'edit');
442 $confirmation->setConfirm($this->
lng->txt(
'dcl_save_record'),
'save');
446 $empty_fileuploads = [];
447 foreach ($all_fields as $field) {
448 $record_field = $record_obj->
getRecordField((
int) $field->getId());
450 $record_field->addHiddenItemsToConfirmation($confirmation);
453 $empty_fileuploads[
'field_' . $field->getId()] = [
463 if ($record_representation->getConfirmationHTML() !==
'') {
464 $record_data .= $field->getTitle() .
": " . $record_representation->getConfirmationHTML() .
"<br />";
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);
474 if ($this->
ctrl->isAsynch()) {
475 echo $confirmation->getHTML();
478 $this->tpl->setContent($confirmation->getHTML());
488 $ilAppEventHandler = $DIC[
'ilAppEventHandler'];
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();
499 $ilfilehash = $has_ilfilehash ? $this->
http->wrapper()->post()->retrieve(
501 $this->
refinery->kindlyTo()->string()
506 if ($table_has_save_confirmation
507 && $has_save_confirmed
510 && !$this->
ctrl->isAsynch()
512 $has_empty_fileuploads = $this->
http->wrapper()->post()->has(
'empty_fileuploads');
515 if ($has_empty_fileuploads) {
516 $empty_fileuploads = $this->
http->wrapper()->post()->retrieve(
518 $this->
refinery->kindlyTo()->string()
520 if (json_decode($empty_fileuploads)) {
521 $_FILES = $_FILES + json_decode($empty_fileuploads,
true);
528 $create_mode = ($this->record_id ==
null);
532 $unchanged_obj = $record_obj;
538 $all_fields = $this->table->getRecordFields();
540 $all_fields = $this->table->getEditableFields(!$this->record_id);
545 foreach ($all_fields as $field) {
547 $field->checkValidityFromForm($this->
form, $this->record_id);
550 $item = $this->
form->getItemByPostVar(
'field_' . $field->getId());
551 $item->setAlert($e->getMessage());
560 $this->
form->setValuesByPost();
561 $this->tpl->setContent($this->
form->getHTML());
569 $this->parent_obj->getRefId(),
578 if ($table_has_save_confirmation && $this->
form->getInput(
'save_confirmed') ==
null && !$this->
ctrl->isAsynch()) {
582 foreach ($all_fields as $field) {
586 $this->saveConfirmation($record_obj, $hash);
596 $this->record_id = $record_obj->
getId();
606 foreach ($all_fields as $field) {
607 $field_setting = $field->getViewSetting($this->tableview_id);
609 if ($field_setting->isVisibleInForm($create_mode) &&
613 } elseif ($create_mode) {
615 $default_value = ilDclTableViewBaseDefaultValue::findSingle(
616 $field_setting->getFieldObject()->getDatatypeId(),
617 $field_setting->getId()
619 if ($default_value !==
null) {
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(
630 $this->
refinery->kindlyTo()->string()
642 $dispatchEvent =
"update";
644 $dispatchEventData = [
645 'dcl' => $this->parent_obj->getDataCollectionObject(),
647 'record_id' => $record_obj->
getId(),
648 'record' => $record_obj,
652 $dispatchEvent =
"create";
653 $ref_id = $this->
http->wrapper()->query()->retrieve(
'ref_id', $this->
refinery->kindlyTo()->int());
655 $objDataCollection->sendNotification(
"new_record", $this->table_id, $record_obj->
getId());
657 $dispatchEventData[
'prev_record'] = $unchanged_obj;
660 $record_obj->
doUpdate($create_mode);
662 $ilAppEventHandler->raise(
663 'components/ILIAS/DataCollection',
664 $dispatchEvent .
'Record',
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);
672 if (!$this->
ctrl->isAsynch()) {
673 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"msg_obj_modified"),
true);
677 if ($this->
ctrl->isAsynch()) {
679 $this->record_id = $record_obj->
getId();
683 $this->
lng->txt(
'msg_obj_modified'),
685 ) . $this->
form->getHTML();
688 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
"listRecords");
697 $hasRedirect = $this->
http->wrapper()->query()->has(
'redirect');
699 if ($force_redirect || ($hasRedirect && !$this->
ctrl->isAsynch())) {
701 $redirect = $this->
http->wrapper()->query()->retrieve(
'redirect', $this->
refinery->kindlyTo()->int());
703 case self::REDIRECT_DETAIL:
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");
709 case self::REDIRECT_RECORD_LIST:
710 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
"listRecords");
714 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
"listRecords");
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');
724 echo $this->
lng->txt(
'dcl_msg_no_perm_edit');
731 $keep = !$this->
ctrl->isAsynch();
732 $this->
form->setValuesByPost();
733 if ($this->
ctrl->isAsynch()) {
737 $this->tpl->setOnScreenMessage(
'failure', $message, $keep);
740 if (isset($this->record_id) && $this->record_id) {
742 if ($record_obj->
getId()) {
744 $allFields = $this->table->getFields();
745 foreach ($allFields as $field) {
746 $field_setting = $field->getViewSetting($this->tableview_id);
748 $field_setting->isLockedEdit() &&
749 $field_setting->isVisibleEdit()
756 $this->tpl->setContent($this->
form->getHTML());
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());
769 $query_parser->setMinWordLength(1);
771 $query_parser->parse();
772 if (!$query_parser->validate()) {
773 $html .= $query_parser->getMessage() .
"<br />";
778 $res = $object_search->performSearch();
783 $html .= $this->
lng->txt(
'dcl_no_search_results_found_for') .
' ' . $search .
"<br />";
788 $tpl =
new ilTemplate(
"tpl.dcl_tree.html",
true,
true,
"components/ILIAS/DataCollection");
789 foreach ((array) $entry[
'refs'] as $reference) {
800 $html .= $tpl->
get();
816 foreach ($a_res as $obj_id => $references) {
820 $r[
'obj_id'] = $obj_id;
821 $r[
'refs'] = $references;
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);
setFormValues()
Set values from object to form.
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
cleanupTempFiles()
Cleanup temp-files.
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
sendFailure(string $message)
static findOrGetInstance($primary_key, array $add_constructor_args=[])
AutoloadingIssuesInspection
__construct(ilObjDataCollectionGUI $parent_obj, int $table_id, int $tableview_id)
static hasAddRecordAccess(int $ref, ?int $user_id=0)
doUpdate(bool $omit_notification=false)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
cancelUpdate()
Cancel Update.
ilDclBaseRecordModel $record
static _lookupId($a_user_str)
ilGlobalPageTemplate $tpl
ILIAS Refinery Factory $refinery
hasPermissionToEdit(int $ref_id)
create()
Create new record gui.
setRecordFieldValue($field_id, $value)
getRecordField(int $field_id)
static getFieldRepresentation(ilDclBaseFieldModel $field)
setRecordFieldValueFromForm(int $field_id, ilPropertyFormGUI $form)
Set a field value.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI ilObjDataCollectionG...
static http()
Fetches the global http state from ILIAS.
ilDclTableView $tableview
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
static _lookupTitle(int $obj_id)
ILIAS HTTP Services $http
searchObjects()
This function is only used by the ajax request if searching for ILIAS references. ...
rebuildUploadsForFileHash(bool $has_ilfilehash)
initForm()
init Form move parts to RecordRepresentationGUI
const REDIRECT_RECORD_LIST
Possible redirects after saving/updating a record - use GET['redirect'] to set constants.
confirmDelete()
Delete confirmation.
static getTableCache(?int $table_id=null)
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
static hasWriteAccess(int $ref, ?int $user_id=0)
static _lookupDescription(int $obj_id)
ilDclPropertyFormGUI $form
cancelDelete()
Cancel deletion.
getRecordData(int $record_id=0)
Return All fields and values from a record ID.
setLastEditBy(?int $last_edit_by)
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
static getRecordCache(?int $record_id)
setCreateDate(ilDateTime $a_datetime)
form( $class_path, string $cmd, string $submit_caption="")
parseSearchResults(array $a_res)
Parse search results.
setLastUpdate(ilDateTime $a_datetime)
static hasPermissionToAddRecord(int $ref_id, int $table_id)
static getRecordFieldCache(object $record, object $field)
checkAndPerformRedirect(bool $force_redirect=false)
Checks to what view (table or detail) should be redirected and performs redirect. ...
static hasEditAccess(int $ref, ?int $user_id=0)
doDelete(bool $omit_notification=false)
fillRecordFieldFormInput($field_id, ilPropertyFormGUI $form)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
ilObjDataCollectionGUI $parent_obj