ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCustomUserFieldsGUI Class Reference

Class ilCustomUserFieldsGUI. More...

+ Collaboration diagram for ilCustomUserFieldsGUI:

Public Member Functions

 __construct (int $ref_id, int $requested_field_id)
 
 executeCommand ()
 
 listUserDefinedFields ()
 
 addField (?ilPropertyFormGUI $a_form=null)
 
 getAccessOptions ()
 Get all access options, order is kept in forms. More...
 
 create ()
 
 edit (?ilPropertyFormGUI $a_form=null)
 
 update ()
 
 askDeleteField ()
 
 deleteField ()
 
 updateFields (string $action='')
 Update custom fields properties (from table gui) More...
 

Static Public Member Functions

static getAccessPermissions ()
 

Protected Member Functions

 getPermissions ()
 
 initFieldDefinition ()
 
 initForm (string $a_mode='create')
 
 validateForm (ilPropertyFormGUI $form, ilUserDefinedFields $user_field_definitions, array &$access, ?array $a_field_permissions=null)
 

Private Attributes

UserGUIRequest $request
 
ilCtrlInterface $ctrl
 
Language $lng
 
UIFactory $ui_factory
 
ilGlobalTemplateInterface $main_tpl
 
ilToolbarGUI $toolbar
 
int $ref_id = 0
 
bool $confirm_change = false
 
int $field_id = 0
 
array $field_definition = []
 
ilClaimingPermissionHelper $permissions
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilCustomUserFieldsGUI::__construct ( int  $ref_id,
int  $requested_field_id 
)

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

References $DIC, $ref_id, ilUserDefinedFields\_getInstance(), ILIAS\Repository\ctrl(), ilClaimingPermissionHelper\getInstance(), ILIAS\Repository\lng(), and ILIAS\Repository\toolbar().

51  {
52  global $DIC;
53  $this->main_tpl = $DIC->ui()->mainTemplate();
54  $this->ctrl = $DIC['ilCtrl'];
55  $this->lng = $DIC['lng'];
56  $this->ui_factory = $DIC['ui.factory'];
57  $this->toolbar = $DIC['ilToolbar'];
58 
59  $this->lng->loadLanguageModule('user');
60  $this->lng->loadLanguageModule('administration');
61 
62  $this->ref_id = $ref_id;
63 
64  $this->field_id = $requested_field_id;
65  $this->ctrl->saveParameter($this, 'field_id', $this->field_id);
66 
67  if ($this->field_id) {
68  $user_field_definitions = ilUserDefinedFields::_getInstance();
69  $this->field_definition = $user_field_definitions->getDefinition($this->field_id);
70  }
71 
72  $this->permissions = ilUDFPermissionHelper::getInstance(
73  $DIC->user()->getId(),
74  $ref_id
75  );
76  $this->request = new UserGUIRequest(
77  $DIC->http(),
78  $DIC->refinery()
79  );
80  }
global $DIC
Definition: shib_login.php:22
static getInstance(int $a_user_id, int $a_ref_id)
+ Here is the call graph for this function:

Member Function Documentation

◆ addField()

ilCustomUserFieldsGUI::addField ( ?ilPropertyFormGUI  $a_form = null)

Definition at line 124 of file class.ilCustomUserFieldsGUI.php.

References initForm().

Referenced by create().

124  : void
125  {
126  if (!$a_form) {
127  $a_form = $this->initForm('create');
128  }
129 
130  $this->main_tpl->setContent($a_form->getHTML());
131  }
initForm(string $a_mode='create')
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ askDeleteField()

ilCustomUserFieldsGUI::askDeleteField ( )

Definition at line 629 of file class.ilCustomUserFieldsGUI.php.

References $id, ilUserDefinedFields\_getInstance(), ILIAS\Repository\ctrl(), listUserDefinedFields(), and ILIAS\Repository\lng().

629  : bool
630  {
631  $fields = $this->request->getFields();
632  if (count($fields) == 0) {
633  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'));
634  $this->listUserDefinedFields();
635  return false;
636  }
637 
638  $confirmation_gui = new ilConfirmationGUI();
639  $confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
640  $confirmation_gui->setHeaderText($this->lng->txt('udf_delete_sure'));
641  $confirmation_gui->setCancel($this->lng->txt('cancel'), 'listUserDefinedFields');
642  $confirmation_gui->setConfirm($this->lng->txt('delete'), 'deleteField');
643 
644  $user_field_definitions = ilUserDefinedFields::_getInstance();
645  foreach ($fields as $id) {
646  $definition = $user_field_definitions->getDefinition($id);
647  $confirmation_gui->addItem('fields[]', (string) $id, $definition['field_name']);
648  }
649 
650  $this->main_tpl->setContent($confirmation_gui->getHTML());
651 
652  return true;
653  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ create()

ilCustomUserFieldsGUI::create ( )

Definition at line 439 of file class.ilCustomUserFieldsGUI.php.

References XapiProxy\$plugin, ilUserDefinedFields\_getInstance(), ilMemberAgreement\_reset(), addField(), ILIAS\Repository\ctrl(), ilCustomUserFieldsHelper\getInstance(), initForm(), ILIAS\Repository\lng(), and validateForm().

439  : void
440  {
441  $user_field_definitions = ilUserDefinedFields::_getInstance();
442  $user_field_definitions->setFieldType(
443  $this->request->getFieldType()
444  );
445 
446  $access = [];
447  $form = $this->initForm('create');
448  if ($this->validateForm($form, $user_field_definitions, $access)) {
449  $user_field_definitions->setFieldName($form->getInput('name'));
450  $user_field_definitions->enableVisible($access['visible']);
451  $user_field_definitions->enableVisibleRegistration((bool) $access['visib_reg']);
452  $user_field_definitions->enableVisibleLocalUserAdministration($access['visib_lua']);
453  $user_field_definitions->enableCourseExport($access['course_export']);
454  $user_field_definitions->enableGroupExport($access['group_export']);
455  $user_field_definitions->enablePrgExport($access['prg_export']);
456  $user_field_definitions->enableChangeable($access['changeable']);
457  $user_field_definitions->enableChangeableLocalUserAdministration($access['changeable_lua']);
458  $user_field_definitions->enableRequired($access['required']);
459  $user_field_definitions->enableExport($access['export']);
460  $user_field_definitions->enableSearchable($access['searchable']);
461  $user_field_definitions->enableCertificate($access['certificate']);
462  $new_id = $user_field_definitions->add();
463 
464  if ($user_field_definitions->isPluginType()) {
465  $plugin = ilCustomUserFieldsHelper::getInstance()->getPluginForType($user_field_definitions->getFieldType());
466  if ($plugin instanceof ilUDFDefinitionPlugin) {
467  $plugin->updateDefinitionFromForm($form, $new_id);
468  }
469  }
470  if ($access['course_export']) {
472  }
473 
474  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('udf_added_field'), true);
475  $this->ctrl->redirect($this);
476  }
477 
478  $form->setValuesByPost();
479  $this->addField($form);
480  }
validateForm(ilPropertyFormGUI $form, ilUserDefinedFields $user_field_definitions, array &$access, ?array $a_field_permissions=null)
addField(?ilPropertyFormGUI $a_form=null)
static _reset()
Reset all.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initForm(string $a_mode='create')
+ Here is the call graph for this function:

◆ deleteField()

ilCustomUserFieldsGUI::deleteField ( )

Definition at line 655 of file class.ilCustomUserFieldsGUI.php.

References $id, ilUserDefinedFields\_getInstance(), ilUDFPermissionHelper\ACTION_FIELD_DELETE, ilUDFPermissionHelper\CONTEXT_FIELD, ILIAS\Repository\ctrl(), getPermissions(), and ILIAS\Repository\lng().

655  : void
656  {
657  $user_field_definitions = ilUserDefinedFields::_getInstance();
658  $fields = $this->request->getFields();
659 
660  // all fields have to be deletable
661  $fail = [];
662  foreach ($fields as $id) {
663  if (!$this->getPermissions()->hasPermission(
665  (string) $id,
667  )) {
668  $field = $user_field_definitions->getDefinition($id);
669  $fail[] = $field['field_name'];
670  }
671  }
672  if ($fail) {
673  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_delete') . ' ' . implode(', ', $fail), true);
674  $this->ctrl->redirect($this, 'listUserDefinedFields');
675  }
676 
677  foreach ($fields as $id) {
678  $user_field_definitions->delete($id);
679  }
680 
681  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('udf_field_deleted'), true);
682  $this->ctrl->redirect($this);
683  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

◆ edit()

ilCustomUserFieldsGUI::edit ( ?ilPropertyFormGUI  $a_form = null)

Definition at line 482 of file class.ilCustomUserFieldsGUI.php.

References initForm().

Referenced by update().

482  : void
483  {
484  if (!$a_form) {
485  $a_form = $this->initForm('edit');
486  }
487 
488  $this->main_tpl->setContent($a_form->getHTML());
489  }
initForm(string $a_mode='create')
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ executeCommand()

ilCustomUserFieldsGUI::executeCommand ( )

Definition at line 87 of file class.ilCustomUserFieldsGUI.php.

References ILIAS\Repository\ctrl().

87  : void
88  {
89  $next_class = $this->ctrl->getNextClass($this);
90  $cmd = $this->ctrl->getCmd();
91 
92  switch ($next_class) {
93  default:
94  if (!$cmd) {
95  $cmd = 'listUserDefinedFields';
96  }
97  $this->$cmd();
98  break;
99  }
100  }
+ Here is the call graph for this function:

◆ getAccessOptions()

ilCustomUserFieldsGUI::getAccessOptions ( )

Get all access options, order is kept in forms.

Returns
array<string,string>

Definition at line 137 of file class.ilCustomUserFieldsGUI.php.

References ILIAS\Repository\lng().

Referenced by initForm(), and validateForm().

137  : array
138  {
139  $opts = [];
140  $opts['visible'] = $this->lng->txt('user_visible_in_profile');
141  $opts['visib_reg'] = $this->lng->txt('visible_registration');
142  $opts['visib_lua'] = $this->lng->txt('usr_settings_visib_lua');
143  $opts['course_export'] = $this->lng->txt('course_export');
144  $opts['group_export'] = $this->lng->txt('group_export');
145  $opts["prg_export"] = $this->lng->txt("prg_export");
146  $opts['changeable'] = $this->lng->txt('changeable');
147  $opts['changeable_lua'] = $this->lng->txt('usr_settings_changeable_lua');
148  $opts['required'] = $this->lng->txt('required_field');
149  $opts['export'] = $this->lng->txt('export');
150  $opts['searchable'] = $this->lng->txt('header_searchable');
151  $opts['certificate'] = $this->lng->txt('certificate');
152  return $opts;
153  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAccessPermissions()

static ilCustomUserFieldsGUI::getAccessPermissions ( )
static
Returns
array<string,string>

Definition at line 158 of file class.ilCustomUserFieldsGUI.php.

References ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CERTIFICATE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_EXPORT, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_REQUIRED, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_SEARCHABLE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_COURSES, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PRG, and ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION.

Referenced by ilCustomUserFieldSettingsTableGUI\__construct().

158  : array
159  {
160  return [
173  ];
174  }
+ Here is the caller graph for this function:

◆ getPermissions()

ilCustomUserFieldsGUI::getPermissions ( )
protected

Definition at line 82 of file class.ilCustomUserFieldsGUI.php.

References $permissions.

Referenced by deleteField(), and listUserDefinedFields().

83  {
84  return $this->permissions;
85  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilClaimingPermissionHelper $permissions
+ Here is the caller graph for this function:

◆ initFieldDefinition()

ilCustomUserFieldsGUI::initFieldDefinition ( )
protected

Definition at line 176 of file class.ilCustomUserFieldsGUI.php.

References ilMemberAgreement\_hasAgreements(), ilUDFPermissionHelper\ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper\ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper\CONTEXT_FIELD, ILIAS\Repository\lng(), ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CERTIFICATE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_EXPORT, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_REQUIRED, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_SEARCHABLE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_COURSES, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PRG, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION, ilUDFPermissionHelper\SUBACTION_FIELD_PROPERTIES, and ilUDFPermissionHelper\SUBACTION_FIELD_TITLE.

Referenced by initForm().

176  : array // Missing array type.
177  {
179  $this->lng->loadLanguageModule('ps');
180  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('ps_warning_modify'));
181  }
182 
183  $perms = [];
184  if ($this->field_definition) {
185  $perms = $this->permissions->hasPermissions(
187  (string) $this->field_definition['field_id'],
188  [
189  [
192  ],
193  [
196  ],
197  [
200  ],
201  [
204  ],
205  [
208  ],
209  [
212  ],
213  [
216  ],
217  [
220  ],
221  [
224  ],
225  [
228  ],
229  [
232  ],
233  [
236  ],
237  [
240  ],
241  [
244  ]
245  ]
246  );
247  }
248  return $perms;
249  }
static _hasAgreements()
Check if there is any user agreement.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initForm()

ilCustomUserFieldsGUI::initForm ( string  $a_mode = 'create')
protected

Definition at line 251 of file class.ilCustomUserFieldsGUI.php.

References $id, XapiProxy\$plugin, ilMemberAgreement\_hasAgreements(), ilUDFPermissionHelper\ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper\ACTION_FIELD_EDIT_PROPERTY, ILIAS\Repository\ctrl(), getAccessOptions(), ilCustomUserFieldsHelper\getInstance(), initFieldDefinition(), ILIAS\Repository\lng(), null, ilFormPropertyGUI\setRequired(), ilUDFPermissionHelper\SUBACTION_FIELD_PROPERTIES, ilUDFPermissionHelper\SUBACTION_FIELD_TITLE, UDF_TYPE_SELECT, UDF_TYPE_TEXT, and UDF_TYPE_WYSIWYG.

Referenced by addField(), create(), edit(), and update().

252  {
253  $perms = [];
254  $se_mu = null;
255  $perm_map = [];
256  $udf_type = null;
257 
259  $this->lng->loadLanguageModule('ps');
260  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('ps_warning_modify'));
261  }
262 
263  if ($this->field_definition) {
264  $perms = $this->initFieldDefinition();
265  $perm_map = self::getAccessPermissions();
266  }
267 
268  $form = new ilPropertyFormGUI();
269  $form->setFormAction($this->ctrl->getFormAction($this));
270 
271  $name = new ilTextInputGUI($this->lng->txt('field_name'), 'name');
272  $name->setRequired(true);
273  $form->addItem($name);
274 
276  $name->setDisabled(true);
277  }
278 
279  // type
280  $radg = new ilRadioGroupInputGUI($this->lng->txt('field_type'), 'field_type');
281  $radg->setRequired(true);
282  foreach (ilCustomUserFieldsHelper::getInstance()->getUDFTypes() as $udf_type => $udf_name) {
283  $op = new ilRadioOption($udf_name, (string) $udf_type);
284  $radg->addOption($op);
285 
286  switch ($udf_type) {
287  case UDF_TYPE_TEXT:
288  case UDF_TYPE_WYSIWYG:
289  // do nothing
290  break;
291  case UDF_TYPE_SELECT:
292  // select values
293  $se_mu = new ilTextWizardInputGUI($this->lng->txt('value'), 'selvalue');
294  $se_mu->setRequired(true);
295  $se_mu->setSize(32);
296  $se_mu->setMaxLength(128);
297  $se_mu->setValues(['']);
298  $op->addSubItem($se_mu);
299  break;
300 
301  default:
302  $plugin = ilCustomUserFieldsHelper::getInstance()->getPluginForType($udf_type);
303  if ($plugin instanceof ilUDFDefinitionPlugin) {
304  $plugin->addDefinitionTypeOptionsToRadioOption($op, $this->field_id);
305  }
306  break;
307  }
308  }
309 
310  $form->addItem($radg);
311 
313  $se_mu->setDisabled(true);
314  $se_mu->setRequired(false);
315  }
316 
317 
318  // access
319  $acc = new ilCheckboxGroupInputGUI($this->lng->txt('access'), 'access');
320 
321  $acc_values = [];
322  foreach ($this->getAccessOptions() as $id => $caption) {
323  $opt = new ilCheckboxOption($caption, $id);
324  $acc->addOption($opt);
325 
326  if ($this->field_definition && $this->field_definition[$id]) {
327  $acc_values[] = $id;
328  }
329 
330  if ($perms && !$perms[ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS][$perm_map[$id]]) {
331  $opt->setDisabled(true);
332  }
333  }
334 
335  $form->addItem($acc);
336 
337 
338  if ($a_mode == 'create') {
339  $radg->setValue((string) UDF_TYPE_TEXT);
340  $form->setTitle($this->lng->txt('add_new_user_defined_field'));
341  $form->addCommandButton('create', $this->lng->txt('save'));
342  } else {
343  $name->setValue($this->field_definition['field_name']);
344  $radg->setValue((string) $this->field_definition['field_type']);
345  $radg->setDisabled(true);
346  $acc->setValue($acc_values);
347 
348  switch ($this->field_definition['field_type']) {
349  case UDF_TYPE_SELECT:
350  $values = $this->field_definition['field_values'];
351  if (!is_array($values) || $values === []) {
352  $values = [''];
353  }
354  $se_mu->setValue($values);
355  $form->setTitle($this->lng->txt('udf_update_select_field'));
356  break;
357 
358  case UDF_TYPE_TEXT:
359  $form->setTitle($this->lng->txt('udf_update_text_field'));
360  break;
361 
362  case UDF_TYPE_WYSIWYG:
363  $form->setTitle($this->lng->txt('udf_update_wysiwyg_field'));
364  break;
365 
366  default:
367  $plugin = ilCustomUserFieldsHelper::getInstance()->getPluginForType($udf_type);
368  if ($plugin instanceof ilUDFDefinitionPlugin) {
369  $form->setTitle($plugin->getDefinitionUpdateFormTitle());
370  }
371  break;
372  }
373  $form->addCommandButton('update', $this->lng->txt('save'));
374  }
375  $form->addCommandButton('listUserDefinedFields', $this->lng->txt('cancel'));
376  return $form;
377  }
const UDF_TYPE_SELECT
This class represents an option in a radio group.
This class represents an option in a checkbox group.
getAccessOptions()
Get all access options, order is kept in forms.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property in a property form.
static _hasAgreements()
Check if there is any user agreement.
setRequired(bool $a_required)
const UDF_TYPE_WYSIWYG
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This class represents a text wizard property in a property form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listUserDefinedFields()

ilCustomUserFieldsGUI::listUserDefinedFields ( )

Definition at line 102 of file class.ilCustomUserFieldsGUI.php.

References ilUDFPermissionHelper\ACTION_UDF_CREATE_FIELD, ilUDFPermissionHelper\CONTEXT_UDF, ILIAS\Repository\ctrl(), getPermissions(), ILIAS\Repository\lng(), and ILIAS\Repository\toolbar().

Referenced by askDeleteField(), and updateFields().

102  : void
103  {
104  if ($this->getPermissions()->hasPermission(
106  (string) $this->ref_id,
108  )) {
109  $this->toolbar->addComponent(
110  $this->ui_factory->link()->standard(
111  $this->lng->txt('add_user_defined_field'),
112  $this->ctrl->getLinkTarget($this, 'addField')
113  )
114  );
115  }
116 
117  $tab = new ilCustomUserFieldSettingsTableGUI($this, 'listUserDefinedFields', $this->getPermissions());
118  if ($this->confirm_change) {
119  $tab->setConfirmChange();
120  }
121  $this->main_tpl->setContent($tab->getHTML());
122  }
TableGUI class for custom defined user fields.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update()

ilCustomUserFieldsGUI::update ( )

Definition at line 491 of file class.ilCustomUserFieldsGUI.php.

References XapiProxy\$plugin, ilUserDefinedFields\_getInstance(), ilMemberAgreement\_reset(), ilUDFPermissionHelper\ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper\ACTION_FIELD_EDIT_PROPERTY, ilUDFPermissionHelper\CONTEXT_FIELD, ILIAS\Repository\ctrl(), ilUserDefinedData\deleteFieldValue(), edit(), ilCustomUserFieldsHelper\getInstance(), initForm(), ILIAS\Repository\lng(), null, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CERTIFICATE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_EXPORT, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_REQUIRED, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_SEARCHABLE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_COURSES, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PRG, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION, ilUDFPermissionHelper\SUBACTION_FIELD_PROPERTIES, ilUDFPermissionHelper\SUBACTION_FIELD_TITLE, UDF_TYPE_SELECT, and validateForm().

491  : void
492  {
493  $perms = [];
494 
495  $user_field_definitions = ilUserDefinedFields::_getInstance();
496  $user_field_definitions->setFieldType($this->field_definition['field_type']);
497 
498  // gather old select options
499  $old_options = null;
500  if ($this->field_id) {
501  $old_values = $user_field_definitions->getDefinition($this->field_id);
502  if ($old_values['field_type'] == UDF_TYPE_SELECT) {
503  $old_options = $old_values['field_values'];
504  }
505 
506  $perms = $this->permissions->hasPermissions(
508  (string) $this->field_id,
509  [
510  [
513  ],
514  [
517  ],
518  [
521  ],
522  [
525  ],
526  [
529  ],
530  [
533  ],
534  [
537  ],
538  [
541  ],
542  [
545  ],
546  [
549  ],
550  [
553  ],
554  [
557  ],
558  [
561  ],
562  [
565  ]
566  ]
567  );
568  }
569 
570  $access = [];
571  $form = $this->initForm('edit');
572  if ($this->validateForm($form, $user_field_definitions, $access, $perms) && $this->field_id) {
573  // field values are set in validateForm()...
574 
576  // diff old select options against new to handle deleted values properly
577  if (is_array($old_options)) {
578  foreach ($old_options as $old_option) {
579  if (!in_array($old_option, $user_field_definitions->getFieldValues())) {
580  ilUserDefinedData::deleteFieldValue($this->field_id, $old_option);
581  }
582  }
583  }
584  }
585  // disabled fields
586  elseif (is_array($old_options)) {
587  $user_field_definitions->setFieldValues($old_options);
588  }
589 
591  $user_field_definitions->setFieldName($form->getInput('name'));
592  } else {
593  $user_field_definitions->setFieldName($this->field_definition['field_name']);
594  }
595 
596  $user_field_definitions->enableVisible($access['visible']);
597  $user_field_definitions->enableVisibleRegistration($access['visib_reg']);
598  $user_field_definitions->enableVisibleLocalUserAdministration($access['visib_lua']);
599  $user_field_definitions->enableCourseExport($access['course_export']);
600  $user_field_definitions->enableGroupExport($access['group_export']);
601  $user_field_definitions->enablePrgExport($access['prg_export']);
602  $user_field_definitions->enableChangeable($access['changeable']);
603  $user_field_definitions->enableChangeableLocalUserAdministration($access['changeable_lua']);
604  $user_field_definitions->enableRequired($access['required']);
605  $user_field_definitions->enableExport($access['export']);
606  $user_field_definitions->enableSearchable($access['searchable']);
607  $user_field_definitions->enableCertificate($access['certificate']);
608  $user_field_definitions->update($this->field_id);
609 
610  if ($user_field_definitions->isPluginType()) {
611  $plugin = ilCustomUserFieldsHelper::getInstance()->getPluginForType($user_field_definitions->getFieldType());
612  if ($plugin instanceof ilUDFDefinitionPlugin) {
613  $plugin->updateDefinitionFromForm($form, $this->field_id);
614  }
615  }
616 
617  if ($access['course_export']) {
619  }
620 
621  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
622  $this->ctrl->redirect($this);
623  }
624 
625  $form->setValuesByPost();
626  $this->edit($form);
627  }
const UDF_TYPE_SELECT
validateForm(ilPropertyFormGUI $form, ilUserDefinedFields $user_field_definitions, array &$access, ?array $a_field_permissions=null)
edit(?ilPropertyFormGUI $a_form=null)
static _reset()
Reset all.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static deleteFieldValue(int $a_field_id, string $a_value)
Delete data of particular value of a (selection) field.
initForm(string $a_mode='create')
+ Here is the call graph for this function:

◆ updateFields()

ilCustomUserFieldsGUI::updateFields ( string  $action = '')

Update custom fields properties (from table gui)

Definition at line 688 of file class.ilCustomUserFieldsGUI.php.

References $field_id, $valid, ilUserDefinedFields\_getInstance(), ilUDFPermissionHelper\ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper\CONTEXT_FIELD, ILIAS\Repository\ctrl(), listUserDefinedFields(), ILIAS\Repository\lng(), ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CERTIFICATE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_EXPORT, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_REQUIRED, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_SEARCHABLE, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_COURSES, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL, ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_PRG, and ilUDFPermissionHelper\SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION.

688  : void
689  {
690  $user_field_definitions = ilUserDefinedFields::_getInstance();
691  $a_fields = $user_field_definitions->getDefinitions();
692 
693  $checked = $this->request->getChecked();
694 
695  $perm_map = self::getAccessPermissions();
696 
697  foreach ($a_fields as $field_id => $definition) {
698  $perms = $this->permissions->hasPermissions(
700  (string) $field_id,
701  [
702  [
705  ],
706  [
709  ],
710  [
713  ],
714  [
717  ],
718  [
721  ],
722  [
725  ],
726  [
729  ],
730  [
733  ],
734  [
737  ],
738  [
741  ],
742  [
745  ],
746  [
749  ]
750  ]
751  );
752 
753  // disabled field
754  foreach ($perm_map as $prop => $perm) {
756  $checked[$prop . '_' . $field_id] = $definition[$prop];
757  }
758  }
759  }
760 
761  $valid = true;
762  foreach ($a_fields as $field_id => $definition) {
763  if (isset($checked['required_' . $field_id]) && (int) $checked['required_' . $field_id] &&
764  (!isset($checked['visib_reg_' . $field_id]) || !(int) $checked['visib_reg_' . $field_id])) {
765  $this->confirm_change = true;
766 
767  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('invalid_visible_required_options_selected'));
768  $valid = false;
769  }
770  }
771 
772  if (!$valid) {
773  $this->listUserDefinedFields();
774  return;
775  }
776 
777  foreach ($a_fields as $field_id => $definition) {
778  $user_field_definitions->setFieldName($definition['field_name']);
779  $user_field_definitions->setFieldType($definition['field_type']);
780  $user_field_definitions->setFieldValues($definition['field_values']);
781  $user_field_definitions->enableVisible((bool) ($checked['visible_' . $field_id] ?? false));
782  $user_field_definitions->enableChangeable((bool) ($checked['changeable_' . $field_id] ?? false));
783  $user_field_definitions->enableRequired((bool) ($checked['required_' . $field_id] ?? false));
784  $user_field_definitions->enableSearchable((bool) ($checked['searchable_' . $field_id] ?? false));
785  $user_field_definitions->enableExport((bool) ($checked['export_' . $field_id] ?? false));
786  $user_field_definitions->enableCourseExport((bool) ($checked['course_export_' . $field_id] ?? false));
787  $user_field_definitions->enableVisibleLocalUserAdministration((bool) ($checked['visib_lua_' . $field_id] ?? false));
788  $user_field_definitions->enableChangeableLocalUserAdministration((bool) ($checked['changeable_lua_' . $field_id] ?? false));
789  $user_field_definitions->enableGroupExport((bool) ($checked['group_export_' . $field_id] ?? false));
790  $user_field_definitions->enableVisibleRegistration((bool) ($checked['visib_reg_' . $field_id] ?? false));
791  $user_field_definitions->enableCertificate((bool) ($checked['certificate_' . $field_id] ?? false));
792  $user_field_definitions->enablePrgExport((bool) ($checked['prg_export_' . $field_id] ?? false));
793 
794  $user_field_definitions->update($field_id);
795  }
796 
797  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
798  $this->ctrl->redirect($this);
799  }
$valid
+ Here is the call graph for this function:

◆ validateForm()

ilCustomUserFieldsGUI::validateForm ( ilPropertyFormGUI  $form,
ilUserDefinedFields  $user_field_definitions,
array &  $access,
?array  $a_field_permissions = null 
)
protected

Definition at line 379 of file class.ilCustomUserFieldsGUI.php.

References $id, $valid, ilUDFPermissionHelper\ACTION_FIELD_EDIT_ACCESS, ilUDFPermissionHelper\ACTION_FIELD_EDIT_PROPERTY, ilPropertyFormGUI\checkInput(), getAccessOptions(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ILIAS\Repository\lng(), ilUserDefinedFields\nameExists(), ilUserDefinedFields\setFieldValues(), ilUDFPermissionHelper\SUBACTION_FIELD_PROPERTIES, UDF_DUPLICATE_VALUES, UDF_TYPE_SELECT, and ilUserDefinedFields\validateValues().

Referenced by create(), and update().

384  : bool {
385  $perm_map = [];
386 
387  if ($form->checkInput()) {
388  $valid = true;
389 
390  $incoming = (array) $form->getInput('access');
391 
392  if ($a_field_permissions) {
393  $perm_map = self::getAccessPermissions();
394  }
395 
396  $access = [];
397  foreach (array_keys($this->getAccessOptions()) as $id) {
398  $access[$id] = in_array($id, $incoming);
399 
400  // disabled fields
401  if ($a_field_permissions && !$a_field_permissions[ilUDFPermissionHelper::ACTION_FIELD_EDIT_ACCESS][$perm_map[$id]]) {
402  $access[$id] = $this->field_definition[$id];
403  }
404  }
405 
406  if ($access['required'] && !$access['visib_reg']) {
407  $this->confirm_change = true;
408  $form->getItemByPostVar('access')->setAlert($this->lng->txt('udf_required_requires_visib_reg'));
409  $valid = false;
410  }
411 
412  if (!$this->field_id && $user_field_definitions->nameExists($form->getInput('name'))) {
413  $form->getItemByPostVar('name')->setAlert($this->lng->txt('udf_name_already_exists'));
414  $valid = false;
415  }
416 
417  if ($form->getInput('field_type') == UDF_TYPE_SELECT &&
419  $user_field_definitions->setFieldValues($form->getInput('selvalue'));
420  if ($error = $user_field_definitions->validateValues()) {
421  switch ($error) {
423  $form->getItemByPostVar('selvalue')->setAlert($this->lng->txt('udf_duplicate_entries'));
424  $valid = false;
425  break;
426  }
427  }
428  }
429 
430  if (!$valid) {
431  $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
432  }
433  return $valid;
434  }
435 
436  return false;
437  }
const UDF_TYPE_SELECT
getItemByPostVar(string $a_post_var)
$valid
getAccessOptions()
Get all access options, order is kept in forms.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
nameExists(string $a_field_name)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const UDF_DUPLICATE_VALUES
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $confirm_change

bool ilCustomUserFieldsGUI::$confirm_change = false
private

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

◆ $ctrl

ilCtrlInterface ilCustomUserFieldsGUI::$ctrl
private

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

◆ $field_definition

array ilCustomUserFieldsGUI::$field_definition = []
private

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

◆ $field_id

int ilCustomUserFieldsGUI::$field_id = 0
private

Definition at line 41 of file class.ilCustomUserFieldsGUI.php.

Referenced by updateFields().

◆ $lng

Language ilCustomUserFieldsGUI::$lng
private

Definition at line 34 of file class.ilCustomUserFieldsGUI.php.

◆ $main_tpl

ilGlobalTemplateInterface ilCustomUserFieldsGUI::$main_tpl
private

Definition at line 36 of file class.ilCustomUserFieldsGUI.php.

◆ $permissions

ilClaimingPermissionHelper ilCustomUserFieldsGUI::$permissions
private

Definition at line 46 of file class.ilCustomUserFieldsGUI.php.

Referenced by getPermissions().

◆ $ref_id

int ilCustomUserFieldsGUI::$ref_id = 0
private

Definition at line 39 of file class.ilCustomUserFieldsGUI.php.

Referenced by __construct().

◆ $request

UserGUIRequest ilCustomUserFieldsGUI::$request
private

Definition at line 32 of file class.ilCustomUserFieldsGUI.php.

◆ $toolbar

ilToolbarGUI ilCustomUserFieldsGUI::$toolbar
private

Definition at line 37 of file class.ilCustomUserFieldsGUI.php.

◆ $ui_factory

UIFactory ilCustomUserFieldsGUI::$ui_factory
private

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


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