ILIAS  release_8 Revision v8.24
ilUserProfile Class Reference

Class ilUserProfile. More...

+ Collaboration diagram for ilUserProfile:

Public Member Functions

 __construct ()
 
 getStandardFields ()
 Get standard user fields array. More...
 
 getLocalUserAdministrationFields ()
 Get visible fields in local user administration. More...
 
 skipGroup (string $a_group)
 Skip a group. More...
 
 skipField (string $a_field)
 Skip a field. More...
 
 addStandardFieldsToForm (ilPropertyFormGUI $a_form, ?ilObjUser $a_user=null, array $custom_fields=null)
 Add standard fields to form. More...
 
 setAjaxCallback (string $a_href)
 

Static Public Member Functions

static userSettingVisible (string $a_setting)
 Checks whether user setting is visible. More...
 
static setMode (int $mode)
 
static isProfileIncomplete (ilObjUser $a_user, bool $a_include_udf=true, bool $a_personal_data_only=true)
 Check if all required personal data fields are set. More...
 
static getIgnorableRequiredSettings ()
 Returns an array of all ignorable profiel fields. More...
 

Data Fields

const MODE_DESKTOP = 1
 
const MODE_REGISTRATION = 2
 

Static Protected Member Functions

static isEditableByUser (string $setting)
 Returns whether a profile setting is editable by an user in the profile gui. More...
 

Protected Attributes

string $ajax_href
 
array $skip_fields
 
array $skip_groups
 
ilUserSettingsConfig $user_settings_config
 

Static Private Attributes

static int $mode = self::MODE_DESKTOP
 
static array $user_field
 

Detailed Description

Class ilUserProfile.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

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

Constructor & Destructor Documentation

◆ __construct()

ilUserProfile::__construct ( )

Definition at line 402 of file class.ilUserProfile.php.

403 {
404 global $DIC;
405
406 $lng = $DIC->language();
407
408 $this->skip_groups = array();
409 $this->skip_fields = array();
410
411 // for hide me from awareness tool text
412 // not nicest workaround, but better than using common block
413 $lng->loadLanguageModule("awrn");
414 $lng->loadLanguageModule("buddysystem");
415
416 $this->user_settings_config = new ilUserSettingsConfig();
417 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$lng

References $DIC, and $lng.

Member Function Documentation

◆ addStandardFieldsToForm()

ilUserProfile::addStandardFieldsToForm ( ilPropertyFormGUI  $a_form,
?ilObjUser  $a_user = null,
array  $custom_fields = null 
)

Add standard fields to form.

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

480 : void {
481 global $DIC;
482
483 $ilSetting = $DIC['ilSetting'];
484 $lng = $DIC['lng'];
485 $rbacreview = $DIC['rbacreview'];
486
487 $registration_settings = null;
488
489 // custom registration settings
490 if (self::$mode == self::MODE_REGISTRATION) {
491 $registration_settings = new ilRegistrationSettings();
492
493 self::$user_field["username"]["group"] = "login_data";
494 self::$user_field["password"]["group"] = "login_data";
495 self::$user_field["language"]["default"] = $lng->lang_key;
496
497 // different position for role
498 $roles = self::$user_field["roles"];
499 unset(self::$user_field["roles"]);
500 self::$user_field["roles"] = $roles;
501 self::$user_field["roles"]["group"] = "settings";
502 }
503
504 $fields = $this->getStandardFields();
505 $current_group = "";
506 $custom_fields_done = false;
507 foreach ($fields as $f => $p) {
508 // next group? -> diplay subheader
509 if (($p["group"] != $current_group) &&
510 self::userSettingVisible($f)) {
511 if (is_array($custom_fields) && $custom_fields !== [] && !$custom_fields_done) {
512 // should be appended to "other" or at least before "settings"
513 if ($current_group == "other" || $p["group"] == "settings") {
514 // add "other" subheader
515 if ($current_group != "other") {
516 $sh = new ilFormSectionHeaderGUI();
517 $sh->setTitle($lng->txt("other"));
518 $a_form->addItem($sh);
519 }
520 foreach ($custom_fields as $custom_field) {
521 $a_form->addItem($custom_field);
522 }
523 $custom_fields_done = true;
524 }
525 }
526
527 $sh = new ilFormSectionHeaderGUI();
528 $sh->setTitle($lng->txt($p["group"]));
529 $a_form->addItem($sh);
530 $current_group = $p["group"];
531 }
532
533 $m = $p["method"] ?? "";
534
535 $lv = (isset($p["lang_var"]) && $p["lang_var"] != "")
536 ? $p["lang_var"]
537 : $f;
538
539 switch ($p["input"]) {
540 case "login":
541 if ((int) $ilSetting->get('allow_change_loginname') || self::$mode == self::MODE_REGISTRATION) {
542 $val = new ilTextInputGUI($lng->txt('username'), 'username');
543 if ($a_user) {
544 $val->setValue($a_user->getLogin());
545 }
546 $val->setMaxLength((int) $p['maxlength']);
547 $val->setSize(255);
548 $val->setRequired(true);
549 } else {
550 // user account name
551 $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un');
552 if ($a_user) {
553 $val->setValue($a_user->getLogin());
554 }
555 }
556 $a_form->addItem($val);
557 break;
558
559 case "text":
560 if (self::userSettingVisible($f)) {
561 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
562 $value = '';
563 if ($a_user) {
564 $value = $a_user->$m() ?? '';
565 }
566 $ti->setValue($value);
567 $ti->setMaxLength($p["maxlength"]);
568 $ti->setSize($p["size"]);
569 $ti->setRequired((bool) $ilSetting->get("require_" . $f));
570 if (!$ti->getRequired() || $ti->getValue()) {
571 $ti->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
572 }
573 $a_form->addItem($ti);
574 }
575 break;
576
577 case "sel_country":
578 if (self::userSettingVisible($f)) {
579 $ci = new ilCountrySelectInputGUI($lng->txt($lv), "usr_" . $f);
580 if ($a_user) {
581 $ci->setValue($a_user->$m());
582 }
583 $ci->setRequired((bool) $ilSetting->get("require_" . $f));
584 if (!$ci->getRequired() || $ci->getValue()) {
585 $ci->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
586 }
587 $a_form->addItem($ci);
588 }
589 break;
590
591 case "birthday":
592 if (self::userSettingVisible($f)) {
593 $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_" . $f);
594 $date = null;
595 if ($a_user && strlen($a_user->$m())) {
596 $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
597 $bi->setDate($date);
598 }
599 $bi->setRequired((bool) $ilSetting->get("require_" . $f));
600 if (!$bi->getRequired() || $date) {
601 $bi->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
602 }
603 $a_form->addItem($bi);
604 }
605 break;
606
607 case "radio":
608 if (self::userSettingVisible($f)) {
609 $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_" . $f);
610 if ($a_user) {
611 $rg->setValue($a_user->$m());
612 }
613 foreach ($p["values"] as $k => $v) {
614 $op = new ilRadioOption($lng->txt($v), $k);
615 $rg->addOption($op);
616 }
617 $rg->setRequired((bool) $ilSetting->get("require_" . $f));
618 if (!$rg->getRequired() || $rg->getValue()) {
619 $rg->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
620 }
621 $a_form->addItem($rg);
622 }
623 break;
624
625 case "picture":
626 if (self::userSettingVisible("upload") && $a_user) {
627 $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
628 $ii->setAllowCapture(true);
629 $ii->setDisabled((bool) $ilSetting->get("usr_settings_disable_upload"));
630
631 $upload = $a_form->getFileUpload("userfile");
632 if ($upload["name"] ?? false) {
633 $ii->setPending($upload["name"]);
634 } else {
636 $a_user->getId(),
637 "small",
638 true,
639 true
640 );
641 if ($im != "") {
642 $ii->setImage($im);
643 $ii->setAlt($lng->txt("personal_picture"));
644 }
645 }
646
647 $a_form->addItem($ii);
648 }
649 break;
650
651 case "roles":
652 $role_names = "";
653 if (self::$mode == self::MODE_DESKTOP) {
654 if (self::userSettingVisible("roles")) {
655 $global_roles = $rbacreview->getGlobalRoles();
656 foreach ($global_roles as $role_id) {
657 if (in_array($role_id, $rbacreview->assignedRoles($a_user->getId()))) {
658 $roleObj = ilObjectFactory::getInstanceByObjId($role_id);
659 $role_names .= $roleObj->getTitle() . ", ";
660 unset($roleObj);
661 }
662 }
663 $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
664 $dr->setValue(substr($role_names, 0, -2));
665 $a_form->addItem($dr);
666 }
667 } elseif (self::$mode == self::MODE_REGISTRATION) {
668 if ($registration_settings->roleSelectionEnabled()) {
669 $options = array();
670 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
671 $options[$role["id"]] = $role["title"];
672 }
673 // registration form validation will take care of missing field / value
674 if ($options) {
675 if (count($options) > 1) {
676 $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_" . $f);
677 $ta->setOptions($options);
678 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
679 if (!$ta->getRequired()) {
680 $ta->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
681 }
682 }
683 // no need for select if only 1 option
684 else {
685 $ta = new ilHiddenInputGUI("usr_" . $f);
686 $keys = array_keys($options);
687 $ta->setValue(array_shift($keys));
688 }
689 $a_form->addItem($ta);
690 }
691 }
692 }
693 break;
694
695 case "second_email":
696 case "email":
697 if (self::userSettingVisible($f)) {
698 $em = new ilEMailInputGUI($lng->txt($lv), "usr_" . $f);
699 if ($a_user) {
700 $em->setValue($a_user->$m());
701 }
702 $em->setRequired((bool) $ilSetting->get("require_" . $f));
703 if (!$em->getRequired() || $em->getValue()) {
704 $em->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
705 }
706 if (self::MODE_REGISTRATION == self::$mode) {
707 $em->setRetype(true);
708 }
709 $em->setMaxLength((int) $p['maxlength']);
710 $a_form->addItem($em);
711 }
712 break;
713 case "textarea":
714 if (self::userSettingVisible($f)) {
715 $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_" . $f);
716 if ($a_user) {
717 $ta->setValue($a_user->$m() ?? '');
718 }
719 $ta->setRows($p["rows"]);
720 $ta->setCols($p["cols"]);
721 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
722 if (!$ta->getRequired() || $ta->getValue()) {
723 $ta->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
724 }
725 $a_form->addItem($ta);
726 }
727 break;
728
729 case "password":
730 if (self::$mode == self::MODE_REGISTRATION) {
731 if (!$registration_settings->passwordGenerationEnabled()) {
732 $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_" . $f);
733 $ta->setUseStripSlashes(false);
734 $ta->setRequired(true);
736 // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
737 } else {
738 $ta = new ilNonEditableValueGUI($lng->txt($lv));
739 $ta->setValue($lng->txt("reg_passwd_via_mail"));
740 }
741 $a_form->addItem($ta);
742 }
743 break;
744
745 case "language":
746 if (self::userSettingVisible($f)) {
747 $ta = new ilSelectInputGUI($lng->txt($lv), "usr_" . $f);
748 if ($a_user) {
749 $ta->setValue($a_user->$m());
750 }
751 $options = array();
752 $lng->loadLanguageModule("meta");
753 foreach ($lng->getInstalledLanguages() as $lang_key) {
754 $options[$lang_key] = $lng->txt("meta_l_" . $lang_key);
755 }
756 asort($options); // #9728
757 $ta->setOptions($options);
758 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
759 if (!$ta->getRequired() || $ta->getValue()) {
760 $ta->setDisabled(
761 $ilSetting->get("usr_settings_disable_" . $f) === '1'
762 || count($options) <= 1
763 );
764 }
765 $a_form->addItem($ta);
766 }
767 break;
768
769 case "multitext":
770 if (self::userSettingVisible($f)) {
771 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
772 $ti->setMulti(true);
773 if ($a_user) {
774 $ti->setValue($a_user->$m());
775 }
776 $ti->setMaxLength($p["maxlength"]);
777 $ti->setSize($p["size"]);
778 $ti->setRequired((bool) $ilSetting->get("require_" . $f));
779 if (!$ti->getRequired() || $ti->getValue()) {
780 $ti->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
781 }
782 if ($this->ajax_href) {
783 // add field to ajax call
784 $ti->setDataSource($this->ajax_href . "&f=" . $f);
785 }
786 $a_form->addItem($ti);
787 }
788 break;
789 case "noneditable":
790 if (self::$mode == self::MODE_DESKTOP && self::userSettingVisible($f)) {
791 $ne = new ilNonEditableValueGUI($lng->txt($lv));
792 $ne->setValue($a_user->$m());
793 $a_form->addItem($ne);
794 }
795 break;
796 }
797 }
798
799 // append custom fields as "other"
800 if (is_array($custom_fields) && $custom_fields !== [] && !$custom_fields_done) {
801 // add "other" subheader
802 if ($current_group != "other") {
803 $sh = new ilFormSectionHeaderGUI();
804 $sh->setTitle($lng->txt("other"));
805 $a_form->addItem($sh);
806 }
807 foreach ($custom_fields as $custom_field) {
808 $a_form->addItem($custom_field);
809 }
810 }
811 }
const IL_CAL_DATE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupRegisterAllowed()
get all roles that are activated in user registration
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFileUpload(string $a_field, ?string $a_index=null, ?string $a_sub_index=null)
Get file upload data.
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...
Class ilObjAuthSettingsGUI.
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
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.
getStandardFields()
Get standard user fields array.
$keys
Definition: metadata.php:204
global $ilSetting
Definition: privfeed.php:17

References $lng.

◆ getIgnorableRequiredSettings()

static ilUserProfile::getIgnorableRequiredSettings ( )
static

Returns an array of all ignorable profiel fields.

Definition at line 916 of file class.ilUserProfile.php.

916 : array // Missing array type.
917 {
918 global $DIC;
919
920 $ilSetting = $DIC->settings();
921
922 $ignorableSettings = array();
923
924 foreach (self::$user_field as $field => $definition) {
925 // !!!username and password must not be ignored!!!
926 if ('username' == $field ||
927 'password' == $field) {
928 continue;
929 }
930
931 // Field is not required -> continue
932 if (!$ilSetting->get('require_' . $field)) {
933 continue;
934 }
935
936 if (self::isEditableByUser($field)) {
937 $ignorableSettings[] = $field;
938 }
939 }
940
941 return $ignorableSettings;
942 }

References $DIC, and $ilSetting.

Referenced by ilObjUserGUI\handleIgnoredRequiredFields().

+ Here is the caller graph for this function:

◆ getLocalUserAdministrationFields()

ilUserProfile::getLocalUserAdministrationFields ( )

Get visible fields in local user administration.

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

439 : array // Missing array type.
440 {
441 global $DIC;
442
443 $ilSetting = $DIC->settings();
444
445 $fields = array();
446 foreach ($this->getStandardFields() as $field => $info) {
447 if ($ilSetting->get('usr_settings_visib_lua_' . $field, '1')) {
448 $fields[$field] = $info;
449 } elseif ($info['visib_lua_fix_value'] ?? false) {
450 $fields[$field] = $info;
451 }
452 }
453 return $fields;
454 }

References $DIC, $ilSetting, and getStandardFields().

+ Here is the call graph for this function:

◆ getStandardFields()

ilUserProfile::getStandardFields ( )

Get standard user fields array.

Definition at line 422 of file class.ilUserProfile.php.

422 : array // Missing array type.
423 {
424 $fields = array();
425 foreach (self::$user_field as $f => $p) {
426 // skip hidden groups
427 if (in_array($p["group"], $this->skip_groups) ||
428 in_array($f, $this->skip_fields)) {
429 continue;
430 }
431 $fields[$f] = $p;
432 }
433 return $fields;
434 }

References Vendor\Package\$f.

Referenced by getLocalUserAdministrationFields().

+ Here is the caller graph for this function:

◆ isEditableByUser()

static ilUserProfile::isEditableByUser ( string  $setting)
staticprotected

Returns whether a profile setting is editable by an user in the profile gui.

Definition at line 907 of file class.ilUserProfile.php.

907 : bool
908 {
911 }
ilUserSettingsConfig $user_settings_config
isVisibleAndChangeable(string $field)
Is field visible and changeable by user?

References ilUserSettingsConfig\isVisibleAndChangeable().

+ Here is the call graph for this function:

◆ isProfileIncomplete()

static ilUserProfile::isProfileIncomplete ( ilObjUser  $a_user,
bool  $a_include_udf = true,
bool  $a_personal_data_only = true 
)
static

Check if all required personal data fields are set.

Parameters
ilObjUser$a_user
bool$a_include_udfcheck custom fields, too
bool$a_personal_data_onlyonly check fields which are visible in personal data
Returns
bool

Definition at line 857 of file class.ilUserProfile.php.

861 : bool {
862 global $DIC;
863
864 $ilSetting = $DIC['ilSetting'];
865
867
868 // standard fields
869 foreach (self::$user_field as $field => $definition) {
870 // only if visible in personal data
871 if ($a_personal_data_only && !$user_settings_config->isVisible($field)) {
872 continue;
873 }
874
875 if ($ilSetting->get("require_" . $field) && $definition["method"]) {
876 $value = $a_user->{$definition["method"]}();
877 if ($value == "") {
878 return true;
879 }
880 }
881 }
882
883 // custom fields
884 if ($a_include_udf) {
885 $user_defined_data = $a_user->getUserDefinedData();
886
887 $user_defined_fields = ilUserDefinedFields::_getInstance();
888 foreach ($user_defined_fields->getRequiredDefinitions() as $field => $definition) {
889 // only if visible in personal data
890 if ($a_personal_data_only && !$definition["visible"]) {
891 continue;
892 }
893
894 if (!($user_defined_data["f_" . $field] ?? false)) {
895 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
896 return true;
897 }
898 }
899 }
900
901 return false;
902 }
static getLogger(string $a_component_id)
Get component logger.
isVisible(string $field)
Is setting visible to user?

Referenced by ilUserImportParser\checkProfileIncomplete(), ilAuthFrontend\handleAuthenticationSuccess(), and ilObjUserGUI\saveObject().

+ Here is the caller graph for this function:

◆ setAjaxCallback()

ilUserProfile::setAjaxCallback ( string  $a_href)

Definition at line 813 of file class.ilUserProfile.php.

813 : void
814 {
815 $this->ajax_href = $a_href;
816 }

◆ setMode()

static ilUserProfile::setMode ( int  $mode)
static

Definition at line 840 of file class.ilUserProfile.php.

840 : bool
841 {
842 if (in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION))) {
843 self::$mode = $mode;
844 return true;
845 }
846 return false;
847 }

Referenced by ilAccountRegistrationGUI\initForm().

+ Here is the caller graph for this function:

◆ skipField()

ilUserProfile::skipField ( string  $a_field)

Skip a field.

Definition at line 468 of file class.ilUserProfile.php.

468 : void
469 {
470 $this->skip_fields[] = $a_field;
471 }

◆ skipGroup()

ilUserProfile::skipGroup ( string  $a_group)

Skip a group.

Definition at line 460 of file class.ilUserProfile.php.

460 : void
461 {
462 $this->skip_groups[] = $a_group;
463 }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible ( string  $a_setting)
static

Checks whether user setting is visible.

Definition at line 821 of file class.ilUserProfile.php.

821 : bool
822 {
823 global $DIC;
824
825 $ilSetting = $DIC['ilSetting'];
826
827
829
830 if (self::$mode == self::MODE_DESKTOP) {
831 return ($user_settings_config->isVisible($a_setting));
832 } else {
833 if (isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true) {
834 return true;
835 }
836 return ($ilSetting->get("usr_settings_visib_reg_" . $a_setting, "1") || $ilSetting->get("require_" . $a_setting, "0"));
837 }
838 }

References $DIC, $ilSetting, and ilUserSettingsConfig\isVisible().

Referenced by ilUserDataSet\importRecord().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $ajax_href

string ilUserProfile::$ajax_href
protected

Definition at line 396 of file class.ilUserProfile.php.

◆ $mode

int ilUserProfile::$mode = self::MODE_DESKTOP
staticprivate

Definition at line 30 of file class.ilUserProfile.php.

◆ $skip_fields

array ilUserProfile::$skip_fields
protected

Definition at line 397 of file class.ilUserProfile.php.

◆ $skip_groups

array ilUserProfile::$skip_groups
protected

Definition at line 398 of file class.ilUserProfile.php.

◆ $user_field

array ilUserProfile::$user_field
staticprivate

Definition at line 56 of file class.ilUserProfile.php.

◆ $user_settings_config

ilUserSettingsConfig ilUserProfile::$user_settings_config
protected

Definition at line 400 of file class.ilUserProfile.php.

◆ MODE_DESKTOP

const ilUserProfile::MODE_DESKTOP = 1

Definition at line 27 of file class.ilUserProfile.php.

◆ MODE_REGISTRATION

const ilUserProfile::MODE_REGISTRATION = 2

Definition at line 28 of file class.ilUserProfile.php.

Referenced by ilAccountRegistrationGUI\initForm().


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