ILIAS  release_4-4 Revision
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...
 

Protected Member Functions

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

Private Member Functions

 accessDenied ()
 

Private Attributes

 $obj_id
 
 $table_id
 
 $parent_obj
 
 $table
 

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 35 of file class.ilDataCollectionFieldEditGUI.php.

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

36  {
37  global $ilCtrl;
38 
39  $this->obj_id = $a_parent_obj->obj_id;
40  $this->parent_obj = $a_parent_obj;
41  $this->table_id = $table_id;
42  if(!$table_id)
43  $table_id = $_GET["table_id"];
44 
45  if(!isset($field_id))
46  $this->field_id = $_GET['field_id'];
47 
48  if(isset($field_id))
49  {
50  $this->field_obj = ilDataCollectionCache::getFieldCache($field_id);
51  }
52  else
53  {
54  $this->field_obj = ilDataCollectionCache::getFieldCache();
55  if(!$table_id)
56  $ilCtrl->redirectByClass("ilDataCollectionGUI", "listFields");
57  $this->field_obj->setTableId($table_id);
58  $ilCtrl->saveParameter($this, "table_id");
59  }
60 
62  }
$_GET["client_id"]
global $ilCtrl
Definition: ilias.php:18
+ Here is the call graph for this function:

Member Function Documentation

◆ accessDenied()

ilDataCollectionFieldEditGUI::accessDenied ( )
private

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

References $tpl.

Referenced by save().

477  {
478  global $tpl;
479  $tpl->setContent("Access Denied");
480  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ Here is the caller graph for this function:

◆ cancel()

ilDataCollectionFieldEditGUI::cancel ( )

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

References $ilCtrl.

172  {
173  global $ilCtrl;
174  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
175  }
global $ilCtrl
Definition: ilias.php:18

◆ cancelDelete()

ilDataCollectionFieldEditGUI::cancelDelete ( )

cancelDelete

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

References $ilCtrl.

151  {
152  global $ilCtrl;
153 
154  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
155  }
global $ilCtrl
Definition: ilias.php:18

◆ checkInput()

ilDataCollectionFieldEditGUI::checkInput (   $a_mode)
protected

Check input of form.

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

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

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

Referenced by save().

444  {
445  global $lng;
446  $return = $this->form->checkInput();
447 
448  // Additional check for text fields: The length property should be max 200 if the textarea option is not set
449  if ($this->form->getInput('datatype') == ilDataCollectionDatatype::INPUTFORMAT_TEXT
450  && (int) $this->form->getInput('prop_'.ilDataCollectionField::PROPERTYID_LENGTH) > 200
451  && !$this->form->getInput('prop_'.ilDataCollectionField::PROPERTYID_TEXTAREA)) {
452  $inputObj = $this->form->getItemByPostVar('prop_'.ilDataCollectionField::PROPERTYID_LENGTH);
453  $inputObj->setAlert($lng->txt("form_msg_value_too_high"));
454  $return = false;
455  }
456 
457  // Don't allow multiple fields with the same title in this table
458  if ($a_mode == 'create') {
459  if ($title = $this->form->getInput('title')) {
460  if (ilDataCollectionTable::_hasFieldByTitle($title, $this->table_id)) {
461  $inputObj = $this->form->getItemByPostVar('title');
462  $inputObj->setAlert($lng->txt("dcl_field_title_unique"));
463  $return = false;
464  }
465  }
466  }
467 
468  if (!$return) ilUtil::sendFailure($lng->txt("form_input_not_valid"));
469 
470  return $return;
471  }
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $lng
Definition: privfeed.php:40
static _hasFieldByTitle($title, $obj_id)
Checks if a table has a field with the given title.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ confirmDelete()

ilDataCollectionFieldEditGUI::confirmDelete ( )

confirmDelete

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

References $ilCtrl, $lng, and $tpl.

131  {
132  global $ilCtrl, $lng, $tpl;
133 
134  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
135  $conf = new ilConfirmationGUI();
136  $conf->setFormAction($ilCtrl->getFormAction($this));
137  $conf->setHeaderText($lng->txt('dcl_confirm_delete_field'));
138 
139  $conf->addItem('field_id', (int) $this->field_obj->getId(), $this->field_obj->getTitle());
140 
141  $conf->setConfirm($lng->txt('delete'), 'delete');
142  $conf->setCancel($lng->txt('cancel'), 'cancelDelete');
143 
144  $tpl->setContent($conf->getHTML());
145  }
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
global $lng
Definition: privfeed.php:40
Confirmation screen class.

◆ create()

ilDataCollectionFieldEditGUI::create ( )

create field add form

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

References $tpl, and initForm().

96  {
97  global $tpl;
98 
99  $this->initForm();
100  $tpl->setContent($this->form->getHTML());
101  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
initForm($a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ delete()

ilDataCollectionFieldEditGUI::delete ( )

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

References $ilCtrl.

161  {
162  global $ilCtrl;
163 
164  $this->table->deleteField($this->field_obj->getId());
165  $ilCtrl->redirectByClass("ildatacollectionfieldlistgui", "listFields");
166  }
global $ilCtrl
Definition: ilias.php:18

◆ edit()

ilDataCollectionFieldEditGUI::edit ( )

create field edit form

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

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

107  {
108  global $tpl;
109 
110  $this->initForm("edit");
111  $this->getValues();
112 
113  $tpl->setContent($this->form->getHTML());
114  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
initForm($a_mode="create")
initEditCustomForm
+ Here is the call graph for this function:

◆ executeCommand()

ilDataCollectionFieldEditGUI::executeCommand ( )

execute command

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

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

69  {
70  global $tpl, $ilCtrl, $ilUser;
71 
72  $cmd = $ilCtrl->getCmd();
73 
74  if(!$this->table->hasPermissionToFields($this->parent_obj->ref_id)){
75  $this->permissionDenied();
76  return;
77  }
78 
79  switch($cmd)
80  {
81  case "update":
82  $this->save("update");
83  break;
84  default:
85  $this->$cmd();
86  break;
87  }
88 
89  return true;
90  }
$cmd
Definition: sahs_server.php:35
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:

◆ getValues()

ilDataCollectionFieldEditGUI::getValues ( )

getFieldValues

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

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

Referenced by edit().

329  {
330  //Std-Values
331  $values = array(
332  'table_id' => $this->field_obj->getTableId(),
333  'field_id' => $this->field_obj->getId(),
334  'title' => $this->field_obj->getTitle(),
335  'datatype' => $this->field_obj->getDatatypeId(),
336  'description' => $this->field_obj->getDescription(),
337  'required' => $this->field_obj->getRequired(),
338  'unique' => $this->field_obj->isUnique(),
339  );
340 
341  $propertyvalues = $this->field_obj->getPropertyvalues();
342 
343 
344  // Propertie-Values - Subitems
345  foreach(ilDataCollectionDatatype::getAllDatatypes() as $datatype)
346  {
347  foreach(ilDataCollectionDatatype::getProperties($datatype['id']) as $property)
348  {
349  $values['prop_'.$property['id']] = $propertyvalues[$property['id']];
350  }
351  }
352 
353  $this->form->setValuesByArray($values);
354 
355  return true;
356  }
static getAllDatatypes()
Get all possible Datatypes.
getProperties($a_id)
Get all properties of a Datatype.
+ 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 182 of file class.ilDataCollectionFieldEditGUI.php.

References $ilCtrl, $lng, $options, $table, ilDataCollectionField\_getTitleValidChars(), ilSubEnabledFormPropertyGUI\addSubItem(), ilDataCollectionDatatype\getAllDatatypes(), ilDataCollectionDatatype\getProperties(), ilDataCollectionDatatype\INPUTFORMAT_BOOLEAN, ilDataCollectionDatatype\INPUTFORMAT_NUMBER, ilDataCollectionDatatype\INPUTFORMAT_REFERENCE, ilDataCollectionDatatype\INPUTFORMAT_REFERENCELIST, ilDataCollectionField\PROPERTYID_REFERENCE, ilDataCollectionField\PROPERTYID_REFERENCELIST, ilFormPropertyGUI\setRequired(), and ilNumberInputGUI\setSize().

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

183  {
184  global $ilCtrl, $lng;
185 
186  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
187  $this->form = new ilPropertyFormGUI();
188 
189  if($a_mode == "edit")
190  {
191  $this->form->setTitle($lng->txt('dcl_edit_field'));
192  $hidden_prop = new ilHiddenInputGUI("field_id");
193  $this->form->addItem($hidden_prop);
194 
195  $this->form->setFormAction($ilCtrl->getFormAction($this),"update");
196 
197  $this->form->addCommandButton('update', $lng->txt('dcl_update_field'));
198  }
199  else
200  {
201  $this->form->setTitle($lng->txt('dcl_new_field'));
202  $hidden_prop = new ilHiddenInputGUI("table_id");
203  $hidden_prop->setValue($this->field_obj->getTableId());
204  $this->form->addItem($hidden_prop);
205 
206  $this->form->setFormAction($ilCtrl->getFormAction($this),"save");
207 
208  $this->form->addCommandButton('save', $lng->txt('dcl_create_field'));
209  }
210  $this->form->addCommandButton('cancel', $lng->txt('cancel'));
211 
212  $text_prop = new ilTextInputGUI($lng->txt("title"), "title");
213  $text_prop->setRequired(true);
214  $text_prop->setInfo(sprintf($lng->txt('fieldtitle_allow_chars'), ilDataCollectionField::_getTitleValidChars(false)));
215  $text_prop->setValidationRegexp(ilDataCollectionField::_getTitleValidChars(true));
216  $this->form->addItem($text_prop);
217 
218 
219  $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'),'datatype');
220  foreach(ilDataCollectionDatatype::getAllDatatypes() as $datatype)
221  {
222  $opt = new ilRadioOption($lng->txt('dcl_'.$datatype['title']), $datatype['id']);
223 
224  foreach(ilDataCollectionDatatype::getProperties($datatype['id']) as $property)
225  {
226  //Type Reference: List Tabels
228  {
229  // Get Tables
230  require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
231  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
232  foreach($tables as $table)
233  {
234  foreach($table->getRecordFields() as $field)
235  {
236  //referencing references may lead to endless loops.
237  if($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCE)
238  {
239  $options[$field->getId()] = $table->getTitle()."->".$field->getTitle();
240  }
241  }
242  }
243  $table_selection = new ilSelectInputGUI(
244  '',
245  'prop_'.$property['id']
246  );
247  $table_selection->setOptions($options);
248  //$table_selection->setValue($this->table_id);
249  $opt->addSubItem($table_selection);
250 
251  }
252  //ReferenceList
254  {
255  // Get Tables
256  require_once("./Modules/DataCollection/classes/class.ilDataCollectionTable.php");
257  $tables = $this->parent_obj->getDataCollectionObject()->getTables();
258  foreach($tables as $table)
259  {
260  foreach($table->getRecordFields() as $field)
261  {
262  //referencing references may lead to endless loops.
263  if($field->getDatatypeId() != ilDataCollectionDatatype::INPUTFORMAT_REFERENCELIST)
264  {
265  $options[$field->getId()] = $table->getTitle()."->".$field->getTitle();
266  }
267  }
268  }
269  $table_selection = new ilSelectInputGUI(
270  '',
271  'prop_'.$property['id']
272  );
273  $table_selection->setOptions($options);
274  $opt->addSubItem($table_selection);
275  }
276  //All other Types: List properties saved in propertie definition table
277  elseif($property['datatype_id'] == $datatype['id'])
278  {
279  if($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_BOOLEAN)
280  {
281  $subitem = new ilCheckboxInputGUI($lng->txt('dcl_'.$property['title']), 'prop_'.$property['id']);
282  $opt->addSubItem($subitem);
283  }
284  else if ($property['inputformat'] == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
285  $subitem = new ilNumberInputGUI($lng->txt('dcl_'.$property['title']), 'prop_'.$property['id']);
286  $subitem->setSize(5);
287  if ($property['title'] == 'length') {
288  $subitem->setMaxValue(4000);
289  }
290  $opt->addSubItem($subitem);
291  } else {
292  $subitem = new ilTextInputGUI($lng->txt('dcl_'.$property['title']), 'prop_'.$property['id']);
293  $opt->addSubItem($subitem);
294  }
295  }
296  }
297 
298 
299 
300 
301  $edit_datatype->addOption($opt);
302  }
303  $edit_datatype->setRequired(true);
304 
305  //you can't change type but we still need it in POST
306  if($a_mode == "edit")
307  {
308  $edit_datatype->setDisabled(true);
309  }
310  $this->form->addItem($edit_datatype);
311 
312  // Description
313  $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description");
314  $this->form->addItem($text_prop);
315 
316  // Required
317  $cb = new ilCheckboxInputGUI($lng->txt("dcl_field_required"), "required");
318  $this->form->addItem($cb);
319 
320  //Unique
321  $cb = new ilCheckboxInputGUI($lng->txt("dcl_unique"), "unique");
322  $this->form->addItem($cb);
323  }
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a property form user interface.
This class represents a checkbox property in a property form.
static getAllDatatypes()
Get all possible Datatypes.
static _getTitleValidChars($a_as_regex=true)
All valid chars for filed titles.
getProperties($a_id)
Get all properties of a Datatype.
global $ilCtrl
Definition: ilias.php:18
This class represents a hidden form property in a property form.
This class represents a property in a property form.
if(!is_array($argv)) $options
This class represents a number property in a property form.
This class represents a text property in a property form.
setSize($a_size)
Set Size.
global $lng
Definition: privfeed.php:40
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()

ilDataCollectionFieldEditGUI::permissionDenied ( )

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

References $tpl.

Referenced by executeCommand().

120  {
121  global $tpl;
122  $tpl->setContent("Permission denied");
123  }
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
+ 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 364 of file class.ilDataCollectionFieldEditGUI.php.

References $ilCtrl, $lng, $tpl, accessDenied(), checkInput(), ilDataCollectionDatatype\getProperties(), initForm(), ilUtil\sendInfo(), and ilUtil\sendSuccess().

Referenced by executeCommand().

365  {
366  global $ilCtrl, $lng, $tpl;
367 
368  //check access
369  if(!$this->table->hasPermissionToFields($this->parent_obj->ref_id)){
370  $this->accessDenied();
371  return;
372  }
373 
374  $this->initForm($a_mode == "update"?"edit":"create");
375  if ($this->checkInput($a_mode))
376  {
377  $title = $this->form->getInput("title");
378  if($a_mode != "create" && $title != $this->field_obj->getTitle())
379  ilUtil::sendInfo($lng->txt("dcl_field_title_change_warning"), true);
380 
381  $this->field_obj->setTitle($title);
382  $this->field_obj->setDescription($this->form->getInput("description"));
383  $this->field_obj->setDatatypeId($this->form->getInput("datatype"));
384  $this->field_obj->setRequired($this->form->getInput("required"));
385  $this->field_obj->setUnique($this->form->getInput("unique"));
386 
387  if($a_mode == "update")
388  {
389  $this->field_obj->doUpdate();
390  }
391  else
392  {
393  $this->field_obj->setVisible(true);
394  $this->field_obj->setOrder($this->table->getNewOrder());
395  $this->field_obj->doCreate();
396  }
397 
398  // Get possible properties and save them
399  include_once("./Modules/DataCollection/classes/class.ilDataCollectionFieldProp.php");
400  foreach(ilDataCollectionDatatype::getProperties($this->field_obj->getDatatypeId()) as $property)
401  {
402  $fieldprop_obj = new ilDataCollectionFieldProp();
403  $fieldprop_obj->setDatatypePropertyId($property['id']);
404  $fieldprop_obj->setFieldId($this->field_obj->getId());
405  $fieldprop_obj->setValue($this->form->getInput("prop_".$property['id']));
406 
407  if($a_mode == "update")
408  {
409  $fieldprop_obj->doUpdate();
410  }
411  else
412  {
413  $fieldprop_obj->doCreate();
414  }
415 
416  }
417 
418  $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId());
419 
420  if($a_mode == "update")
421  {
422  ilUtil::sendSuccess($lng->txt("dcl_msg_field_modified"),true);
423  }
424  else
425  {
426  $this->table->addField($this->field_obj);
427  $this->table->buildOrderFields();
428  ilUtil::sendSuccess($lng->txt("msg_field_created"), false);
429  }
430  $ilCtrl->redirectByClass(strtolower("ilDataCollectionFieldListGUI"), "listFields");
431  }
432  else
433  {
434  $this->form->setValuesByPost();
435  $tpl->setContent($this->form->getHTML());
436  }
437  }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
Class ilDataCollectionFieldProp.
getProperties($a_id)
Get all properties of a Datatype.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
initForm($a_mode="create")
initEditCustomForm
global $lng
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $obj_id

ilDataCollectionFieldEditGUI::$obj_id
private

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

◆ $parent_obj

ilDataCollectionFieldEditGUI::$parent_obj
private

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

◆ $table

ilDataCollectionFieldEditGUI::$table
private

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

Referenced by initForm().

◆ $table_id

ilDataCollectionFieldEditGUI::$table_id
private

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

Referenced by __construct().


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