ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 56 of file class.ilDclFieldEditGUI.php.

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

57  {
58  global $DIC;
59  $ilCtrl = $DIC['ilCtrl'];
60 
61  $this->obj_id = $a_parent_obj->obj_id;
62  $this->parent_obj = $a_parent_obj;
63 
64  $this->table_id = $_GET["table_id"];
65  $this->field_id = $_GET['field_id'];
66 
67  if ($this->field_id) {
68  $this->field_obj = ilDclCache::getFieldCache($this->field_id);
69  } else {
70  $datatype = null;
71  if (isset($_POST['datatype']) && in_array($_POST['datatype'], array_keys(ilDclDatatype::getAllDatatype()))) {
72  $datatype = $_POST['datatype'];
73  }
74  $this->field_obj = ilDclFieldFactory::getFieldModelInstance($this->field_id, $datatype);
75  if (!$this->table_id) {
76  $ilCtrl->redirectByClass("ilDclTableListGUI", "listFields");
77  }
78  $this->field_obj->setTableId($this->table_id);
79  $ilCtrl->saveParameter($this, "table_id");
80  }
81 
82  $this->table = ilDclCache::getTableCache($this->table_id);
83  }
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 208 of file class.ilDclFieldEditGUI.php.

References $DIC, and $ilCtrl.

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

◆ cancelDelete()

ilDclFieldEditGUI::cancelDelete ( )

cancelDelete

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

References $DIC, and $ilCtrl.

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

◆ checkAccess()

ilDclFieldEditGUI::checkAccess ( )
protected
Returns
bool

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

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

Referenced by executeCommand().

402  {
403  if ($field_id = $this->field_obj->getId()) {
404  return ilObjDataCollectionAccess::hasAccessToField($this->getDataCollectionObject()->ref_id, $this->table_id, $field_id);
405  } else {
406  return ilObjDataCollectionAccess::hasAccessToFields($this->getDataCollectionObject()->ref_id, $this->table_id);
407  }
408  }
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 361 of file class.ilDclFieldEditGUI.php.

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

Referenced by save().

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

◆ confirmDelete()

ilDclFieldEditGUI::confirmDelete ( )

confirmDelete

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

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

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

◆ create()

ilDclFieldEditGUI::create ( )

create field add form

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

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

120  {
121  global $DIC;
122  $tpl = $DIC['tpl'];
123 
124  $this->initForm();
125  $tpl->setContent($this->form->getHTML());
126  }
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 195 of file class.ilDclFieldEditGUI.php.

References $DIC, and $ilCtrl.

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

◆ edit()

ilDclFieldEditGUI::edit ( )

create field edit form

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

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

133  {
134  global $DIC;
135  $tpl = $DIC['tpl'];
136 
137  $this->initForm("edit");
138 
139  $this->field_obj->fillPropertiesForm($this->form);
140 
141  $tpl->setContent($this->form->getHTML());
142  }
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 89 of file class.ilDclFieldEditGUI.php.

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

90  {
91  global $DIC;
92  $ilCtrl = $DIC['ilCtrl'];
93  $ilCtrl->saveParameter($this, 'field_id');
94 
95  $cmd = $ilCtrl->getCmd();
96 
97  if (!$this->checkAccess()) {
98  $this->permissionDenied();
99 
100  return;
101  }
102 
103  switch ($cmd) {
104  case "update":
105  $this->save("update");
106  break;
107  default:
108  $this->$cmd();
109  break;
110  }
111 
112  return true;
113  }
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 413 of file class.ilDclFieldEditGUI.php.

Referenced by checkAccess(), and initForm().

414  {
415  return $this->parent_obj->getDataCollectionObject();
416  }
+ Here is the caller graph for this function:

◆ initForm()

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

initEditCustomForm

Parameters
string$a_modevalues: create | edit

Definition at line 221 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().

222  {
223  global $DIC;
224  $ilCtrl = $DIC['ilCtrl'];
225  $lng = $DIC['lng'];
226 
227  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
228  $this->form = new ilPropertyFormGUI();
229 
230  if ($a_mode == "edit") {
231  $this->form->setTitle($lng->txt('dcl_edit_field'));
232  $hidden_prop = new ilHiddenInputGUI("field_id");
233  $this->form->addItem($hidden_prop);
234 
235  $this->form->setFormAction($ilCtrl->getFormAction($this), "update");
236 
237  $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
238  } else {
239  $this->form->setTitle($lng->txt('dcl_new_field'));
240  $hidden_prop = new ilHiddenInputGUI("table_id");
241  $hidden_prop->setValue($this->field_obj->getTableId());
242  $this->form->addItem($hidden_prop);
243 
244  $this->form->setFormAction($ilCtrl->getFormAction($this), "save");
245 
246  $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
247  }
248  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
249 
250  $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
251  $text_prop->setRequired(true);
252  $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDclBaseFieldModel::_getTitleInvalidChars(false)));
253  $text_prop->setValidationRegexp(ilDclBaseFieldModel::_getTitleInvalidChars(true));
254  $this->form->addItem($text_prop);
255 
256  // Description
257  $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
258  $this->form->addItem($text_prop);
259 
260  $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
261 
262  foreach (ilDclDatatype::getAllDatatype() as $datatype) {
263  $model = new ilDclBaseFieldModel();
264  $model->setDatatypeId($datatype->getId());
265 
266  if ($a_mode == 'edit' && $datatype->getId() == $this->field_obj->getDatatypeId()) {
267  $model = $this->field_obj;
268  }
269 
270  $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($model);
271  $field_representation->addFieldCreationForm($edit_datatype, $this->getDataCollectionObject(), $a_mode);
272  }
273  $edit_datatype->setRequired(true);
274 
275  //you can't change type but we still need it in POST
276  if ($a_mode == "edit") {
277  $edit_datatype->setDisabled(true);
278  }
279  $this->form->addItem($edit_datatype);
280 
281  // Required
282  $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
283  $this->form->addItem($cb);
284 
285  //Unique
286  $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
287  $cb->setInfo($lng->txt('dcl_unique_desc'));
288  $this->form->addItem($cb);
289  }
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.
This class represents a text property in a property form.
global $lng
Definition: privfeed.php:17
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 148 of file class.ilDclFieldEditGUI.php.

References $DIC, and $tpl.

Referenced by executeCommand().

149  {
150  global $DIC;
151  $tpl = $DIC['tpl'];
152  $tpl->setContent("Permission denied");
153  }
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 297 of file class.ilDclFieldEditGUI.php.

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

Referenced by executeCommand().

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

Referenced by initForm().

◆ $form

ilDclFieldEditGUI::$form
protected

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

◆ $obj_id

ilDclFieldEditGUI::$obj_id
protected

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

◆ $parent_obj

ilDclFieldEditGUI::$parent_obj
protected

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

◆ $table

ilDclFieldEditGUI::$table
protected

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