ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilDataCollectionFieldEditGUI Class Reference

Class ilDataCollectionFieldEditGUI. More...

+ Collaboration diagram for ilDataCollectionFieldEditGUI:

Public Member Functions

 __construct (ilObjDataCollectionGUI $a_parent_obj, $table_id, $field_id)
 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...
 

Data Fields

const REFERENCE_SEPARATOR = " -> "
 

Protected Member Functions

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

Protected Attributes

 $obj_id
 
 $table_id
 
 $parent_obj
 
 $table
 
 $form
 

Private Member Functions

 accessDenied ()
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDataCollectionFieldEditGUI::__construct ( ilObjDataCollectionGUI  $a_parent_obj,
  $table_id,
  $field_id 
)

Constructor.

Parameters
object$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 59 of file class.ilDataCollectionFieldEditGUI.php.

59 {
60 global $ilCtrl;
61
62 $this->obj_id = $a_parent_obj->obj_id;
63 $this->parent_obj = $a_parent_obj;
64 $this->table_id = $table_id;
65 if (!$table_id) {
66 $table_id = $_GET["table_id"];
67 }
68
69 if (!isset($field_id)) {
70 $this->field_id = $_GET['field_id'];
71 }
72
73 if (isset($field_id)) {
74 $this->field_obj = ilDataCollectionCache::getFieldCache($field_id);
75 } else {
76 $this->field_obj = ilDataCollectionCache::getFieldCache();
77 if (!$table_id) {
78 $ilCtrl->redirectByClass("ilDataCollectionGUI", "listFields");
79 }
80 $this->field_obj->setTableId($table_id);
81 $ilCtrl->saveParameter($this, "table_id");
82 }
83
85 }
$_GET["client_id"]
global $ilCtrl
Definition: ilias.php:18

References $_GET, $ilCtrl, $table_id, ilDataCollectionCache\getFieldCache(), and ilDataCollectionCache\getTableCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ accessDenied()

ilDataCollectionFieldEditGUI::accessDenied ( )
private

Definition at line 494 of file class.ilDataCollectionFieldEditGUI.php.

494 {
495 global $tpl;
496 $tpl->setContent("Access Denied");
497 }
global $tpl
Definition: ilias.php:8

References $tpl.

Referenced by save().

+ Here is the caller graph for this function:

◆ cancel()

ilDataCollectionFieldEditGUI::cancel ( )

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

192 {
193 global $ilCtrl;
194 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
195 }

References $ilCtrl.

◆ cancelDelete()

ilDataCollectionFieldEditGUI::cancelDelete ( )

cancelDelete

Definition at line 171 of file class.ilDataCollectionFieldEditGUI.php.

171 {
172 global $ilCtrl;
173
174 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
175 }

References $ilCtrl.

◆ checkInput()

ilDataCollectionFieldEditGUI::checkInput (   $a_mode)
protected

Check input of form.

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

Definition at line 458 of file class.ilDataCollectionFieldEditGUI.php.

458 {
459 global $lng;
460 $return = $this->form->checkInput();
461
462 // Additional check for text fields: The length property should be max 200 if the textarea option is not set
463 if ($this->form->getInput('datatype') == ilDataCollectionDatatype::INPUTFORMAT_TEXT
464 && (int)$this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_LENGTH) > 200
465 && !$this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_TEXTAREA)
466 ) {
467 $inputObj = $this->form->getItemByPostVar('prop_' . ilDataCollectionField::PROPERTYID_LENGTH);
468 $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
469 $return = false;
470 }
471
472 // Don't allow multiple fields with the same title in this table
473 if ($a_mode == 'create') {
474 if ($title = $this->form->getInput('title')) {
475 if (ilDataCollectionTable::_hasFieldByTitle($title, $this->table_id)) {
476 $inputObj = $this->form->getItemByPostVar('title');
477 $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
478 $return = false;
479 }
480 }
481 }
482
483 if (!$return) {
484 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
485 }
486
487 return $return;
488 }
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:40

References $lng, ilDataCollectionTable\_hasFieldByTitle(), ilDataCollectionDatatype\INPUTFORMAT_TEXT, ilDataCollectionField\PROPERTYID_LENGTH, ilDataCollectionField\PROPERTYID_TEXTAREA, and ilUtil\sendFailure().

Referenced by save().

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

◆ confirmDelete()

ilDataCollectionFieldEditGUI::confirmDelete ( )

confirmDelete

Definition at line 151 of file class.ilDataCollectionFieldEditGUI.php.

151 {
152 global $ilCtrl, $lng, $tpl;
153
154 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
155 $conf = new ilConfirmationGUI();
156 $conf->setFormAction($ilCtrl->getFormAction($this));
157 $conf->setHeaderText($lng->txt('dcl_confirm_delete_field'));
158
159 $conf->addItem('field_id', (int)$this->field_obj->getId(), $this->field_obj->getTitle());
160
161 $conf->setConfirm($lng->txt('delete'), 'delete');
162 $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
163
164 $tpl->setContent($conf->getHTML());
165 }
Confirmation screen class.

References $ilCtrl, $lng, and $tpl.

◆ create()

ilDataCollectionFieldEditGUI::create ( )

create field add form

Definition at line 118 of file class.ilDataCollectionFieldEditGUI.php.

118 {
119 global $tpl;
120
121 $this->initForm();
122 $tpl->setContent($this->form->getHTML());
123 }
initForm($a_mode="create")
initEditCustomForm

References $tpl, and initForm().

+ Here is the call graph for this function:

◆ delete()

ilDataCollectionFieldEditGUI::delete ( )

Definition at line 181 of file class.ilDataCollectionFieldEditGUI.php.

181 {
182 global $ilCtrl;
183
184 $this->table->deleteField($this->field_obj->getId());
185 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
186 }

References $ilCtrl.

◆ edit()

ilDataCollectionFieldEditGUI::edit ( )

create field edit form

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

129 {
130 global $tpl;
131
132 $this->initForm("edit");
133 $this->getValues();
134
135 $tpl->setContent($this->form->getHTML());
136 }

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

+ Here is the call graph for this function:

◆ executeCommand()

ilDataCollectionFieldEditGUI::executeCommand ( )

execute command

Definition at line 91 of file class.ilDataCollectionFieldEditGUI.php.

91 {
92 global $tpl, $ilCtrl, $ilUser;
93
94 $cmd = $ilCtrl->getCmd();
95
96 if (!$this->table->hasPermissionToFields($this->parent_obj->ref_id)) {
97 $this->permissionDenied();
98
99 return;
100 }
101
102 switch ($cmd) {
103 case "update":
104 $this->save("update");
105 break;
106 default:
107 $this->$cmd();
108 break;
109 }
110
111 return true;
112 }
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15

References $cmd, $ilCtrl, $ilUser, $tpl, permissionDenied(), and save().

+ Here is the call graph for this function:

◆ getValues()

ilDataCollectionFieldEditGUI::getValues ( )

getFieldValues

Definition at line 356 of file class.ilDataCollectionFieldEditGUI.php.

356 {
357 //Std-Values
358 $values = array(
359 'table_id' => $this->field_obj->getTableId(),
360 'field_id' => $this->field_obj->getId(),
361 'title' => $this->field_obj->getTitle(),
362 'datatype' => $this->field_obj->getDatatypeId(),
363 'description' => $this->field_obj->getDescription(),
364 'required' => $this->field_obj->getRequired(),
365 'unique' => $this->field_obj->isUnique(),
366 );
367
368 $propertyvalues = $this->field_obj->getPropertyvalues();
369
370 // Propertie-Values - Subitems
371 foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) {
372 foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) {
373 $values['prop_' . $property['id']] = $propertyvalues[$property['id']];
374 }
375 }
376
377 $this->form->setValuesByArray($values);
378
379 return true;
380 }
static getProperties($a_id)
Get all properties of a Datatype.
static getAllDatatypes()
Get all possible Datatypes.

References ilDataCollectionDatatype\getAllDatatypes(), and ilDataCollectionDatatype\getProperties().

Referenced by edit().

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

◆ initForm()

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

initEditCustomForm

Parameters
string$a_modevalues: create | edit

Definition at line 203 of file class.ilDataCollectionFieldEditGUI.php.

203 {
204 global $ilCtrl, $lng;
205
206 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
207 $this->form = new ilPropertyFormGUI();
208
209 if ($a_mode == "edit") {
210 $this->form->setTitle($lng->txt('dcl_edit_field'));
211 $hidden_prop = new ilHiddenInputGUI("field_id");
212 $this->form->addItem($hidden_prop);
213
214 $this->form->setFormAction($ilCtrl->getFormAction($this), "update");
215
216 $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
217 } else {
218 $this->form->setTitle($lng->txt('dcl_new_field'));
219 $hidden_prop = new ilHiddenInputGUI("table_id");
220 $hidden_prop->setValue($this->field_obj->getTableId());
221 $this->form->addItem($hidden_prop);
222
223 $this->form->setFormAction($ilCtrl->getFormAction($this), "save");
224
225 $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
226 }
227 $this->form->addCommandButton('cancel', $lng->txt('cancel'));
228
229 $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
230 $text_prop->setRequired(true);
231 $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDataCollectionField::_getTitleValidChars(false)));
232 $text_prop->setValidationRegexp(ilDataCollectionField::_getTitleValidChars(true));
233 $this->form->addItem($text_prop);
234
235 $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
236 foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) {
237 $opt = new ilRadioOption($lng->txt('dcl_' . $datatype['title']), $datatype['id']);
238
239 foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) {
240 //Type Reference: List Tabels
241 if ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE AND
243 ) {
244 $options = array();
245 // Get Tables
246 require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
247 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
248 foreach ($tables as $table) {
249 foreach ($table->getRecordFields() as $field) {
250 //referencing references may lead to endless loops.
251 if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
252 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
253 }
254 }
255 }
256 $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']);
257 $table_selection->setOptions($options);
258 //$table_selection->setValue($this->table_id);
259 $opt->addSubItem($table_selection);
260 } //ReferenceList
261 elseif ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST AND
263 ) {
264 // Get Tables
265 require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
266 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
267 foreach ($tables as $table) {
268 foreach ($table->getRecordFields() as $field) {
269 //referencing references may lead to endless loops.
270 if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST) {
271 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
272 }
273 }
274 }
275 $table_selection = new ilSelectInputGUI('', 'prop_' . $property['id']);
276 $table_selection->setOptions($options);
277 $opt->addSubItem($table_selection);
278 } elseif ($property['id'] == ilDataCollectionField::PROPERTYID_FORMULA_EXPRESSION) {
280 $fields = array();
281 foreach ($table->getFieldsForFormula() as $f) {
282 $placeholder = ($f->isStandardField()) ? $f->getId() : $f->getTitle();
283 $fields[] = '<a class="dclPropExpressionField" data-placeholder="' . $placeholder . '">' . $f->getTitle() . '</a>';
284 }
285 $subitem = new ilTextAreaInputGUI($lng->txt('dcl_prop_expression'), 'prop_' . $property['id']);
286 $operators = implode(', ', array_keys(ilDclExpressionParser::getOperators()));
287 $functions = implode(', ', ilDclExpressionParser::getFunctions());
288 $subitem->setInfo(sprintf($lng->txt('dcl_prop_expression_info'), $operators, $functions, implode('<br>', $fields)));
289 $opt->addSubItem($subitem);
290 } elseif ($property['datatype_id'] == $datatype['id']) {
291 //All other Types: List properties saved in propertie definition table
292 if ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
293 $subitem = new ilCheckboxInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
294 if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
295 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
296 }
297 $opt->addSubItem($subitem);
298 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
299 $subitem = new ilNumberInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
300
301 // TODO: Nicer way to add additional info to fields (need changes in language-logic)
302 /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
303 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
304 }*/
305 $subitem->setSize(5);
306 if ($property['title'] == 'length') {
307 $subitem->setMaxValue(4000);
308 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
309 }
310 $opt->addSubItem($subitem);
311 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NON_EDITABLE_VALUE) {
312 $subitem = new ilNonEditableValueGUI($lng->txt('dcl_'.$property['title']));
313 $subitem->setValue(implode(', ', ilDataCollectionDatatype::$mob_suffixes));
314 $opt->addSubItem($subitem);
315 } else {
316 $subitem = new ilTextInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
317 // TODO: Nicer way to add additional info to fields (need changes in language-logic)
318 /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
319 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
320 }*/
321 if($property['title'] == 'regex') {
322 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
323 }
324 $opt->addSubItem($subitem);
325 }
326 }
327 }
328
329 $edit_datatype->addOption($opt);
330 }
331 $edit_datatype->setRequired(true);
332
333 //you can't change type but we still need it in POST
334 if ($a_mode == "edit") {
335 $edit_datatype->setDisabled(true);
336 }
337 $this->form->addItem($edit_datatype);
338
339 // Description
340 $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
341 $this->form->addItem($text_prop);
342
343 // Required
344 $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
345 $this->form->addItem($cb);
346
347 //Unique
348 $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
349 $this->form->addItem($cb);
350 }
This class represents a checkbox property in a property form.
static _getTitleValidChars($a_as_regex=true)
All valid chars for filed titles.
This class represents a hidden form property in a property form.
This class represents a non editable value in a property form.
This class represents a number 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 an option in a radio group.
This class represents a selection list 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.
if(!is_array($argv)) $options

References $_GET, $ilCtrl, $lng, ilDataCollectionDatatype\$mob_suffixes, $options, $table, ilDataCollectionField\_getTitleValidChars(), ilDataCollectionDatatype\getAllDatatypes(), ilDclExpressionParser\getFunctions(), ilDclExpressionParser\getOperators(), ilDataCollectionDatatype\getProperties(), ilDataCollectionCache\getTableCache(), ilDataCollectionDatatype\INPUTFORMAT_BOOLEAN, ilDataCollectionDatatype\INPUTFORMAT_NON_EDITABLE_VALUE, ilDataCollectionDatatype\INPUTFORMAT_NUMBER, ilDataCollectionDatatype\INPUTFORMAT_REFERENCE, ilDataCollectionDatatype\INPUTFORMAT_REFERENCELIST, ilDataCollectionField\PROPERTYID_FORMULA_EXPRESSION, ilDataCollectionField\PROPERTYID_N_REFERENCE, and ilDataCollectionField\PROPERTYID_REFERENCE.

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

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

◆ permissionDenied()

ilDataCollectionFieldEditGUI::permissionDenied ( )

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

142 {
143 global $tpl;
144 $tpl->setContent("Permission denied");
145 }

References $tpl.

Referenced by executeCommand().

+ Here is the caller graph for this function:

◆ save()

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

save Field

Parameters
string$a_modevalues: create | update

Definition at line 388 of file class.ilDataCollectionFieldEditGUI.php.

388 {
389 global $ilCtrl, $lng, $tpl;
390
391 //check access
392 if (!$this->table->hasPermissionToFields($this->parent_obj->ref_id)) {
393 $this->accessDenied();
394
395 return;
396 }
397
398 $this->initForm($a_mode == "update" ? "edit" : "create");
399 if ($this->checkInput($a_mode)) {
400 $title = $this->form->getInput("title");
401 if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
402 ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
403 }
404
405 $this->field_obj->setTitle($title);
406 $this->field_obj->setDescription($this->form->getInput("description"));
407 $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
408 $this->field_obj->setRequired($this->form->getInput("required"));
409 $this->field_obj->setUnique($this->form->getInput("unique"));
410
411 if ($a_mode == "update") {
412 $this->field_obj->doUpdate();
413 } else {
414 $this->field_obj->setVisible(true);
415 $this->field_obj->setOrder($this->table->getNewOrder());
416 $this->field_obj->doCreate();
417 }
418
419 // Get possible properties and save them
420 include_once("./Modules/DataCollection/classes/class.ilDataCollectionFieldProp.php");
421 foreach (ilDataCollectionDatatype::getProperties($this->field_obj->getDatatypeId()) as $property) {
422 $fieldprop_obj = new ilDataCollectionFieldProp();
423 $fieldprop_obj->setDatatypePropertyId($property['id']);
424 $fieldprop_obj->setFieldId($this->field_obj->getId());
425 $fieldprop_obj->setValue($this->form->getInput("prop_" . $property['id']));
426
427 if ($a_mode == "update") {
428 $fieldprop_obj->doUpdate();
429 } else {
430 $fieldprop_obj->doCreate();
431 }
432 }
433
434 $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
435
436 if ($a_mode == "update") {
437 ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"), true);
438 } else {
439 $this->table->addField($this->field_obj);
440 $this->table->buildOrderFields();
441 ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
442 }
443 $ilCtrl->redirectByClass(strtolower("ilDataCollectionFieldListGUI"), "listFields");
444 } else {
445 $this->form->setValuesByPost();
446 $tpl->setContent($this->form->getHTML());
447 }
448 }
Class ilDataCollectionFieldProp.
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 $ilCtrl, $lng, $tpl, accessDenied(), checkInput(), ilDataCollectionDatatype\getProperties(), initForm(), 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

◆ $form

ilDataCollectionFieldEditGUI::$form
protected

Definition at line 50 of file class.ilDataCollectionFieldEditGUI.php.

◆ $obj_id

ilDataCollectionFieldEditGUI::$obj_id
protected

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

◆ $parent_obj

ilDataCollectionFieldEditGUI::$parent_obj
protected

Definition at line 40 of file class.ilDataCollectionFieldEditGUI.php.

◆ $table

ilDataCollectionFieldEditGUI::$table
protected

Definition at line 45 of file class.ilDataCollectionFieldEditGUI.php.

Referenced by initForm().

◆ $table_id

ilDataCollectionFieldEditGUI::$table_id
protected

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

Referenced by __construct().

◆ REFERENCE_SEPARATOR

const ilDataCollectionFieldEditGUI::REFERENCE_SEPARATOR = " -> "

Definition at line 25 of file class.ilDataCollectionFieldEditGUI.php.


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