ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

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  }
static findOrGetInstance($primary_key, array $add_constructor_args=[])
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
ilObjDataCollectionGUI $parent_obj
+ Here is the call graph for this function:

Member Function Documentation

◆ accessDenied()

ilDclRecordEditGUI::accessDenied ( )
protected

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

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

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

716  : void
717  {
718  if (!$this->ctrl->isAsynch()) {
719  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_no_perm_edit'), true);
720  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords');
721  } else {
722  echo $this->lng->txt('dcl_msg_no_perm_edit');
723  exit();
724  }
725  }
exit
Definition: login.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cancelDelete()

ilDclRecordEditGUI::cancelDelete ( )

Cancel deletion.

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

References ILIAS\Repository\ctrl().

223  : void
224  {
225  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
226  }
+ Here is the call graph for this function:

◆ cancelSave()

◆ cancelUpdate()

ilDclRecordEditGUI::cancelUpdate ( )

Cancel Update.

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

References checkAndPerformRedirect().

Referenced by cancelSave().

398  : void
399  {
400  $this->checkAndPerformRedirect(true);
401  }
checkAndPerformRedirect(bool $force_redirect=false)
Checks to what view (table or detail) should be redirected and performs redirect. ...
+ 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 693 of file class.ilDclRecordEditGUI.php.

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

Referenced by cancelUpdate(), and save().

693  : void
694  {
695  $hasRedirect = $this->http->wrapper()->query()->has('redirect');
696 
697  if ($force_redirect || ($hasRedirect && !$this->ctrl->isAsynch())) {
698  if ($hasRedirect) {
699  $redirect = $this->http->wrapper()->query()->retrieve('redirect', $this->refinery->kindlyTo()->int());
700  switch ($redirect) {
701  case self::REDIRECT_DETAIL:
702  $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'record_id', $this->record_id);
703  $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'table_id', $this->table_id);
704  $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'tableview_id', $this->tableview_id);
705  $this->ctrl->redirectByClass(ilDclDetailedViewGUI::class, "renderRecord");
706  break;
707  case self::REDIRECT_RECORD_LIST:
708  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
709  break;
710  }
711  }
712  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
713  }
714  }
static http()
Fetches the global http state from ILIAS.
+ 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 829 of file class.ilDclRecordEditGUI.php.

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

Referenced by edit().

829  : void
830  {
831  $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash');
832  if ($has_ilfilehash) {
833  $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string());
834  $this->form->cleanupTempFiles($ilfilehash);
835  }
836  }
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
+ 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 195 of file class.ilDclRecordEditGUI.php.

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

195  : 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  }
ilDclBaseRecordModel $record
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
static getRecordCache(?int $record_id)
static getRecordFieldCache(object $record, object $field)
+ Here is the call graph for this function:

◆ create()

ilDclRecordEditGUI::create ( )

Create new record gui.

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

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

171  : void
172  {
173  global $DIC;
174  $DIC->help()->setSubScreenId('create');
175  $this->initForm();
176  $this->tpl->setContent($this->form->getHTML());
177  }
global $DIC
Definition: feed.php:28
initForm()
init Form move parts to RecordRepresentationGUI
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:

◆ delete()

ilDclRecordEditGUI::delete ( )

Remove record.

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

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

231  : 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  }
ilDclBaseRecordModel $record
static getRecordCache(?int $record_id)
doDelete(bool $omit_notification=false)
+ Here is the call graph for this function:

◆ edit()

ilDclRecordEditGUI::edit ( )

Record edit gui.

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

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

182  : void
183  {
184  $this->initForm();
185  $this->cleanupTempFiles();
186 
187  $this->setFormValues();
188  $this->tpl->setContent($this->form->getHTML());
189  }
setFormValues()
Set values from object to form.
cleanupTempFiles()
Cleanup temp-files.
initForm()
init Form move parts to RecordRepresentationGUI
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:

◆ executeCommand()

ilDclRecordEditGUI::executeCommand ( )

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

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

133  : void
134  {
135  $this->getRecord();
136 
137  $cmd = $this->ctrl->getCmd();
138  $this->$cmd();
139  }
+ Here is the call graph for this function:

◆ getForm()

ilDclRecordEditGUI::getForm ( )

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

References $form.

839  {
840  return $this->form;
841  }
Class ilDclPropertyFormGUI ilDclPropertyFormGUI: ilFormPropertyDispatchGUI.
ilDclPropertyFormGUI $form

◆ getRecord()

ilDclRecordEditGUI::getRecord ( )

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

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

Referenced by executeCommand().

141  : 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  }
static hasAddRecordAccess(int $ref, ?int $user_id=0)
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
static getRecordCache(?int $record_id)
+ 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 252 of file class.ilDclRecordEditGUI.php.

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

252  : 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  }
exit
Definition: login.php:29
ilDclBaseRecordModel $record
static http()
Fetches the global http state from ILIAS.
static getRecordCache(?int $record_id)
+ Here is the call graph for this function:

◆ initForm()

ilDclRecordEditGUI::initForm ( )

init Form move parts to RecordRepresentationGUI

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

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

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

274  : 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  }
Class ilDclPropertyFormGUI ilDclPropertyFormGUI: ilFormPropertyDispatchGUI.
static getFieldRepresentation(ilDclBaseFieldModel $field)
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)
form( $class_path, string $cmd, string $submit_caption="")
+ 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 811 of file class.ilDclRecordEditGUI.php.

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

Referenced by searchObjects().

811  : array
812  {
813  $rows = [];
814  foreach ($a_res as $obj_id => $references) {
815  $r = [];
816  $r['title'] = ilObject::_lookupTitle($obj_id);
817  $r['desc'] = ilObject::_lookupDescription($obj_id);
818  $r['obj_id'] = $obj_id;
819  $r['refs'] = $references;
820  $rows[] = $r;
821  }
822 
823  return $rows;
824  }
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
$r
+ 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 76 of file class.ilDclRecordEditGUI.php.

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

Referenced by save().

76  : 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  }
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilDclRecordEditGUI::save ( )

Save record.

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

References $DIC, Vendor\Package\$e, $form, $ref_id, $table_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(), ilDataCollectionMailNotification\TYPE_RECORD_CREATE, and ILIAS\Repository\user().

485  : 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  foreach ($all_fields as $field) {
545  try {
546  $field->checkValidityFromForm($this->form, $this->record_id);
547  } catch (ilDclInputException $e) {
548  $valid = false;
549  $item = $this->form->getItemByPostVar('field_' . $field->getId());
550  $item->setAlert($e->getMessage());
551  }
552  }
553 
554  if (!$valid) {
555  // Form not valid...
556  //TODO: URL title flushes on invalid form
558  $this->form->setValuesByPost();
559  $this->tpl->setContent($this->form->getHTML());
560  $this->sendFailure($this->lng->txt('form_input_not_valid'));
561 
562  return;
563  }
564 
565  if ($create_mode) {
567  $this->parent_obj->getRefId(),
569  ))) {
570  $this->accessDenied();
571 
572  return;
573  }
574 
575  // when save_confirmation is enabled, not yet confirmed and we have not an async-request => prepare for displaying confirmation
576  if ($table_has_save_confirmation && $this->form->getInput('save_confirmed') == null && !$this->ctrl->isAsynch()) {
577  $hash = $this->rebuildUploadsForFileHash($has_ilfilehash);
578 
579  //edit values, they are valid we already checked them above
580  foreach ($all_fields as $field) {
581  $record_obj->setRecordFieldValueFromForm((int) $field->getId(), $this->form);
582  }
583 
584  $this->saveConfirmation($record_obj, $hash);
585 
586  return;
587  }
588 
589  $record_obj->setOwner($this->user->getId());
590  $record_obj->setCreateDate($date_obj);
591  $record_obj->setTableId($this->table_id);
592  $record_obj->doCreate();
593 
594  $this->record_id = $record_obj->getId();
595  } else {
596  if (!$record_obj->hasPermissionToEdit($this->parent_obj->getRefId())) {
597  $this->accessDenied();
598 
599  return;
600  }
601  }
602 
603  //edit values, they are valid we already checked them above
604  foreach ($all_fields as $field) {
605  $field_setting = $field->getViewSetting($this->tableview_id);
606 
607  if ($field_setting->isVisibleInForm($create_mode) &&
608  (!$field_setting->isLocked($create_mode) || ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()))) {
609  // set all visible fields
610  $record_obj->setRecordFieldValueFromForm((int) $field->getId(), $this->form);
611  } elseif ($create_mode) {
612  // set default values when creating
613  $default_value = ilDclTableViewBaseDefaultValue::findSingle(
614  $field_setting->getFieldObject()->getDatatypeId(),
615  $field_setting->getId()
616  );
617  if ($default_value !== null) {
618  $record_obj->setRecordFieldValue($field->getId(), $default_value->getValue());
619  }
620  }
621  }
622 
623  // Do we need to set a new owner for this record?
624  if (!$create_mode && $this->tableview->getFieldSetting('owner')->isVisibleEdit()) {
625  if ($this->http->wrapper()->post()->has('field_owner')) {
626  $field_owner = $this->http->wrapper()->post()->retrieve(
627  'field_owner',
628  $this->refinery->kindlyTo()->string()
629  );
630  $owner_id = ilObjUser::_lookupId($field_owner);
631  if (!$owner_id) {
632  $this->sendFailure($this->lng->txt('user_not_known'));
633 
634  return;
635  }
636  $record_obj->setOwner($owner_id);
637  }
638  }
639 
640  $dispatchEvent = "update";
641 
642  $dispatchEventData = [
643  'dcl' => $this->parent_obj->getDataCollectionObject(),
644  'table_id' => $this->table_id,
645  'record_id' => $record_obj->getId(),
646  'record' => $record_obj,
647  ];
648 
649  if ($create_mode) {
650  $dispatchEvent = "create";
651  $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
652  $objDataCollection = new ilObjDataCollection($ref_id);
653  $objDataCollection->sendRecordNotification(ilDataCollectionMailNotification::TYPE_RECORD_CREATE, $record_obj);
654  } else {
655  $dispatchEventData['prev_record'] = $unchanged_obj;
656  }
657 
658  $record_obj->doUpdate($create_mode);
659 
660  $ilAppEventHandler->raise(
661  'Modules/DataCollection',
662  $dispatchEvent . 'Record',
663  $dispatchEventData
664  );
665 
666  $this->ctrl->setParameter($this, "table_id", $this->table_id);
667  $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id);
668  $this->ctrl->setParameter($this, "record_id", $this->record_id);
669 
670  if (!$this->ctrl->isAsynch()) {
671  $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
672  }
673 
674  $this->checkAndPerformRedirect();
675  if ($this->ctrl->isAsynch()) {
676  // If ajax request, return the form in edit mode again
677  $this->record_id = $record_obj->getId();
678  $this->initForm();
679  $this->setFormValues();
681  $this->lng->txt('msg_obj_modified'),
682  'success'
683  ) . $this->form->getHTML();
684  exit();
685  } else {
686  $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
687  }
688  }
setFormValues()
Set values from object to form.
exit
Definition: login.php:29
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
$valid
static _lookupId($a_user_str)
static rebuildTempFileByHash(string $hash)
const IL_CAL_UNIX
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
rebuildUploadsForFileHash(bool $has_ilfilehash)
initForm()
init Form move parts to RecordRepresentationGUI
static hasWriteAccess(int $ref, ?int $user_id=0)
ilDclPropertyFormGUI $form
static getRecordCache(?int $record_id)
form( $class_path, string $cmd, string $submit_caption="")
static hasPermissionToAddRecord(int $ref_id, int $table_id)
checkAndPerformRedirect(bool $force_redirect=false)
Checks to what view (table or detail) should be redirected and performs redirect. ...
+ 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 761 of file class.ilDclRecordEditGUI.php.

References $path, $res, $results, 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().

761  : void
762  {
763  $search = $this->http->wrapper()->post()->retrieve('search_for', $this->refinery->kindlyTo()->string());
764  $dest = $this->http->wrapper()->post()->retrieve('dest', $this->refinery->kindlyTo()->string());
765  $html = "";
766  $query_parser = new ilQueryParser($search);
767  $query_parser->setMinWordLength(1);
768  $query_parser->setCombination(ilQueryParser::QP_COMBINATION_AND);
769  $query_parser->parse();
770  if (!$query_parser->validate()) {
771  $html .= $query_parser->getMessage() . "<br />";
772  }
773 
774  // only like search since fulltext does not support search with less than 3 characters
775  $object_search = new ilLikeObjectSearch($query_parser);
776  $res = $object_search->performSearch();
777  //$res->setRequiredPermission('copy');
778  $res->filter(ROOT_FOLDER_ID, true);
779 
780  if (!count($results = $res->getResultsByObjId())) {
781  $html .= $this->lng->txt('dcl_no_search_results_found_for') . ' ' . $search . "<br />";
782  }
784 
785  foreach ($results as $entry) {
786  $tpl = new ilTemplate("tpl.dcl_tree.html", true, true, "Modules/DataCollection");
787  foreach ((array) $entry['refs'] as $reference) {
788  $path = new ilPathGUI();
789  $tpl->setCurrentBlock('result');
790  $tpl->setVariable(
791  'RESULT_PATH',
792  $path->getPath(ROOT_FOLDER_ID, (int) $reference) . " ยป " . $entry['title']
793  );
794  $tpl->setVariable('RESULT_REF', $reference);
795  $tpl->setVariable('FIELD_ID', $dest);
797  }
798  $html .= $tpl->get();
799  }
800 
801  echo $html;
802  exit;
803  }
Creates a path for a start and endnode.
$res
Definition: ltiservices.php:69
exit
Definition: login.php:29
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
const ROOT_FOLDER_ID
Definition: constants.php:32
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
ilGlobalPageTemplate $tpl
$path
Definition: ltiservices.php:32
static http()
Fetches the global http state from ILIAS.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$results
parseSearchResults(array $a_res)
Parse search results.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
+ Here is the call graph for this function:

◆ sendFailure()

ilDclRecordEditGUI::sendFailure ( string  $message)
protected

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

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

Referenced by save().

727  : void
728  {
729  $keep = !$this->ctrl->isAsynch();
730  $this->form->setValuesByPost();
731  if ($this->ctrl->isAsynch()) {
732  echo ilUtil::getSystemMessageHTML($message, 'failure') . $this->form->getHTML();
733  exit();
734  } else {
735  $this->tpl->setOnScreenMessage('failure', $message, $keep);
736 
737  // Fill locked fields on edit mode - otherwise they are empty (workaround)
738  if (isset($this->record_id) && $this->record_id) {
739  $record_obj = ilDclCache::getRecordCache($this->record_id);
740  if ($record_obj->getId()) {
741  //Get Table Field Definitions
742  $allFields = $this->table->getFields();
743  foreach ($allFields as $field) {
744  $field_setting = $field->getViewSetting($this->tableview_id);
745  if (
746  $field_setting->isLockedEdit() &&
747  $field_setting->isVisibleEdit()
748  ) {
749  $record_obj->fillRecordFieldFormInput($field->getId(), $this->form);
750  }
751  }
752  }
753  }
754  $this->tpl->setContent($this->form->getHTML());
755  }
756  }
exit
Definition: login.php:29
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
ilDclPropertyFormGUI $form
static getRecordCache(?int $record_id)
form( $class_path, string $cmd, string $submit_caption="")
$message
Definition: xapiexit.php:32
+ 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 375 of file class.ilDclRecordEditGUI.php.

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

Referenced by edit(), and save().

375  : 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  }
ilDclPropertyFormGUI $form
static getRecordCache(?int $record_id)
form( $class_path, string $cmd, string $submit_caption="")
+ 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 35 of file class.ilDclRecordEditGUI.php.

◆ $form

ilDclPropertyFormGUI ilDclRecordEditGUI::$form
protected

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

Referenced by getForm(), save(), sendFailure(), and setFormValues().

◆ $http

ILIAS HTTP Services ilDclRecordEditGUI::$http
protected

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

◆ $lng

ilLanguage ilDclRecordEditGUI::$lng
protected

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

◆ $parent_obj

ilObjDataCollectionGUI ilDclRecordEditGUI::$parent_obj
protected

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

Referenced by __construct().

◆ $record

ilDclBaseRecordModel ilDclRecordEditGUI::$record
protected

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

Referenced by delete().

◆ $record_id

int ilDclRecordEditGUI::$record_id = null
protected

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

Referenced by getRecordData().

◆ $refinery

ILIAS Refinery Factory ilDclRecordEditGUI::$refinery
protected

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

◆ $table

ilDclTable ilDclRecordEditGUI::$table
protected

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

◆ $table_id

int ilDclRecordEditGUI::$table_id = 1
protected

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

Referenced by __construct(), and save().

◆ $tableview

ilDclTableView ilDclRecordEditGUI::$tableview
protected

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

◆ $tableview_id

int ilDclRecordEditGUI::$tableview_id = null
protected

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

Referenced by __construct().

◆ $tpl

ilGlobalPageTemplate ilDclRecordEditGUI::$tpl
protected

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

◆ $user

ilObjUser ilDclRecordEditGUI::$user
protected

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

◆ REDIRECT_DETAIL

const ilDclRecordEditGUI::REDIRECT_DETAIL = 2

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

Referenced by ilDclDetailedViewGUI\renderRecord().

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


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