ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserProfile Class Reference

Class ilUserProfile. More...

+ Collaboration diagram for ilUserProfile:

Public Member Functions

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

Static Public Member Functions

static userSettingVisible ($a_setting)
 Checks whether user setting is visible. More...
 
static setMode ($mode)
 
static isProfileIncomplete ($a_user, $a_include_udf=true, $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 ($setting)
 Returns whether a profile setting is editable by an user in the profile gui. More...
 

Static Private Attributes

static $mode = self::MODE_DESKTOP
 
static $user_field
 

Detailed Description

Class ilUserProfile.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilUserProfile::__construct ( )

Constructor.

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

374 {
375 global $DIC;
376
377 $lng = $DIC['lng'];
378
379 $this->skip_groups = array();
380 $this->skip_fields = array();
381
382 // for hide me from awareness tool text
383 // not nicest workaround, but better than using common block
384 $lng->loadLanguageModule("awrn");
385 $lng->loadLanguageModule("buddysystem");
386 }
global $DIC
Definition: saml.php:7
$lng

References $DIC, and $lng.

Member Function Documentation

◆ addStandardFieldsToForm()

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

Add standard fields to form.

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

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

References $DIC, $f, $ii, $ilSetting, $lng, $m, PHPMailer\PHPMailer\$options, ilObjRole\_lookupRegisterAllowed(), ilUtil\getPasswordRequirementsInfo(), getStandardFields(), IL_CAL_DATE, MODE_REGISTRATION, and userSettingVisible().

+ Here is the call graph for this function:

◆ getIgnorableRequiredSettings()

static ilUserProfile::getIgnorableRequiredSettings ( )
static

Returns an array of all ignorable profiel fields.

Returns
array @access public

@global ilSetting

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

923 {
929 global $DIC;
930
931 $ilSetting = $DIC['ilSetting'];
932
933 $ignorableSettings = array();
934
935 foreach (self::$user_field as $field => $definition) {
936 // !!!username and password must not be ignored!!!
937 if ('username' == $field ||
938 'password' == $field) {
939 continue;
940 }
941
942 // Field is not required -> continue
943 if (!$ilSetting->get('require_' . $field)) {
944 continue;
945 }
946
947 if (self::isEditableByUser($field)) {
948 $ignorableSettings[] = $field;
949 }
950 }
951
952 return $ignorableSettings;
953 }

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.

Returns

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

410 {
411 global $DIC;
412
413 $ilSetting = $DIC['ilSetting'];
414
415 $settings = $ilSetting->getAll();
416
417 $fields = array();
418 foreach ($this->getStandardFields() as $field => $info) {
419 if ($ilSetting->get('usr_settings_visib_lua_' . $field, 1)) {
420 $fields[$field] = $info;
421 } elseif ($info['visib_lua_fix_value']) {
422 $fields[$field] = $info;
423 }
424 }
425 return $fields;
426 }
$info
Definition: index.php:5

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

+ Here is the call graph for this function:

◆ getStandardFields()

ilUserProfile::getStandardFields ( )

Get standard user fields array.

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

392 {
393 $fields = array();
394 foreach (self::$user_field as $f => $p) {
395 // skip hidden groups
396 if (in_array($p["group"], $this->skip_groups) ||
397 in_array($f, $this->skip_fields)) {
398 continue;
399 }
400 $fields[$f] = $p;
401 }
402 return $fields;
403 }

References $f.

Referenced by addStandardFieldsToForm(), and getLocalUserAdministrationFields().

+ Here is the caller graph for this function:

◆ isEditableByUser()

static ilUserProfile::isEditableByUser (   $setting)
staticprotected

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

Parameters
stringA key of a profile setting
Returns
boolean Determines whether the passed setting can be edited by the user itself @access protected

@global ilSetting

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

893 {
899 global $DIC;
900
901 $ilSetting = $DIC['ilSetting'];
902
903 // Not visible in personal data or not changeable
904 if ($ilSetting->get('usr_settings_hide_' . $setting) == 1 ||
905 $ilSetting->get('usr_settings_disable_' . $setting) == 1) {
906 // User has no chance to edit this field
907 return false;
908 }
909
910 return true;
911 }

References $DIC, and $ilSetting.

◆ isProfileIncomplete()

static ilUserProfile::isProfileIncomplete (   $a_user,
  $a_include_udf = true,
  $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 839 of file class.ilUserProfile.php.

840 {
841 global $DIC;
842
843 $ilSetting = $DIC['ilSetting'];
844
845 // standard fields
846 foreach (self::$user_field as $field => $definition) {
847 // only if visible in personal data
848 if ($a_personal_data_only && $ilSetting->get("usr_settings_hide_" . $field)) {
849 continue;
850 }
851
852 if ($ilSetting->get("require_" . $field) && $definition["method"]) {
853 $value = $a_user->{$definition["method"]}();
854 if ($value == "") {
855 return true;
856 }
857 }
858 }
859
860 // custom fields
861 if ($a_include_udf) {
862 $user_defined_data = $a_user->getUserDefinedData();
863
864 include_once './Services/User/classes/class.ilUserDefinedFields.php';
865 $user_defined_fields = ilUserDefinedFields::_getInstance();
866 foreach ($user_defined_fields->getRequiredDefinitions() as $field => $definition) {
867 // only if visible in personal data
868 if ($a_personal_data_only && !$definition["visible"]) {
869 continue;
870 }
871
872 if (!$user_defined_data["f_" . $field]) {
873 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
874 return true;
875 }
876 }
877 }
878
879 return false;
880 }
static getLogger($a_component_id)
Get component logger.
static _getInstance()
Get instance.

References $DIC, and $ilSetting.

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

+ Here is the caller graph for this function:

◆ setAjaxCallback()

ilUserProfile::setAjaxCallback (   $a_href)

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

795 {
796 $this->ajax_href = $a_href;
797 }

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

819 {
820 global $DIC;
821
822 $lng = $DIC['lng'];
823
824 if (in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION))) {
825 self::$mode = $mode;
826 return true;
827 }
828 return false;
829 }

References $DIC, $lng, and $mode.

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

441 {
442 $this->skip_fields[] = $a_field;
443 }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

433 {
434 $this->skip_groups[] = $a_group;
435 }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

803 {
804 global $DIC;
805
806 $ilSetting = $DIC['ilSetting'];
807
808 if (self::$mode == self::MODE_DESKTOP) {
809 return ($ilSetting->get("usr_settings_hide_" . $a_setting) != 1);
810 } else {
811 if (isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true) {
812 return true;
813 }
814 return ($ilSetting->get("usr_settings_visib_reg_" . $a_setting, "1") || $ilSetting->get("require_" . $a_setting, "0"));
815 }
816 }

References $DIC, and $ilSetting.

Referenced by addStandardFieldsToForm(), and ilUserDataSet\importRecord().

+ Here is the caller graph for this function:

Field Documentation

◆ $mode

ilUserProfile::$mode = self::MODE_DESKTOP
staticprivate

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

Referenced by setMode().

◆ $user_field

ilUserProfile::$user_field
staticprivate

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

◆ MODE_DESKTOP

const ilUserProfile::MODE_DESKTOP = 1

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

◆ MODE_REGISTRATION

const ilUserProfile::MODE_REGISTRATION = 2

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