ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDclFieldEditGUI Class Reference

Class ilDclFieldEditGUI. More...

+ 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 ($a_mode="create")
 initEditCustomForm More...
 
 save ($a_mode="create")
 save Field More...
 
 getDataCollectionObject ()
 

Protected Member Functions

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

Protected Attributes

 $obj_id
 
 $table_id
 
 $parent_obj
 
 $table
 
 $form
 
 $field_obj
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDclFieldEditGUI::__construct ( ilDclTableListGUI  $a_parent_obj)

Constructor.

Parameters
ilDclTableListGUI$a_parent_obj
int$table_idWe need a table_id if no field_id is set (creation mode). We ignore the table_id by edit mode
int$field_idThe field_id of a existing fiel (edit mode)

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

References $_GET, $_POST, $DIC, $ilCtrl, ilDclDatatype\getAllDatatype(), ilDclCache\getFieldCache(), ilDclFieldFactory\getFieldModelInstance(), and ilDclCache\getTableCache().

54  {
55  global $DIC;
56  $ilCtrl = $DIC['ilCtrl'];
57 
58  $this->obj_id = $a_parent_obj->obj_id;
59  $this->parent_obj = $a_parent_obj;
60 
61  $this->table_id = $_GET["table_id"];
62  $this->field_id = $_GET['field_id'];
63 
64  if ($this->field_id) {
65  $this->field_obj = ilDclCache::getFieldCache($this->field_id);
66  } else {
67  $datatype = null;
68  if (isset($_POST['datatype']) && in_array($_POST['datatype'], array_keys(ilDclDatatype::getAllDatatype()))) {
69  $datatype = $_POST['datatype'];
70  }
71  $this->field_obj = ilDclFieldFactory::getFieldModelInstance($this->field_id, $datatype);
72  if (!$this->table_id) {
73  $ilCtrl->redirectByClass("ilDclTableListGUI", "listFields");
74  }
75  $this->field_obj->setTableId($this->table_id);
76  $ilCtrl->saveParameter($this, "table_id");
77  }
78 
79  $this->table = ilDclCache::getTableCache($this->table_id);
80  }
static getAllDatatype()
Get all possible Datatypes.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static getFieldCache($field_id=0)
static getTableCache($table_id=0)
global $ilCtrl
Definition: ilias.php:18
static getFieldModelInstance($field_id, $datatype=null)
Get FieldModel from field-id and datatype.
$_POST["username"]
+ Here is the call graph for this function:

Member Function Documentation

◆ cancel()

ilDclFieldEditGUI::cancel ( )

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

References $DIC, and $ilCtrl.

206  {
207  global $DIC;
208  $ilCtrl = $DIC['ilCtrl'];
209  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
210  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18

◆ cancelDelete()

ilDclFieldEditGUI::cancelDelete ( )

cancelDelete

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

References $DIC, and $ilCtrl.

181  {
182  global $DIC;
183  $ilCtrl = $DIC['ilCtrl'];
184 
185  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
186  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18

◆ checkAccess()

ilDclFieldEditGUI::checkAccess ( )
protected
Returns
bool

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

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

Referenced by executeCommand().

399  {
400  if ($field_id = $this->field_obj->getId()) {
401  return ilObjDataCollectionAccess::hasAccessToField($this->getDataCollectionObject()->ref_id, $this->table_id, $field_id);
402  } else {
403  return ilObjDataCollectionAccess::hasAccessToFields($this->getDataCollectionObject()->ref_id, $this->table_id);
404  }
405  }
static hasAccessToFields($ref_id, $table_id)
static hasAccessToField($ref_id, $table_id, $field_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkInput()

ilDclFieldEditGUI::checkInput (   $a_mode)
protected

Check input of form.

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

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

References $DIC, $lng, $title, ilDclTable\_hasFieldByTitle(), ilDclFieldFactory\getFieldModelInstanceByClass(), and ilUtil\sendFailure().

Referenced by save().

359  {
360  global $DIC;
361  $lng = $DIC['lng'];
362  $return = $this->form->checkInput();
363 
364  // load specific model for input checking
365  $datatype_id = $this->form->getInput('datatype');
366  if ($datatype_id != null && is_numeric($datatype_id)) {
367  $base_model = new ilDclBaseFieldModel();
368  $base_model->setDatatypeId($datatype_id);
369  $field_validation_class = ilDclFieldFactory::getFieldModelInstanceByClass($base_model);
370 
371  if (!$field_validation_class->checkFieldCreationInput($this->form)) {
372  $return = false;
373  }
374  }
375 
376  // Don't allow multiple fields with the same title in this table
377  if ($a_mode == 'create') {
378  if ($title = $this->form->getInput('title')) {
379  if (ilDclTable::_hasFieldByTitle($title, $this->table_id)) {
380  $inputObj = $this->form->getItemByPostVar('title');
381  $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
382  $return = false;
383  }
384  }
385  }
386 
387  if (!$return) {
388  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
389  }
390 
391  return $return;
392  }
Class ilDclBaseFieldModel.
global $DIC
Definition: saml.php:7
static _hasFieldByTitle($title, $obj_id)
Checks if a table has a field with the given title.
$lng
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmDelete()

ilDclFieldEditGUI::confirmDelete ( )

confirmDelete

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

References $DIC, $ilCtrl, $lng, and $tpl.

157  {
158  global $DIC;
159  $ilCtrl = $DIC['ilCtrl'];
160  $lng = $DIC['lng'];
161  $tpl = $DIC['tpl'];
162 
163  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
164  $conf = new ilConfirmationGUI();
165  $conf->setFormAction($ilCtrl->getFormAction($this));
166  $conf->setHeaderText($lng->txt('dcl_confirm_delete_field'));
167 
168  $conf->addItem('field_id', (int) $this->field_obj->getId(), $this->field_obj->getTitle());
169 
170  $conf->setConfirm($lng->txt('delete'), 'delete');
171  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
172 
173  $tpl->setContent($conf->getHTML());
174  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
global $ilCtrl
Definition: ilias.php:18
$lng
Confirmation screen class.

◆ create()

ilDclFieldEditGUI::create ( )

create field add form

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

References $DIC, $tpl, and initForm().

117  {
118  global $DIC;
119  $tpl = $DIC['tpl'];
120 
121  $this->initForm();
122  $tpl->setContent($this->form->getHTML());
123  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
initForm($a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ delete()

ilDclFieldEditGUI::delete ( )

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

References $DIC, and $ilCtrl.

193  {
194  global $DIC;
195  $ilCtrl = $DIC['ilCtrl'];
196 
197  $this->table->deleteField($this->field_obj->getId());
198  $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
199  }
global $DIC
Definition: saml.php:7
global $ilCtrl
Definition: ilias.php:18

◆ edit()

ilDclFieldEditGUI::edit ( )

create field edit form

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

References $DIC, $tpl, and initForm().

130  {
131  global $DIC;
132  $tpl = $DIC['tpl'];
133 
134  $this->initForm("edit");
135 
136  $this->field_obj->fillPropertiesForm($this->form);
137 
138  $tpl->setContent($this->form->getHTML());
139  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
initForm($a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ executeCommand()

ilDclFieldEditGUI::executeCommand ( )

execute command

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

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

87  {
88  global $DIC;
89  $ilCtrl = $DIC['ilCtrl'];
90  $ilCtrl->saveParameter($this, 'field_id');
91 
92  $cmd = $ilCtrl->getCmd();
93 
94  if (!$this->checkAccess()) {
95  $this->permissionDenied();
96 
97  return;
98  }
99 
100  switch ($cmd) {
101  case "update":
102  $this->save("update");
103  break;
104  default:
105  $this->$cmd();
106  break;
107  }
108 
109  return true;
110  }
global $DIC
Definition: saml.php:7
save($a_mode="create")
save Field
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

◆ getDataCollectionObject()

ilDclFieldEditGUI::getDataCollectionObject ( )
Returns
ilObjDataCollection

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

Referenced by checkAccess(), and initForm().

411  {
412  return $this->parent_obj->getDataCollectionObject();
413  }
+ Here is the caller graph for this function:

◆ initForm()

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

initEditCustomForm

Parameters
string$a_modevalues: create | edit

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

References $DIC, $field_obj, $ilCtrl, $lng, ilDclBaseFieldModel\_getTitleInvalidChars(), ilDclDatatype\getAllDatatype(), getDataCollectionObject(), ilDclFieldFactory\getFieldRepresentationInstance(), ilFormPropertyGUI\setInfo(), and ilFormPropertyGUI\setRequired().

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

219  {
220  global $DIC;
221  $ilCtrl = $DIC['ilCtrl'];
222  $lng = $DIC['lng'];
223 
224  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
225  $this->form = new ilPropertyFormGUI();
226 
227  if ($a_mode == "edit") {
228  $this->form->setTitle($lng->txt('dcl_edit_field'));
229  $hidden_prop = new ilHiddenInputGUI("field_id");
230  $this->form->addItem($hidden_prop);
231 
232  $this->form->setFormAction($ilCtrl->getFormAction($this), "update");
233 
234  $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
235  } else {
236  $this->form->setTitle($lng->txt('dcl_new_field'));
237  $hidden_prop = new ilHiddenInputGUI("table_id");
238  $hidden_prop->setValue($this->field_obj->getTableId());
239  $this->form->addItem($hidden_prop);
240 
241  $this->form->setFormAction($ilCtrl->getFormAction($this), "save");
242 
243  $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
244  }
245  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
246 
247  $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
248  $text_prop->setRequired(true);
249  $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDclBaseFieldModel::_getTitleInvalidChars(false)));
250  $text_prop->setValidationRegexp(ilDclBaseFieldModel::_getTitleInvalidChars(true));
251  $this->form->addItem($text_prop);
252 
253  // Description
254  $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
255  $this->form->addItem($text_prop);
256 
257  $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
258 
259  foreach (ilDclDatatype::getAllDatatype() as $datatype) {
260  $model = new ilDclBaseFieldModel();
261  $model->setDatatypeId($datatype->getId());
262 
263  if ($a_mode == 'edit' && $datatype->getId() == $this->field_obj->getDatatypeId()) {
264  $model = $this->field_obj;
265  }
266 
267  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($model);
268  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject(), $a_mode);
269  }
270  $edit_datatype->setRequired(true);
271 
272  //you can't change type but we still need it in POST
273  if ($a_mode == "edit") {
274  $edit_datatype->setDisabled(true);
275  }
276  $this->form->addItem($edit_datatype);
277 
278  // Required
279  $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
280  $this->form->addItem($cb);
281 
282  //Unique
283  $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
284  $cb->setInfo($lng->txt('dcl_unique_desc'));
285  $this->form->addItem($cb);
286  }
Class ilDclBaseFieldModel.
static _getTitleInvalidChars($a_as_regex=true)
All valid chars for filed titles.
This class represents a property form user interface.
static getAllDatatype()
Get all possible Datatypes.
global $DIC
Definition: saml.php:7
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
Returns FieldRepresentation from BaseFieldModel.
This class represents a checkbox property in a property form.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
This class represents a hidden form property in a property form.
This class represents a property in a property form.
$lng
This class represents a text property in a property form.
This class represents a text area property in a property form.
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ permissionDenied()

ilDclFieldEditGUI::permissionDenied ( )

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

References $DIC, and $tpl.

Referenced by executeCommand().

146  {
147  global $DIC;
148  $tpl = $DIC['tpl'];
149  $tpl->setContent("Permission denied");
150  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
+ Here is the caller graph for this function:

◆ save()

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

save Field

Parameters
string$a_modevalues: create | update

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

References $DIC, $ilCtrl, $lng, $title, $tpl, checkInput(), initForm(), and ilUtil\sendInfo().

Referenced by executeCommand().

295  {
296  global $DIC;
297  $ilCtrl = $DIC['ilCtrl'];
298  $lng = $DIC['lng'];
299  $tpl = $DIC['tpl'];
300 
301  $this->initForm($a_mode == "update" ? "edit" : "create");
302 
303  if ($this->checkInput($a_mode)) {
304 
305  // check if confirmation is needed and if so, fetch and render confirmationGUI
306  if (($a_mode == "update") && !($this->form->getInput('confirmed')) && $this->field_obj->isConfirmationRequired($this->form)) {
307  $ilConfirmationGUI = $this->field_obj->getConfirmationGUI($this->form);
308  $tpl->setContent($ilConfirmationGUI->getHTML());
309 
310  return;
311  }
312 
313  $title = $this->form->getInput("title");
314  if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
315  ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
316  }
317 
318  $this->field_obj->setTitle($title);
319  $this->field_obj->setDescription($this->form->getInput("description"));
320  $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
321  $this->field_obj->setRequired($this->form->getInput("required"));
322  $this->field_obj->setUnique($this->form->getInput("unique"));
323 
324  if ($a_mode == "update") {
325  $this->field_obj->doUpdate();
326  } else {
327  $this->field_obj->setOrder($this->table->getNewFieldOrder());
328  $this->field_obj->doCreate();
329  }
330 
331  // Get possible properties and save them
332  $this->field_obj->storePropertiesFromForm($this->form);
333 
334  $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
335 
336  if ($a_mode == "update") {
337  ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"), true);
338  } else {
339  $this->table->addField($this->field_obj);
340  $this->table->buildOrderFields();
341  ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
342  }
343  $ilCtrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields");
344  } else {
345  $this->form->setValuesByPost();
346  $tpl->setContent($this->form->getHTML());
347  }
348  }
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
global $ilCtrl
Definition: ilias.php:18
initForm($a_mode="create")
initEditCustomForm
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$lng
checkInput($a_mode)
Check input of form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $field_obj

ilDclFieldEditGUI::$field_obj
protected

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

Referenced by initForm().

◆ $form

ilDclFieldEditGUI::$form
protected

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

◆ $obj_id

ilDclFieldEditGUI::$obj_id
protected

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

◆ $parent_obj

ilDclFieldEditGUI::$parent_obj
protected

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

◆ $table

ilDclFieldEditGUI::$table
protected

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

◆ $table_id

ilDclFieldEditGUI::$table_id
protected

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


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