ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 
 checkUniqueness ()
 

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
 
ilLanguage $lng
 

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 40 of file class.ilDclFieldEditGUI.php.

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

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

Member Function Documentation

◆ cancel()

ilDclFieldEditGUI::cancel ( )

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

References $DIC.

199  : void
200  {
201  global $DIC;
202  $ilCtrl = $DIC['ilCtrl'];
203  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
204  }
global $DIC
Definition: shib_login.php:22

◆ cancelDelete()

ilDclFieldEditGUI::cancelDelete ( )

cancelDelete

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

References $DIC.

176  : void
177  {
178  global $DIC;
179  $ilCtrl = $DIC['ilCtrl'];
180 
181  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
182  }
global $DIC
Definition: shib_login.php:22

◆ checkAccess()

ilDclFieldEditGUI::checkAccess ( )
protected
Returns
bool

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

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

Referenced by executeCommand().

385  : bool
386  {
387  if ($field_id = $this->field_obj->getId()) {
389  $this->getDataCollectionObject()->getRefId(),
390  $this->table_id,
391  (int) $field_id
392  );
393  } else {
395  $this->getDataCollectionObject()->getRefId(),
396  $this->table_id
397  );
398  }
399  }
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 340 of file class.ilDclFieldEditGUI.php.

References $DIC, ilDclTable\_hasFieldByTitle(), checkUniqueness(), ILIAS\Repository\form(), ilDclFieldFactory\getFieldModelInstanceByClass(), null, and ilLanguage\txt().

Referenced by save().

340  : bool
341  {
342  global $DIC;
343  $lng = $DIC['lng'];
344  $return = $this->form->checkInput();
345 
346  //mantis 30758, 36585, jour fixe decision:
347  //uniqueness shall be changeable for all types of fields
348  if ($a_mode === 'update' && !$this->checkUniqueness()) {
349  $return = false;
350  }
351 
352  // load specific model for input checking
353  $datatype_id = $this->form->getInput('datatype');
354  if ($datatype_id != null && is_numeric($datatype_id)) {
355  $base_model = new ilDclBaseFieldModel();
356  $base_model->setDatatypeId((int) $datatype_id);
357  $field_validation_class = ilDclFieldFactory::getFieldModelInstanceByClass($base_model);
358 
359  if (!$field_validation_class->checkFieldCreationInput($this->form)) {
360  $return = false;
361  }
362  }
363 
364  // Don't allow multiple fields with the same title in this table
365  if ($a_mode == 'create') {
366  if ($title = $this->form->getInput('title')) {
367  if (ilDclTable::_hasFieldByTitle($title, $this->table_id)) {
368  $inputObj = $this->form->getItemByPostVar('title');
369  $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
370  $return = false;
371  }
372  }
373  }
374 
375  if (!$return) {
376  $this->main_tpl->setOnScreenMessage('failure', $lng->txt("form_input_not_valid"));
377  }
378 
379  return $return;
380  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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...
global $DIC
Definition: shib_login.php:22
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:

◆ checkUniqueness()

ilDclFieldEditGUI::checkUniqueness ( )
protected
Returns
bool

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

References Vendor\Package\$e, $txt, ILIAS\Repository\form(), ilDclDatatype\INPUTFORMAT_FORMULA, ilDclDatatype\INPUTFORMAT_RATING, and ILIAS\Repository\lng().

Referenced by checkInput().

404  : bool
405  {
406  $this->field_obj->setUnique((bool) $this->form->getInput("unique"));
407  if (!$this->field_obj->isUnique()) {
408  return true;
409  }
410 
411  $txt = $this->lng->txt("dcl_duplicate_non_unique_entries_exist");
412 
413  //check validity of all available records
414  foreach ($this->table->getRecords() as $record) {
415 
416  //except of formula field
417  if ((int) ($this->field_obj->getDatatypeId()) !== ilDclDatatype::INPUTFORMAT_FORMULA) {
418  //get field value
419  $value = $record->getRecordFieldValue($this->field_obj->getId());
420 
421  //special for rating field: only voting of the current user
422  if ((int) ($this->field_obj->getDatatypeId()) === ilDclDatatype::INPUTFORMAT_RATING) {
423  $value = $record->getRecordFieldValueForUser($this->field_obj->getId());
424  $txt = "";
425  }
426  //validity of field content
427  try {
428  $this->field_obj->checkValidity($value, $record->getId());
429  } catch (ilDclInputException $e) {
430  $item = $this->form->getItemByPostVar('unique');
431  $item->setAlert($txt);
432  return false;
433  }
434  }
435  }
436  return true;
437  }
$txt
Definition: error.php:31
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 154 of file class.ilDclFieldEditGUI.php.

References $DIC, and ilLanguage\txt().

154  : void
155  {
156  global $DIC;
157  $ilCtrl = $DIC['ilCtrl'];
158  $lng = $DIC['lng'];
159  $tpl = $DIC['tpl'];
160 
161  $conf = new ilConfirmationGUI();
162  $conf->setFormAction($ilCtrl->getFormAction($this));
163  $conf->setHeaderText($lng->txt('dcl_confirm_delete_field'));
164 
165  $conf->addItem('field_id', $this->field_obj->getId(), $this->field_obj->getTitle());
166 
167  $conf->setConfirm($lng->txt('delete'), 'delete');
168  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
169 
170  $tpl->setContent($conf->getHTML());
171  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

◆ create()

ilDclFieldEditGUI::create ( )

create field add form

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

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

121  : void
122  {
123  $this->help->setSubScreenId('create');
124 
125  $this->initForm();
126  $this->main_tpl->setContent($this->form->getHTML());
127  }
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 187 of file class.ilDclFieldEditGUI.php.

References $DIC.

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

◆ edit()

ilDclFieldEditGUI::edit ( )

create field edit form

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

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

132  : void
133  {
134  $this->help->setSubScreenId('edit');
135 
136  $this->initForm("edit");
137  $this->field_obj->fillPropertiesForm($this->form);
138  $this->main_tpl->setContent($this->form->getHTML());
139  }
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 95 of file class.ilDclFieldEditGUI.php.

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

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

◆ getDataCollectionObject()

ilDclFieldEditGUI::getDataCollectionObject ( )
Returns
ilObjDataCollection

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

Referenced by checkAccess(), and initForm().

443  {
444  return $this->parent_obj->getDataCollectionObject();
445  }
+ 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 210 of file class.ilDclFieldEditGUI.php.

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

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

210  : void
211  {
212  global $DIC;
213  $ilCtrl = $DIC['ilCtrl'];
214  $lng = $DIC['lng'];
215 
216  $this->form = new ilPropertyFormGUI();
217 
218  if ($a_mode == "edit") {
219  $this->form->setTitle($lng->txt('dcl_edit_field'));
220  $hidden_prop = new ilHiddenInputGUI("field_id");
221  $this->form->addItem($hidden_prop);
222 
223  $this->form->setFormAction($ilCtrl->getFormAction($this));
224 
225  $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
226  } else {
227  $this->form->setTitle($lng->txt('dcl_new_field'));
228  $hidden_prop = new ilHiddenInputGUI("table_id");
229  $hidden_prop->setValue((string) $this->field_obj->getTableId());
230  $this->form->addItem($hidden_prop);
231 
232  $this->form->setFormAction($ilCtrl->getFormAction($this));
233 
234  $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
235  }
236  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
237 
238  $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
239  $text_prop->setRequired(true);
240  $text_prop->setInfo(sprintf(
241  $lng->txt('fieldtitle_allow_chars'),
243  ));
244  $text_prop->setValidationRegexp(ilDclBaseFieldModel::_getTitleInvalidChars());
245  $this->form->addItem($text_prop);
246 
247  // Description
248  $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
249  $text_prop->setInfo($lng->txt('dcl_field_description_desc'));
250  $this->form->addItem($text_prop);
251 
252  $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
253 
254  if ($a_mode === 'edit') {
255  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($this->field_obj);
256  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject(), $a_mode);
257  $edit_datatype->setDisabled(true);
258  } else {
259  foreach (ilDclDatatype::getAllDatatype() as $datatype) {
260  $model = new ilDclBaseFieldModel();
261  $model->setDatatypeId($datatype->getId());
263  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($model);
264  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject());
265  }
266  }
267  $edit_datatype->setRequired(true);
268  $this->form->addItem($edit_datatype);
269 
270  //Unique
271  $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
272  $cb->setInfo($lng->txt('dcl_unique_desc'));
273  $this->form->addItem($cb);
274  }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
This class represents a hidden form property in a property form.
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...
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
global $DIC
Definition: shib_login.php:22
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 144 of file class.ilDclFieldEditGUI.php.

References $DIC.

Referenced by executeCommand().

144  : void
145  {
146  global $DIC;
147  $tpl = $DIC['tpl'];
148  $tpl->setContent("Permission denied");
149  }
global $DIC
Definition: shib_login.php:22
+ 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 280 of file class.ilDclFieldEditGUI.php.

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

Referenced by executeCommand().

280  : void
281  {
282  global $DIC;
283  $ilCtrl = $DIC['ilCtrl'];
284  $lng = $DIC['lng'];
285  $tpl = $DIC['tpl'];
286 
287  $this->initForm($a_mode == "update" ? "edit" : "create");
288 
289  if ($this->checkInput($a_mode)) {
290 
291  // check if confirmation is needed and if so, fetch and render confirmationGUI
292  if (($a_mode == "update") && !($this->form->getInput('confirmed')) && $this->field_obj->isConfirmationRequired($this->form)) {
293  $ilConfirmationGUI = $this->field_obj->getConfirmationGUI($this->form);
294  $tpl->setContent($ilConfirmationGUI->getHTML());
295 
296  return;
297  }
298 
299  $title = $this->form->getInput("title");
300  if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
301  $this->main_tpl->setOnScreenMessage('info', $lng->txt("dcl_field_title_change_warning"), true);
302  }
303 
304  $this->field_obj->setTitle($title);
305  $this->field_obj->setDescription($this->form->getInput("description"));
306  $this->field_obj->setDatatypeId((int) $this->form->getInput("datatype"));
307  $this->field_obj->setUnique((bool) $this->form->getInput("unique"));
308 
309  if ($a_mode == "update") {
310  $this->field_obj->doUpdate();
311  } else {
312  $this->field_obj->setOrder($this->table->getNewFieldOrder());
313  $this->field_obj->doCreate();
314  }
315 
316  // Get possible properties and save them
317  $this->field_obj->storePropertiesFromForm($this->form);
318 
319  $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
320 
321  if ($a_mode == "update") {
322  $this->main_tpl->setOnScreenMessage('success', $lng->txt("dcl_msg_field_modified"), true);
323  } else {
324  $this->table->addField($this->field_obj);
325  $this->table->buildOrderFields();
326  $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_field_created"));
327  }
328  $ilCtrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields");
329  } else {
330  $this->form->setValuesByPost();
331  $tpl->setContent($this->form->getHTML());
332  }
333  }
checkInput(string $a_mode)
Check input of form.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
global $DIC
Definition: shib_login.php:22
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 35 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 32 of file class.ilDclFieldEditGUI.php.

◆ $http

ILIAS HTTP Services ilDclFieldEditGUI::$http
protected

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

◆ $lng

ilLanguage ilDclFieldEditGUI::$lng
private

Definition at line 31 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 34 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: