ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilDclFieldEditGUI Class Reference
+ Collaboration diagram for ilDclFieldEditGUI:

Public Member Functions

 __construct (ilDclTableListGUI $a_parent_obj)
 Constructor. More...
 
 executeCommand ()
 execute command More...
 
 create ()
 create field add form More...
 
 edit ()
 create field edit form More...
 
 permissionDenied ()
 
 confirmDelete ()
 confirmDelete More...
 
 cancelDelete ()
 cancelDelete More...
 
 delete ()
 
 cancel ()
 
 initForm (string $a_mode="create")
 initEditCustomForm More...
 
 save (string $a_mode="create")
 save Field More...
 
 getDataCollectionObject ()
 

Protected Member Functions

 checkInput (string $a_mode)
 Check input of form. More...
 
 checkAccess ()
 

Protected Attributes

int $obj_id
 
int $table_id
 
ilDclTableListGUI $parent_obj
 
ilDclTable $table
 
ilPropertyFormGUI $form
 
ilDclBaseFieldModel $field_obj
 
ilHelpGUI $help
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 
int $field_id
 

Private Attributes

ilGlobalTemplateInterface $main_tpl
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilDclFieldEditGUI::__construct ( ilDclTableListGUI  $a_parent_obj)

Constructor.

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

References $DIC, ilDclDatatype\getAllDatatype(), ilDclCache\getFieldCache(), ilDclFieldFactory\getFieldModelInstance(), ilDclTableListGUI\getObjId(), ilDclCache\getTableCache(), ILIAS\Repository\help(), ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

40  {
41  global $DIC;
42  $this->main_tpl = $DIC->ui()->mainTemplate();
43  $ilCtrl = $DIC['ilCtrl'];
44 
45  $this->obj_id = $a_parent_obj->getObjId();
46  $this->parent_obj = $a_parent_obj;
47  $this->help = $DIC->help();
48  $this->http = $DIC->http();
49  $this->refinery = $DIC->refinery();
50 
51  $this->table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
52 
53  $hasFieldId = $this->http->wrapper()->query()->has('field_id');
54  if ($hasFieldId) {
55  $this->field_id = $this->http->wrapper()->query()->retrieve('field_id', $this->refinery->kindlyTo()->int());
56  } else {
57  $this->field_id = 0;
58  }
59 
60  if ($this->field_id) {
61  $this->field_obj = ilDclCache::getFieldCache($this->field_id);
62  } else {
63  $datatype = null;
64 
65  $has_datatype = $this->http->wrapper()->post()->has('datatype');
66 
67  if ($has_datatype) {
68  $datatype_value = $this->http->wrapper()->post()->retrieve(
69  'datatype',
70  $this->refinery->kindlyTo()->int()
71  );
72  if (in_array(
73  $datatype_value,
74  array_keys(ilDclDatatype::getAllDatatype())
75  )) {
76  $datatype = $datatype_value;
77  }
78  }
79  $this->field_obj = ilDclFieldFactory::getFieldModelInstance($this->field_id, $datatype);
80  if (!$this->table_id) {
81  $ilCtrl->redirectByClass("ilDclTableListGUI", "listFields");
82  }
83  $this->field_obj->setTableId($this->table_id);
84  $ilCtrl->saveParameter($this, "table_id");
85  }
86 
87  $this->table = ilDclCache::getTableCache($this->table_id);
88  }
static getFieldCache(int $field_id=0)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
static getFieldModelInstance(int $field_id, ?int $datatype=null)
Get FieldModel from field-id and datatype.
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
+ Here is the call graph for this function:

Member Function Documentation

◆ cancel()

ilDclFieldEditGUI::cancel ( )

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

References $DIC.

197  : void
198  {
199  global $DIC;
200  $ilCtrl = $DIC['ilCtrl'];
201  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
202  }
global $DIC
Definition: feed.php:28

◆ cancelDelete()

ilDclFieldEditGUI::cancelDelete ( )

cancelDelete

Definition at line 174 of file class.ilDclFieldEditGUI.php.

References $DIC.

174  : void
175  {
176  global $DIC;
177  $ilCtrl = $DIC['ilCtrl'];
178 
179  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
180  }
global $DIC
Definition: feed.php:28

◆ checkAccess()

ilDclFieldEditGUI::checkAccess ( )
protected
Returns
bool

Definition at line 376 of file class.ilDclFieldEditGUI.php.

References getDataCollectionObject(), ilObjDataCollectionAccess\hasAccessToField(), and ilObjDataCollectionAccess\hasAccessToFields().

Referenced by executeCommand().

376  : bool
377  {
378  if ($field_id = $this->field_obj->getId()) {
380  $this->getDataCollectionObject()->getRefId(),
381  $this->table_id,
382  (int) $field_id
383  );
384  } else {
386  $this->getDataCollectionObject()->getRefId(),
387  $this->table_id
388  );
389  }
390  }
static hasAccessToFields(int $ref_id, int $table_id)
static hasAccessToField(int $ref_id, int $table_id, int $field_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkInput()

ilDclFieldEditGUI::checkInput ( string  $a_mode)
protected

Check input of form.

Parameters
$a_mode'create' | 'update'
Returns
bool

Definition at line 337 of file class.ilDclFieldEditGUI.php.

References $DIC, $lng, ilDclTable\_hasFieldByTitle(), ILIAS\Repository\form(), and ilDclFieldFactory\getFieldModelInstanceByClass().

Referenced by save().

337  : bool
338  {
339  global $DIC;
340  $lng = $DIC['lng'];
341  $return = $this->form->checkInput();
342 
343  // load specific model for input checking
344  $datatype_id = $this->form->getInput('datatype');
345  if ($datatype_id != null && is_numeric($datatype_id)) {
346  $base_model = new ilDclBaseFieldModel();
347  $base_model->setDatatypeId((int) $datatype_id);
348  $field_validation_class = ilDclFieldFactory::getFieldModelInstanceByClass($base_model);
349 
350  if (!$field_validation_class->checkFieldCreationInput($this->form)) {
351  $return = false;
352  }
353  }
354 
355  // Don't allow multiple fields with the same title in this table
356  if ($a_mode == 'create') {
357  if ($title = $this->form->getInput('title')) {
358  if (ilDclTable::_hasFieldByTitle($title, $this->table_id)) {
359  $inputObj = $this->form->getItemByPostVar('title');
360  $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
361  $return = false;
362  }
363  }
364  }
365 
366  if (!$return) {
367  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("form_input_not_valid"));
368  }
369 
370  return $return;
371  }
global $DIC
Definition: feed.php:28
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, ?int $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
$lng
static _hasFieldByTitle(string $title, int $obj_id)
Checks if a table has a field with the given title.
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()

ilDclFieldEditGUI::confirmDelete ( )

confirmDelete

Definition at line 152 of file class.ilDclFieldEditGUI.php.

References $DIC, and $lng.

152  : void
153  {
154  global $DIC;
155  $ilCtrl = $DIC['ilCtrl'];
156  $lng = $DIC['lng'];
157  $tpl = $DIC['tpl'];
158 
159  $conf = new ilConfirmationGUI();
160  $conf->setFormAction($ilCtrl->getFormAction($this));
161  $conf->setHeaderText($lng->txt('dcl_confirm_delete_field'));
162 
163  $conf->addItem('field_id', $this->field_obj->getId(), $this->field_obj->getTitle());
164 
165  $conf->setConfirm($lng->txt('delete'), 'delete');
166  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
167 
168  $tpl->setContent($conf->getHTML());
169  }
global $DIC
Definition: feed.php:28
$lng

◆ create()

ilDclFieldEditGUI::create ( )

create field add form

Definition at line 119 of file class.ilDclFieldEditGUI.php.

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

119  : void
120  {
121  $this->help->setSubScreenId('create');
122 
123  $this->initForm();
124  $this->main_tpl->setContent($this->form->getHTML());
125  }
form( $class_path, string $cmd, string $submit_caption="")
initForm(string $a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ delete()

ilDclFieldEditGUI::delete ( )

Definition at line 185 of file class.ilDclFieldEditGUI.php.

References $DIC.

185  : void
186  {
187  global $DIC;
188  $ilCtrl = $DIC['ilCtrl'];
189 
190  $this->table->deleteField((int) $this->field_obj->getId());
191  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
192  }
global $DIC
Definition: feed.php:28

◆ edit()

ilDclFieldEditGUI::edit ( )

create field edit form

Definition at line 130 of file class.ilDclFieldEditGUI.php.

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

130  : void
131  {
132  $this->help->setSubScreenId('edit');
133 
134  $this->initForm("edit");
135  $this->field_obj->fillPropertiesForm($this->form);
136  $this->main_tpl->setContent($this->form->getHTML());
137  }
form( $class_path, string $cmd, string $submit_caption="")
initForm(string $a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ executeCommand()

ilDclFieldEditGUI::executeCommand ( )

execute command

Definition at line 93 of file class.ilDclFieldEditGUI.php.

References $DIC, checkAccess(), permissionDenied(), and save().

93  : void
94  {
95  global $DIC;
96  $ilCtrl = $DIC['ilCtrl'];
97  $ilCtrl->saveParameter($this, 'field_id');
98 
99  $cmd = $ilCtrl->getCmd();
100 
101  if (!$this->checkAccess()) {
102  $this->permissionDenied();
103  return;
104  }
105 
106  switch ($cmd) {
107  case "update":
108  $this->save("update");
109  break;
110  default:
111  $this->$cmd();
112  break;
113  }
114  }
save(string $a_mode="create")
save Field
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

◆ getDataCollectionObject()

ilDclFieldEditGUI::getDataCollectionObject ( )
Returns
ilObjDataCollection

Definition at line 395 of file class.ilDclFieldEditGUI.php.

Referenced by checkAccess(), and initForm().

396  {
397  return $this->parent_obj->getDataCollectionObject();
398  }
+ Here is the caller graph for this function:

◆ initForm()

ilDclFieldEditGUI::initForm ( string  $a_mode = "create")

initEditCustomForm

Parameters
string$a_modevalues: create | edit

Definition at line 208 of file class.ilDclFieldEditGUI.php.

References $DIC, $lng, ilDclBaseFieldModel\_getTitleInvalidChars(), ILIAS\Repository\form(), ilDclDatatype\getAllDatatype(), getDataCollectionObject(), ilDclFieldFactory\getFieldModelInstanceByClass(), and ilDclFieldFactory\getFieldRepresentationInstance().

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

208  : void
209  {
210  global $DIC;
211  $ilCtrl = $DIC['ilCtrl'];
212  $lng = $DIC['lng'];
213 
214  $this->form = new ilPropertyFormGUI();
215 
216  if ($a_mode == "edit") {
217  $this->form->setTitle($lng->txt('dcl_edit_field'));
218  $hidden_prop = new ilHiddenInputGUI("field_id");
219  $this->form->addItem($hidden_prop);
220 
221  $this->form->setFormAction($ilCtrl->getFormAction($this));
222 
223  $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
224  } else {
225  $this->form->setTitle($lng->txt('dcl_new_field'));
226  $hidden_prop = new ilHiddenInputGUI("table_id");
227  $hidden_prop->setValue((string) $this->field_obj->getTableId());
228  $this->form->addItem($hidden_prop);
229 
230  $this->form->setFormAction($ilCtrl->getFormAction($this));
231 
232  $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
233  }
234  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
235 
236  $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
237  $text_prop->setRequired(true);
238  $text_prop->setInfo(sprintf(
239  $lng->txt('fieldtitle_allow_chars'),
241  ));
242  $text_prop->setValidationRegexp(ilDclBaseFieldModel::_getTitleInvalidChars());
243  $this->form->addItem($text_prop);
244 
245  // Description
246  $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
247  $this->form->addItem($text_prop);
248 
249  $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
250 
251  if ($a_mode === 'edit') {
252  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($this->field_obj);
253  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject(), $a_mode);
254  $edit_datatype->setDisabled(true);
255  } else {
256  foreach (ilDclDatatype::getAllDatatype() as $datatype) {
257  $model = new ilDclBaseFieldModel();
258  $model->setDatatypeId($datatype->getId());
260  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($model);
261  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject());
262  }
263  }
264  $edit_datatype->setRequired(true);
265  $this->form->addItem($edit_datatype);
266 
267  //Unique
268  $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
269  $cb->setInfo($lng->txt('dcl_unique_desc'));
270  $this->form->addItem($cb);
271  }
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property in a property form.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, ?int $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
$lng
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
form( $class_path, string $cmd, string $submit_caption="")
This class represents a text area property in a property form.
static _getTitleInvalidChars(bool $a_as_regex=true)
All valid chars for filed titles.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ permissionDenied()

ilDclFieldEditGUI::permissionDenied ( )

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

References $DIC.

Referenced by executeCommand().

142  : void
143  {
144  global $DIC;
145  $tpl = $DIC['tpl'];
146  $tpl->setContent("Permission denied");
147  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ save()

ilDclFieldEditGUI::save ( string  $a_mode = "create")

save Field

Parameters
string$a_modevalues: create | update

Definition at line 277 of file class.ilDclFieldEditGUI.php.

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

Referenced by executeCommand().

277  : void
278  {
279  global $DIC;
280  $ilCtrl = $DIC['ilCtrl'];
281  $lng = $DIC['lng'];
282  $tpl = $DIC['tpl'];
283 
284  $this->initForm($a_mode == "update" ? "edit" : "create");
285 
286  if ($this->checkInput($a_mode)) {
287 
288  // check if confirmation is needed and if so, fetch and render confirmationGUI
289  if (($a_mode == "update") && !($this->form->getInput('confirmed')) && $this->field_obj->isConfirmationRequired($this->form)) {
290  $ilConfirmationGUI = $this->field_obj->getConfirmationGUI($this->form);
291  $tpl->setContent($ilConfirmationGUI->getHTML());
292 
293  return;
294  }
295 
296  $title = $this->form->getInput("title");
297  if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
298  $this->main_tpl->setOnScreenMessage('info', $lng->txt("dcl_field_title_change_warning"), true);
299  }
300 
301  $this->field_obj->setTitle($title);
302  $this->field_obj->setDescription($this->form->getInput("description"));
303  $this->field_obj->setDatatypeId((int) $this->form->getInput("datatype"));
304  $this->field_obj->setUnique((bool) $this->form->getInput("unique"));
305 
306  if ($a_mode == "update") {
307  $this->field_obj->doUpdate();
308  } else {
309  $this->field_obj->setOrder($this->table->getNewFieldOrder());
310  $this->field_obj->doCreate();
311  }
312 
313  // Get possible properties and save them
314  $this->field_obj->storePropertiesFromForm($this->form);
315 
316  $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
317 
318  if ($a_mode == "update") {
319  $this->main_tpl->setOnScreenMessage('success', $lng->txt("dcl_msg_field_modified"), true);
320  } else {
321  $this->table->addField($this->field_obj);
322  $this->table->buildOrderFields();
323  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_field_created"));
324  }
325  $ilCtrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields");
326  } else {
327  $this->form->setValuesByPost();
328  $tpl->setContent($this->form->getHTML());
329  }
330  }
checkInput(string $a_mode)
Check input of form.
global $DIC
Definition: feed.php:28
$lng
form( $class_path, string $cmd, string $submit_caption="")
initForm(string $a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $field_id

int ilDclFieldEditGUI::$field_id
protected

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

◆ $field_obj

ilDclBaseFieldModel ilDclFieldEditGUI::$field_obj
protected

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

◆ $form

ilPropertyFormGUI ilDclFieldEditGUI::$form
protected

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

◆ $help

ilHelpGUI ilDclFieldEditGUI::$help
protected

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

◆ $http

ILIAS HTTP Services ilDclFieldEditGUI::$http
protected

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

◆ $main_tpl

ilGlobalTemplateInterface ilDclFieldEditGUI::$main_tpl
private

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

◆ $obj_id

int ilDclFieldEditGUI::$obj_id
protected

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

◆ $parent_obj

ilDclTableListGUI ilDclFieldEditGUI::$parent_obj
protected

Definition at line 26 of file class.ilDclFieldEditGUI.php.

◆ $refinery

ILIAS Refinery Factory ilDclFieldEditGUI::$refinery
protected

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

◆ $table

ilDclTable ilDclFieldEditGUI::$table
protected

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

◆ $table_id

int ilDclFieldEditGUI::$table_id
protected

Definition at line 24 of file class.ilDclFieldEditGUI.php.


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