ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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...
 
 getValues ()
 getFieldValues 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 62 of file class.ilDclFieldEditGUI.php.

62 {
63 global $DIC;
64 $ilCtrl = $DIC['ilCtrl'];
65
66 $this->obj_id = $a_parent_obj->obj_id;
67 $this->parent_obj = $a_parent_obj;
68
69 $this->table_id = $_GET["table_id"];
70 $this->field_id = $_GET['field_id'];
71
72 if ($this->field_id) {
73 $this->field_obj = ilDclCache::getFieldCache($this->field_id);
74 } else {
75 $datatype = null;
76 if(isset($_POST['datatype']) && in_array($_POST['datatype'], array_keys(ilDclDatatype::getAllDatatype()))) {
77 $datatype = $_POST['datatype'];
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 }
$_GET["client_id"]
$_POST["username"]
static getTableCache($table_id=0)
static getFieldCache($field_id=0)
static getAllDatatype()
Get all possible Datatypes.
static getFieldModelInstance($field_id, $datatype=null)
Get FieldModel from field-id and datatype.
global $ilCtrl
Definition: ilias.php:18
global $DIC

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

+ Here is the call graph for this function:

Member Function Documentation

◆ cancel()

ilDclFieldEditGUI::cancel ( )

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

205 {
206 global $DIC;
207 $ilCtrl = $DIC['ilCtrl'];
208 $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
209 }

References $DIC, and $ilCtrl.

◆ cancelDelete()

ilDclFieldEditGUI::cancelDelete ( )

cancelDelete

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

182 {
183 global $DIC;
184 $ilCtrl = $DIC['ilCtrl'];
185
186 $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields");
187 }

References $DIC, and $ilCtrl.

◆ checkAccess()

ilDclFieldEditGUI::checkAccess ( )
protected
Returns
bool

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

420 {
421 if ($field_id = $this->field_obj->getId()) {
422 return ilObjDataCollectionAccess::hasAccessToField($this->getDataCollectionObject()->ref_id, $this->table_id, $field_id);
423 } else {
424 return ilObjDataCollectionAccess::hasAccessToFields($this->getDataCollectionObject()->ref_id, $this->table_id);
425 }
426 }
static hasAccessToFields($ref_id, $table_id)
static hasAccessToField($ref_id, $table_id, $field_id)

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

Referenced by executeCommand().

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

381 {
382 global $DIC;
383 $lng = $DIC['lng'];
384 $return = $this->form->checkInput();
385
386 // load specific model for input checking
387 $datatype_id = $this->form->getInput('datatype');
388 if($datatype_id != null && is_numeric($datatype_id)) {
389 $base_model = new ilDclBaseFieldModel();
390 $base_model->setDatatypeId($datatype_id);
391 $field_validation_class = ilDclFieldFactory::getFieldModelInstanceByClass($base_model);
392
393 if(!$field_validation_class->checkFieldCreationInput($this->form)) {
394 $return = false;
395 }
396 }
397
398 // Don't allow multiple fields with the same title in this table
399 if ($a_mode == 'create') {
400 if ($title = $this->form->getInput('title')) {
401 if (ilDclTable::_hasFieldByTitle($title, $this->table_id)) {
402 $inputObj = $this->form->getItemByPostVar('title');
403 $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
404 $return = false;
405 }
406 }
407 }
408
409 if (!$return) {
410 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
411 }
412
413 return $return;
414 }
Class ilDclBaseFieldModel.
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...
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.
global $lng
Definition: privfeed.php:17

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

Referenced by save().

+ 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.

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

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

◆ create()

ilDclFieldEditGUI::create ( )

create field add form

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

123 {
124 global $DIC;
125 $tpl = $DIC['tpl'];
126
127 $this->initForm();
128 $tpl->setContent($this->form->getHTML());
129 }
initForm($a_mode="create")
initEditCustomForm

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

+ Here is the call graph for this function:

◆ delete()

ilDclFieldEditGUI::delete ( )

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

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

References $DIC, and $ilCtrl.

◆ edit()

ilDclFieldEditGUI::edit ( )

create field edit form

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

135 {
136 global $DIC;
137 $tpl = $DIC['tpl'];
138
139 $this->initForm("edit");
140 $this->getValues();
141
142 $tpl->setContent($this->form->getHTML());
143 }

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

+ Here is the call graph for this function:

◆ executeCommand()

ilDclFieldEditGUI::executeCommand ( )

execute command

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

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
104 return;
105 }
106
107 switch ($cmd) {
108 case "update":
109 $this->save("update");
110 break;
111 default:
112 $this->$cmd();
113 break;
114 }
115
116 return true;
117 }
save($a_mode="create")
save Field
$cmd
Definition: sahs_server.php:35

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

+ Here is the call graph for this function:

◆ getDataCollectionObject()

ilDclFieldEditGUI::getDataCollectionObject ( )
Returns
ilObjDataCollection

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

431 {
432 return $this->parent_obj->getDataCollectionObject();
433 }

Referenced by checkAccess(), and initForm().

+ Here is the caller graph for this function:

◆ getValues()

ilDclFieldEditGUI::getValues ( )

getFieldValues

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

290 {
291 //Std-Values
292 $values = array(
293 'table_id' => $this->field_obj->getTableId(),
294 'field_id' => $this->field_obj->getId(),
295 'title' => $this->field_obj->getTitle(),
296 'datatype' => $this->field_obj->getDatatypeId(),
297 'description' => $this->field_obj->getDescription(),
298 'required' => $this->field_obj->getRequired(),
299 'unique' => $this->field_obj->isUnique(),
300 );
301
302 $properties = $this->field_obj->getValidFieldProperties();
303 foreach ($properties as $prop) {
304 $values['prop_' . $prop] = $this->field_obj->getProperty($prop);
305 }
306
307 $this->form->setValuesByArray($values);
308
309 return true;
310 }

Referenced by edit().

+ Here is the caller graph for this function:

◆ initForm()

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

initEditCustomForm

Parameters
string$a_modevalues: create | edit

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

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

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ permissionDenied()

ilDclFieldEditGUI::permissionDenied ( )

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

149 {
150 global $DIC;
151 $tpl = $DIC['tpl'];
152 $tpl->setContent("Permission denied");
153 }

References $DIC, and $tpl.

Referenced by executeCommand().

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

318 {
319 global $DIC;
320 $ilCtrl = $DIC['ilCtrl'];
321 $lng = $DIC['lng'];
322 $tpl = $DIC['tpl'];
323
324 $this->initForm($a_mode == "update" ? "edit" : "create");
325
326 if ($this->checkInput($a_mode)) {
327 $title = $this->form->getInput("title");
328 if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
329 ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
330 }
331
332 $this->field_obj->setTitle($title);
333 $this->field_obj->setDescription($this->form->getInput("description"));
334 $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
335 $this->field_obj->setRequired($this->form->getInput("required"));
336 $this->field_obj->setUnique($this->form->getInput("unique"));
337
338 if ($a_mode == "update") {
339 $this->field_obj->doUpdate();
340 } else {
341 $this->field_obj->setOrder($this->table->getNewFieldOrder());
342 $this->field_obj->doCreate();
343 }
344
345 // Get possible properties and save them
346 $field_props = $this->field_obj->getValidFieldProperties();
347 foreach ($field_props as $property) {
348 $representation = ilDclFieldFactory::getFieldRepresentationInstance($this->field_obj);
349 $value = $this->form->getInput($representation->getPropertyInputFieldId($property));
350
351 // save non empty values and set them to null, when they already exist. Do not override plugin-hook when already set.
352 if(!empty($value) || ($this->field_obj->getPropertyInstance($property) != NULL && $property != ilDclBaseFieldModel::PROP_PLUGIN_HOOK_NAME)) {
353 $this->field_obj->setProperty($property, $value)->store();
354 }
355 }
356
357 $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
358
359 if ($a_mode == "update") {
360 ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"), true);
361 } else {
362 $this->table->addField($this->field_obj);
363 $this->table->buildOrderFields();
364 ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
365 }
366 $ilCtrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields");
367 } else {
368 $this->form->setValuesByPost();
369 $tpl->setContent($this->form->getHTML());
370 }
371 }
checkInput($a_mode)
Check input of form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.

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

Referenced by executeCommand().

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

Referenced by initForm().

◆ $form

ilDclFieldEditGUI::$form
protected

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

◆ $obj_id

ilDclFieldEditGUI::$obj_id
protected

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

◆ $parent_obj

ilDclFieldEditGUI::$parent_obj
protected

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

◆ $table

ilDclFieldEditGUI::$table
protected

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

◆ $table_id

ilDclFieldEditGUI::$table_id
protected

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


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