19 declare(strict_types=1);
50 int $requested_field_id
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'];
59 $this->
lng->loadLanguageModule(
'user');
60 $this->
lng->loadLanguageModule(
'administration');
64 $this->field_id = $requested_field_id;
65 $this->
ctrl->saveParameter($this,
'field_id', $this->field_id);
67 if ($this->field_id) {
69 $this->field_definition = $user_field_definitions->getDefinition($this->field_id);
73 $DIC->user()->getId(),
89 $next_class = $this->
ctrl->getNextClass($this);
90 $cmd = $this->
ctrl->getCmd();
92 switch ($next_class) {
95 $cmd =
'listUserDefinedFields';
106 (
string) $this->ref_id,
110 $this->ui_factory->link()->standard(
111 $this->
lng->txt(
'add_user_defined_field'),
112 $this->
ctrl->getLinkTarget($this,
'addField')
118 if ($this->confirm_change) {
119 $tab->setConfirmChange();
121 $this->main_tpl->setContent($tab->getHTML());
127 $a_form = $this->
initForm(
'create');
130 $this->main_tpl->setContent($a_form->getHTML());
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');
179 $this->
lng->loadLanguageModule(
'ps');
180 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'ps_warning_modify'));
184 if ($this->field_definition) {
185 $perms = $this->permissions->hasPermissions(
187 (
string) $this->field_definition[
'field_id'],
259 $this->
lng->loadLanguageModule(
'ps');
260 $this->main_tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'ps_warning_modify'));
263 if ($this->field_definition) {
265 $perm_map = self::getAccessPermissions();
269 $form->setFormAction($this->
ctrl->getFormAction($this));
272 $name->setRequired(
true);
273 $form->addItem($name);
276 $name->setDisabled(
true);
284 $radg->addOption($op);
296 $se_mu->setMaxLength(128);
297 $se_mu->setValues([
'']);
298 $op->addSubItem($se_mu);
304 $plugin->addDefinitionTypeOptionsToRadioOption($op, $this->field_id);
310 $form->addItem($radg);
313 $se_mu->setDisabled(
true);
314 $se_mu->setRequired(
false);
324 $acc->addOption($opt);
326 if ($this->field_definition && $this->field_definition[$id]) {
331 $opt->setDisabled(
true);
335 $form->addItem($acc);
338 if ($a_mode ==
'create') {
340 $form->setTitle($this->
lng->txt(
'add_new_user_defined_field'));
341 $form->addCommandButton(
'create', $this->
lng->txt(
'save'));
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);
348 switch ($this->field_definition[
'field_type']) {
350 $values = $this->field_definition[
'field_values'];
351 if (!is_array($values) || $values === []) {
354 $se_mu->setValue($values);
355 $form->setTitle($this->
lng->txt(
'udf_update_select_field'));
359 $form->setTitle($this->
lng->txt(
'udf_update_text_field'));
363 $form->setTitle($this->
lng->txt(
'udf_update_wysiwyg_field'));
369 $form->setTitle(
$plugin->getDefinitionUpdateFormTitle());
373 $form->addCommandButton(
'update', $this->
lng->txt(
'save'));
375 $form->addCommandButton(
'listUserDefinedFields', $this->
lng->txt(
'cancel'));
383 ?array $a_field_permissions =
null 390 $incoming = (array) $form->
getInput(
'access');
392 if ($a_field_permissions) {
393 $perm_map = self::getAccessPermissions();
398 $access[
$id] = in_array($id, $incoming);
402 $access[
$id] = $this->field_definition[
$id];
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'));
412 if (!$this->field_id && $user_field_definitions->
nameExists($form->
getInput(
'name'))) {
431 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
442 $user_field_definitions->setFieldType(
443 $this->request->getFieldType()
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();
464 if ($user_field_definitions->isPluginType()) {
467 $plugin->updateDefinitionFromForm($form, $new_id);
470 if ($access[
'course_export']) {
474 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'udf_added_field'),
true);
475 $this->
ctrl->redirect($this);
478 $form->setValuesByPost();
488 $this->main_tpl->setContent($a_form->getHTML());
496 $user_field_definitions->setFieldType($this->field_definition[
'field_type']);
500 if ($this->field_id) {
501 $old_values = $user_field_definitions->getDefinition($this->field_id);
503 $old_options = $old_values[
'field_values'];
506 $perms = $this->permissions->hasPermissions(
508 (
string) $this->field_id,
572 if ($this->
validateForm($form, $user_field_definitions, $access, $perms) && $this->field_id) {
577 if (is_array($old_options)) {
578 foreach ($old_options as $old_option) {
579 if (!in_array($old_option, $user_field_definitions->getFieldValues())) {
586 elseif (is_array($old_options)) {
587 $user_field_definitions->setFieldValues($old_options);
591 $user_field_definitions->setFieldName($form->getInput(
'name'));
593 $user_field_definitions->setFieldName($this->field_definition[
'field_name']);
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);
610 if ($user_field_definitions->isPluginType()) {
613 $plugin->updateDefinitionFromForm($form, $this->field_id);
617 if ($access[
'course_export']) {
621 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'settings_saved'),
true);
622 $this->
ctrl->redirect($this);
625 $form->setValuesByPost();
631 $fields = $this->request->getFields();
632 if (count($fields) == 0) {
633 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'select_one'));
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');
645 foreach ($fields as
$id) {
646 $definition = $user_field_definitions->getDefinition($id);
647 $confirmation_gui->addItem(
'fields[]', (
string) $id, $definition[
'field_name']);
650 $this->main_tpl->setContent($confirmation_gui->getHTML());
658 $fields = $this->request->getFields();
662 foreach ($fields as
$id) {
668 $field = $user_field_definitions->getDefinition($id);
669 $fail[] = $field[
'field_name'];
673 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'msg_no_perm_delete') .
' ' . implode(
', ', $fail),
true);
674 $this->
ctrl->redirect($this,
'listUserDefinedFields');
677 foreach ($fields as $id) {
678 $user_field_definitions->delete($id);
681 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'udf_field_deleted'),
true);
682 $this->
ctrl->redirect($this);
691 $a_fields = $user_field_definitions->getDefinitions();
693 $checked = $this->request->getChecked();
695 $perm_map = self::getAccessPermissions();
697 foreach ($a_fields as $field_id => $definition) {
698 $perms = $this->permissions->hasPermissions(
754 foreach ($perm_map as $prop => $perm) {
756 $checked[$prop .
'_' .
$field_id] = $definition[$prop];
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;
767 $this->main_tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'invalid_visible_required_options_selected'));
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));
794 $user_field_definitions->update($field_id);
797 $this->main_tpl->setOnScreenMessage(
'success', $this->
lng->txt(
'settings_saved'),
true);
798 $this->
ctrl->redirect($this);
This class represents an option in a radio group.
const SUBACTION_FIELD_ACCESS_VISIBLE_GROUPS
const SUBACTION_FIELD_ACCESS_SEARCHABLE
validateForm(ilPropertyFormGUI $form, ilUserDefinedFields $user_field_definitions, array &$access, ?array $a_field_permissions=null)
This class represents an option in a checkbox group.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
edit(?ilPropertyFormGUI $a_form=null)
Additional user data fields definition.
ilGlobalTemplateInterface $main_tpl
ilClaimingPermissionHelper $permissions
addField(?ilPropertyFormGUI $a_form=null)
const SUBACTION_FIELD_ACCESS_VISIBLE_COURSES
const ACTION_FIELD_DELETE
const SUBACTION_FIELD_ACCESS_EXPORT
static _reset()
Reset all.
getAccessOptions()
Get all access options, order is kept in forms.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
const SUBACTION_FIELD_ACCESS_CERTIFICATE
const SUBACTION_FIELD_ACCESS_CHANGEABLE_PERSONAL
Class ilCustomUserFieldsGUI.
const SUBACTION_FIELD_ACCESS_REQUIRED
const ACTION_FIELD_EDIT_ACCESS
TableGUI class for custom defined user fields.
const ACTION_FIELD_EDIT_PROPERTY
const SUBACTION_FIELD_ACCESS_VISIBLE_PERSONAL
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SUBACTION_FIELD_PROPERTIES
nameExists(string $a_field_name)
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAccessPermissions()
__construct(int $ref_id, int $requested_field_id)
static _hasAgreements()
Check if there is any user agreement.
static deleteFieldValue(int $a_field_id, string $a_value)
Delete data of particular value of a (selection) field.
const SUBACTION_FIELD_TITLE
initForm(string $a_mode='create')
const SUBACTION_FIELD_ACCESS_VISIBLE_LOCAL
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
const ACTION_UDF_CREATE_FIELD
static getInstance(int $a_user_id, int $a_ref_id)
const SUBACTION_FIELD_ACCESS_VISIBLE_REGISTRATION
This class represents a text wizard property in a property form.
const UDF_DUPLICATE_VALUES
const SUBACTION_FIELD_ACCESS_VISIBLE_PRG
const SUBACTION_FIELD_ACCESS_CHANGEABLE_LOCAL
setFieldValues(array $a_values)
updateFields(string $action='')
Update custom fields properties (from table gui)