ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 $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 }
351
352
356 public function getValues() {
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 }
381
382
388 public function save($a_mode = "create") {
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 }
449
450
458 protected function checkInput($a_mode) {
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 }
489
490
491 /*
492 * accessDenied
493 */
494 private function accessDenied() {
495 global $tpl;
496 $tpl->setContent("Access Denied");
497 }
498}
499
500?>
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 non editable value 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