ILIAS  release_7 Revision v7.30-3-g800a261c036
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...
 

Protected Attributes

 $user_settings_config
 

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 379 of file class.ilUserProfile.php.

380 {
381 global $DIC;
382
383 $lng = $DIC['lng'];
384
385 $this->skip_groups = array();
386 $this->skip_fields = array();
387
388 // for hide me from awareness tool text
389 // not nicest workaround, but better than using common block
390 $lng->loadLanguageModule("awrn");
391 $lng->loadLanguageModule("buddysystem");
392
393 $this->user_settings_config = new ilUserSettingsConfig();
394 }
User settings configuration (what preferences can be visible/changed/...)
global $DIC
Definition: goto.php:24
$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 456 of file class.ilUserProfile.php.

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

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

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 417 of file class.ilUserProfile.php.

418 {
419 global $DIC;
420
421 $ilSetting = $DIC['ilSetting'];
422
423 $settings = $ilSetting->getAll();
424
425 $fields = array();
426 foreach ($this->getStandardFields() as $field => $info) {
427 if ($ilSetting->get('usr_settings_visib_lua_' . $field, 1)) {
428 $fields[$field] = $info;
429 } elseif ($info['visib_lua_fix_value']) {
430 $fields[$field] = $info;
431 }
432 }
433 return $fields;
434 }

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

+ Here is the call graph for this function:

◆ getStandardFields()

ilUserProfile::getStandardFields ( )

Get standard user fields array.

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

400 {
401 $fields = array();
402 foreach (self::$user_field as $f => $p) {
403 // skip hidden groups
404 if (in_array($p["group"], $this->skip_groups) ||
405 in_array($f, $this->skip_fields)) {
406 continue;
407 }
408 $fields[$f] = $p;
409 }
410 return $fields;
411 }

References Vendor\Package\$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

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

906 {
908 return $user_settings_config->isVisibleAndChangeable($setting);
909 }

◆ 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 850 of file class.ilUserProfile.php.

851 {
852 global $DIC;
853
854 $ilSetting = $DIC['ilSetting'];
855
857
858 // standard fields
859 foreach (self::$user_field as $field => $definition) {
860 // only if visible in personal data
861 if ($a_personal_data_only && !$user_settings_config->isVisible($field)) {
862 continue;
863 }
864
865 if ($ilSetting->get("require_" . $field) && $definition["method"]) {
866 $value = $a_user->{$definition["method"]}();
867 if ($value == "") {
868 return true;
869 }
870 }
871 }
872
873 // custom fields
874 if ($a_include_udf) {
875 $user_defined_data = $a_user->getUserDefinedData();
876
877 include_once './Services/User/classes/class.ilUserDefinedFields.php';
878 $user_defined_fields = ilUserDefinedFields::_getInstance();
879 foreach ($user_defined_fields->getRequiredDefinitions() as $field => $definition) {
880 // only if visible in personal data
881 if ($a_personal_data_only && !$definition["visible"]) {
882 continue;
883 }
884
885 if (!$user_defined_data["f_" . $field]) {
886 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
887 return true;
888 }
889 }
890 }
891
892 return false;
893 }
static getLogger($a_component_id)
Get component logger.
static _getInstance()
Get instance.

References $DIC, $ilSetting, and $user_settings_config.

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

+ Here is the caller graph for this function:

◆ setAjaxCallback()

ilUserProfile::setAjaxCallback (   $a_href)

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

803 {
804 $this->ajax_href = $a_href;
805 }

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

830 {
831 global $DIC;
832
833 $lng = $DIC['lng'];
834
835 if (in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION))) {
836 self::$mode = $mode;
837 return true;
838 }
839 return false;
840 }

References $DIC, $lng, and $mode.

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

449 {
450 $this->skip_fields[] = $a_field;
451 }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

441 {
442 $this->skip_groups[] = $a_group;
443 }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

811 {
812 global $DIC;
813
814 $ilSetting = $DIC['ilSetting'];
815
816
818
819 if (self::$mode == self::MODE_DESKTOP) {
820 return ($user_settings_config->isVisible($a_setting));
821 } else {
822 if (isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true) {
823 return true;
824 }
825 return ($ilSetting->get("usr_settings_visib_reg_" . $a_setting, "1") || $ilSetting->get("require_" . $a_setting, "0"));
826 }
827 }

References $DIC, $ilSetting, and $user_settings_config.

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.

◆ $user_settings_config

ilUserProfile::$user_settings_config
protected

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

Referenced by isProfileIncomplete(), and userSettingVisible().

◆ 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: