ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 362 of file class.ilUserProfile.php.

363 {
364 global $lng;
365
366 $this->skip_groups = array();
367 $this->skip_fields = array();
368
369 // for hide me from awareness tool text
370 // not nicest workaround, but better than using common block
371 $lng->loadLanguageModule("awrn");
372 $lng->loadLanguageModule("buddysystem");
373 }
global $lng
Definition: privfeed.php:17

References $lng.

Member Function Documentation

◆ addStandardFieldsToForm()

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

Add standard fields to form.

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

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

References $ilSetting, $lng, $options, 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 960 of file class.ilUserProfile.php.

961 {
967 global $ilSetting;
968
969 $ignorableSettings = array();
970
971 foreach(self::$user_field as $field => $definition)
972 {
973 // !!!username and password must not be ignored!!!
974 if( 'username' == $field ||
975 'password' == $field )
976 {
977 continue;
978 }
979
980 // Field is not required -> continue
981 if( !$ilSetting->get('require_'.$field) )
982 {
983 continue;
984 }
985
986 if( self::isEditableByUser($field) )
987 {
988 $ignorableSettings[] = $field;
989 }
990 }
991
992 return $ignorableSettings;
993 }

References $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 398 of file class.ilUserProfile.php.

399 {
400 global $ilSetting;
401
402 $settings = $ilSetting->getAll();
403
404 $fields = array();
405 foreach($this->getStandardFields() as $field => $info)
406 {
407 if($ilSetting->get('usr_settings_visib_lua_'.$field,1))
408 {
409 $fields[$field] = $info;
410 }
411 elseif($info['visib_lua_fix_value'])
412 {
413 $fields[$field] = $info;
414 }
415 }
416 return $fields;
417 }
$info
Definition: example_052.php:80

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

+ Here is the call graph for this function:

◆ getStandardFields()

ilUserProfile::getStandardFields ( )

Get standard user fields array.

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

379 {
380 $fields = array();
381 foreach (self::$user_field as $f => $p)
382 {
383 // skip hidden groups
384 if (in_array($p["group"], $this->skip_groups) ||
385 in_array($f, $this->skip_fields))
386 {
387 continue;
388 }
389 $fields[$f] = $p;
390 }
391 return $fields;
392 }

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

932 {
938 global $ilSetting;
939
940 // Not visible in personal data or not changeable
941 if( $ilSetting->get('usr_settings_hide_'.$setting) == 1 ||
942 $ilSetting->get('usr_settings_disable_'.$setting) == 1 )
943 {
944 // User has no chance to edit this field
945 return false;
946 }
947
948 return true;
949 }

References $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 872 of file class.ilUserProfile.php.

873 {
874 global $ilSetting;
875
876 // standard fields
877 foreach(self::$user_field as $field => $definition)
878 {
879 // only if visible in personal data
880 if($a_personal_data_only && $ilSetting->get("usr_settings_hide_".$field))
881 {
882 continue;
883 }
884
885 if($ilSetting->get("require_".$field) && $definition["method"])
886 {
887 $value = $a_user->{$definition["method"]}();
888 if($value == "")
889 {
890 return true;
891 }
892 }
893 }
894
895 // custom fields
896 if($a_include_udf)
897 {
898 $user_defined_data = $a_user->getUserDefinedData();
899
900 include_once './Services/User/classes/class.ilUserDefinedFields.php';
901 $user_defined_fields = ilUserDefinedFields::_getInstance();
902 foreach($user_defined_fields->getRequiredDefinitions() as $field => $definition)
903 {
904 // only if visible in personal data
905 if($a_personal_data_only && !$definition["visible"])
906 {
907 continue;
908 }
909
910 if(!$user_defined_data["f_".$field])
911 {
912 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
913 return true;
914 }
915 }
916 }
917
918 return false;
919 }
static getLogger($a_component_id)
Get component logger.
static _getInstance()
Get instance.

References $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 826 of file class.ilUserProfile.php.

827 {
828 $this->ajax_href = $a_href;
829 }

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

853 {
854 global $lng;
855
856 if(in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION)))
857 {
858 self::$mode = $mode;
859 return true;
860 }
861 return false;
862 }

References $lng, and $mode.

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

432 {
433 $this->skip_fields[] = $a_field;
434 }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

424 {
425 $this->skip_groups[] = $a_group;
426 }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

835 {
836 global $ilSetting;
837
838 if(self::$mode == self::MODE_DESKTOP)
839 {
840 return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
841 }
842 else
843 {
844 if(isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true)
845 {
846 return true;
847 }
848 return ($ilSetting->get("usr_settings_visib_reg_".$a_setting, "1") || $ilSetting->get("require_".$a_setting, "0"));
849 }
850 }

References $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: