ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDataCollectionFieldEditGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once("./Modules/DataCollection/classes/class.ilDataCollectionField.php");
4require_once("./Modules/DataCollection/classes/class.ilDataCollectionDatatype.php");
5require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
6require_once "class.ilDataCollectionCache.php";
7require_once('./Services/Form/classes/class.ilNonEditableValueGUI.php');
8
23
24
25 const REFERENCE_SEPARATOR = " -> ";
26
30 protected $obj_id;
31
35 protected $table_id;
36
40 protected $parent_obj;
41
45 protected $table;
46
50 protected $form;
51
59 public function __construct(ilObjDataCollectionGUI $a_parent_obj, $table_id, $field_id) {
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 }
86
87
91 public function executeCommand() {
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 }
113
114
118 public function create() {
119 global $tpl;
120
121 $this->initForm();
122 $tpl->setContent($this->form->getHTML());
123 }
124
125
129 public function edit() {
130 global $tpl;
131
132 $this->initForm("edit");
133 $this->getValues();
134
135 $tpl->setContent($this->form->getHTML());
136 }
137
138
139 /*
140 * permissionDenied
141 */
142 public function permissionDenied() {
143 global $tpl;
144 $tpl->setContent("Permission denied");
145 }
146
147
151 public function confirmDelete() {
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 }
166
167
171 public function cancelDelete() {
172 global $ilCtrl;
173
174 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
175 }
176
177
178 /*
179 * delete
180 */
181 public function delete() {
182 global $ilCtrl;
183
184 $this->table->deleteField($this->field_obj->getId());
185 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
186 }
187
188
189 /*
190 * cancel
191 */
192 public function cancel() {
193 global $ilCtrl;
194 $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
195 }
196
197
203 public function initForm($a_mode = "create") {
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 // Description
236 $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
237 $this->form->addItem($text_prop);
238
239 $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype');
240 foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) {
241 $opt = new ilRadioOption($lng->txt('dcl_' . $datatype['title']), $datatype['id']);
242
243 foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) {
244 //Type Reference: List Tabels
245 if ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCE AND
247 ) {
248 $options = array();
249 // Get Tables
250 require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
251 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
252 foreach ($tables as $table) {
253 foreach ($table->getRecordFields() as $field) {
254 //referencing references may lead to endless loops.
255 if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCE) {
256 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
257 }
258 }
259 }
260 $table_selection = new ilSelectInputGUI($lng->txt('dcl_reference_title'), 'prop_' . $property['id']);
261 $table_selection->setOptions($options);
262 //$table_selection->setValue($this->table_id);
263 $opt->addSubItem($table_selection);
264 } //ReferenceList
265 elseif ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST AND
267 ) {
268 // Get Tables
269 require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
270 $tables = $this->parent_obj->getDataCollectionObject()->getTables();
271 foreach ($tables as $table) {
272 foreach ($table->getRecordFields() as $field) {
273 //referencing references may lead to endless loops.
274 if ($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST) {
275 $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle();
276 }
277 }
278 }
279 $table_selection = new ilSelectInputGUI($lng->txt('dcl_reference_title'), 'prop_' . $property['id']);
280 $table_selection->setOptions($options);
281 $opt->addSubItem($table_selection);
282 } elseif ($property['id'] == ilDataCollectionField::PROPERTYID_FORMULA_EXPRESSION) {
284 $fields = array();
285 foreach ($table->getFieldsForFormula() as $f) {
286 $placeholder = ($f->isStandardField()) ? $f->getId() : $f->getTitle();
287 $fields[] = '<a class="dclPropExpressionField" data-placeholder="' . $placeholder . '">' . $f->getTitle() . '</a>';
288 }
289 $subitem = new ilTextAreaInputGUI($lng->txt('dcl_prop_expression'), 'prop_' . $property['id']);
290 $operators = implode(', ', array_keys(ilDclExpressionParser::getOperators()));
291 $functions = implode(', ', ilDclExpressionParser::getFunctions());
292 $subitem->setInfo(sprintf($lng->txt('dcl_prop_expression_info'), $operators, $functions, implode('<br>', $fields)));
293 $opt->addSubItem($subitem);
294 } elseif ($property['datatype_id'] == $datatype['id']) {
295 //All other Types: List properties saved in propertie definition table
296 if ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN) {
297 $subitem = new ilCheckboxInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
298 if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
299 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
300 }
301 $opt->addSubItem($subitem);
302 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
303 $subitem = new ilNumberInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
304
305 // TODO: Nicer way to add additional info to fields (need changes in language-logic)
306 /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
307 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
308 }*/
309 $subitem->setSize(5);
310 if ($property['title'] == 'length') {
311 $subitem->setMaxValue(4000);
312 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
313 }
314 $opt->addSubItem($subitem);
315 } elseif ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NON_EDITABLE_VALUE) {
316 // TODO Not required atm, otherwise we need to define where the value for the field comes from
317 //$subitem = new ilNonEditableValueGUI($lng->txt('dcl_' . $property['title']));
318 //$subitem->setValue(implode(', ', ilDataCollectionDatatype::$mob_suffixes));
319 //$opt->addSubItem($subitem);
320 } else {
321 $subitem = new ilTextInputGUI($lng->txt('dcl_' . $property['title']), 'prop_' . $property['id']);
322 // TODO: Nicer way to add additional info to fields (need changes in language-logic)
323 /*if($lng->txt('dcl_'.$property['title'].'_info') != '-dcl_'.$property['title'].'_info-') {
324 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
325 }*/
326 if($property['title'] == 'regex') {
327 $subitem->setInfo($lng->txt('dcl_'.$property['title'].'_info'));
328 }
329 $opt->addSubItem($subitem);
330 }
331 }
332 }
333
334 $opt->setInfo($lng->txt('dcl_' . $datatype['title'] . '_desc'));
335 if ($datatype['id'] == ilDataCollectionDatatype::INPUTFORMAT_MOB) {
336 $opt->setInfo(sprintf($lng->txt('dcl_' . $datatype['title'] . '_desc'), implode(', ', ilDataCollectionDatatype::$mob_suffixes)));
337 }
338 $edit_datatype->addOption($opt);
339 }
340 $edit_datatype->setRequired(true);
341
342 //you can't change type but we still need it in POST
343 if ($a_mode == "edit") {
344 $edit_datatype->setDisabled(true);
345 }
346 $this->form->addItem($edit_datatype);
347
348 // Required
349 $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
350 $this->form->addItem($cb);
351
352 //Unique
353 $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
354 $cb->setInfo($lng->txt('dcl_unique_desc'));
355 $this->form->addItem($cb);
356 }
357
358
362 public function getValues() {
363 //Std-Values
364 $values = array(
365 'table_id' => $this->field_obj->getTableId(),
366 'field_id' => $this->field_obj->getId(),
367 'title' => $this->field_obj->getTitle(),
368 'datatype' => $this->field_obj->getDatatypeId(),
369 'description' => $this->field_obj->getDescription(),
370 'required' => $this->field_obj->getRequired(),
371 'unique' => $this->field_obj->isUnique(),
372 );
373
374 $propertyvalues = $this->field_obj->getPropertyvalues();
375
376 // Propertie-Values - Subitems
377 foreach (ilDataCollectionDatatype::getAllDatatypes() as $datatype) {
378 foreach (ilDataCollectionDatatype::getProperties($datatype['id']) as $property) {
379 $values['prop_' . $property['id']] = $propertyvalues[$property['id']];
380 }
381 }
382
383 $this->form->setValuesByArray($values);
384
385 return true;
386 }
387
388
394 public function save($a_mode = "create") {
395 global $ilCtrl, $lng, $tpl;
396
397 //check access
398 if (!$this->table->hasPermissionToFields($this->parent_obj->ref_id)) {
399 $this->accessDenied();
400
401 return;
402 }
403
404 $this->initForm($a_mode == "update" ? "edit" : "create");
405 if ($this->checkInput($a_mode)) {
406 $title = $this->form->getInput("title");
407 if ($a_mode != "create" && $title != $this->field_obj->getTitle()) {
408 ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
409 }
410
411 $this->field_obj->setTitle($title);
412 $this->field_obj->setDescription($this->form->getInput("description"));
413 $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
414 $this->field_obj->setRequired($this->form->getInput("required"));
415 $this->field_obj->setUnique($this->form->getInput("unique"));
416
417 if ($a_mode == "update") {
418 $this->field_obj->doUpdate();
419 } else {
420 $this->field_obj->setVisible(true);
421 $this->field_obj->setOrder($this->table->getNewOrder());
422 $this->field_obj->doCreate();
423 }
424
425 // Get possible properties and save them
426 include_once("./Modules/DataCollection/classes/class.ilDataCollectionFieldProp.php");
427 foreach (ilDataCollectionDatatype::getProperties($this->field_obj->getDatatypeId()) as $property) {
428 $fieldprop_obj = new ilDataCollectionFieldProp();
429 $fieldprop_obj->setDatatypePropertyId($property['id']);
430 $fieldprop_obj->setFieldId($this->field_obj->getId());
431 $fieldprop_obj->setValue($this->form->getInput("prop_" . $property['id']));
432
433 if ($a_mode == "update") {
434 $fieldprop_obj->doUpdate();
435 } else {
436 $fieldprop_obj->doCreate();
437 }
438 }
439
440 $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
441
442 if ($a_mode == "update") {
443 ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"), true);
444 } else {
445 $this->table->addField($this->field_obj);
446 $this->table->buildOrderFields();
447 ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
448 }
449 $ilCtrl->redirectByClass(strtolower("ilDataCollectionFieldListGUI"), "listFields");
450 } else {
451 $this->form->setValuesByPost();
452 $tpl->setContent($this->form->getHTML());
453 }
454 }
455
456
464 protected function checkInput($a_mode) {
465 global $lng;
466 $return = $this->form->checkInput();
467
468 // Additional check for text fields: The length property should be max 200 if the textarea option is not set
469 if ($this->form->getInput('datatype') == ilDataCollectionDatatype::INPUTFORMAT_TEXT
470 && (int)$this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_LENGTH) > 200
471 && !$this->form->getInput('prop_' . ilDataCollectionField::PROPERTYID_TEXTAREA)
472 ) {
473 $inputObj = $this->form->getItemByPostVar('prop_' . ilDataCollectionField::PROPERTYID_LENGTH);
474 $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
475 $return = false;
476 }
477
478 // Don't allow multiple fields with the same title in this table
479 if ($a_mode == 'create') {
480 if ($title = $this->form->getInput('title')) {
481 if (ilDataCollectionTable::_hasFieldByTitle($title, $this->table_id)) {
482 $inputObj = $this->form->getItemByPostVar('title');
483 $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
484 $return = false;
485 }
486 }
487 }
488
489 if (!$return) {
490 ilUtil::sendFailure($lng->txt("form_input_not_valid"));
491 }
492
493 return $return;
494 }
495
496
497 /*
498 * accessDenied
499 */
500 private function accessDenied() {
501 global $tpl;
502 $tpl->setContent("Access Denied");
503 }
504}
505
506?>
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
This class represents a checkbox property in a property form.
Confirmation screen class.
static getProperties($a_id)
Get all properties of a Datatype.
static getAllDatatypes()
Get all possible Datatypes.
Class ilDataCollectionFieldEditGUI.
initForm($a_mode="create")
initEditCustomForm
__construct(ilObjDataCollectionGUI $a_parent_obj, $table_id, $field_id)
Constructor.
Class ilDataCollectionFieldProp.
static _getTitleValidChars($a_as_regex=true)
All valid chars for filed titles.
static _hasFieldByTitle($title, $obj_id)
Checks if a table has a field with the given title.
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
Class ilObjDataCollectionGUI.
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.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options
global $ilUser
Definition: imgupload.php:15