ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 344 of file class.ilUserProfile.php.

References $lng.

345  {
346  global $lng;
347 
348  $this->skip_groups = array();
349  $this->skip_fields = array();
350 
351  // for hide me from awareness tool text
352  // not nicest workaround, but better than using common block
353  $lng->loadLanguageModule("awrn");
354  $lng->loadLanguageModule("buddysystem");
355  }
global $lng
Definition: privfeed.php:40

Member Function Documentation

◆ addStandardFieldsToForm()

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

Add standard fields to form.

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

References $ilSetting, $lng, $options, ilObjUser\_getPersonalPicturePath(), ilObjRole\_lookupRegisterAllowed(), getStandardFields(), IL_CAL_DATE, ilDateTime\setDate(), ilRadioOption\setDisabled(), ilFormPropertyGUI\setDisabled(), ilFormPropertyGUI\setMulti(), ilSelectInputGUI\setOptions(), ilFormPropertyGUI\setRequired(), ilTextInputGUI\setValue(), ilSelectInputGUI\setValue(), ilEMailInputGUI\setValue(), ilRadioGroupInputGUI\setValue(), ilNonEditableValueGUI\setValue(), ilTextAreaInputGUI\setValue(), and userSettingVisible().

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

◆ getIgnorableRequiredSettings()

static ilUserProfile::getIgnorableRequiredSettings ( )
static

Returns an array of all ignorable profiel fields.

Returns
array public

ilSetting

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

References $ilSetting.

Referenced by ilObjUserGUI\handleIgnoredRequiredFields().

959  {
965  global $ilSetting;
966 
967  $ignorableSettings = array();
968 
969  foreach(self::$user_field as $field => $definition)
970  {
971  // !!!username and password must not be ignored!!!
972  if( 'username' == $field ||
973  'password' == $field )
974  {
975  continue;
976  }
977 
978  // Field is not required -> continue
979  if( !$ilSetting->get('require_'.$field) )
980  {
981  continue;
982  }
983 
984  if( self::isEditableByUser($field) )
985  {
986  $ignorableSettings[] = $field;
987  }
988  }
989 
990  return $ignorableSettings;
991  }
global $ilSetting
Definition: privfeed.php:40
+ Here is the caller graph for this function:

◆ getLocalUserAdministrationFields()

ilUserProfile::getLocalUserAdministrationFields ( )

Get visible fields in local user administration.

Returns

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

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

381  {
382  global $ilSetting;
383 
384  $settings = $ilSetting->getAll();
385 
386  $fields = array();
387  foreach($this->getStandardFields() as $field => $info)
388  {
389  if($ilSetting->get('usr_settings_visib_lua_'.$field,1))
390  {
391  $fields[$field] = $info;
392  }
393  elseif($info['visib_lua_fix_value'])
394  {
395  $fields[$field] = $info;
396  }
397  }
398  return $fields;
399  }
getStandardFields()
Get standard user fields array.
$info
Definition: example_052.php:80
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ getStandardFields()

ilUserProfile::getStandardFields ( )

Get standard user fields array.

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

Referenced by addStandardFieldsToForm(), and getLocalUserAdministrationFields().

361  {
362  $fields = array();
363  foreach (self::$user_field as $f => $p)
364  {
365  // skip hidden groups
366  if (in_array($p["group"], $this->skip_groups) ||
367  in_array($f, $this->skip_fields))
368  {
369  continue;
370  }
371  $fields[$f] = $p;
372  }
373  return $fields;
374  }
+ 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 protected

ilSetting

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

References $ilSetting.

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

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

References $ilSetting, and ilUserDefinedFields\_getInstance().

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

872  {
873  global $ilSetting;
874 
875  // standard fields
876  foreach(self::$user_field as $field => $definition)
877  {
878  // only if visible in personal data
879  if($a_personal_data_only && $ilSetting->get("usr_settings_hide_".$field))
880  {
881  continue;
882  }
883 
884  if($ilSetting->get("require_".$field) && $definition["method"])
885  {
886  $value = $a_user->{$definition["method"]}();
887  if($value == "")
888  {
889  return true;
890  }
891  }
892  }
893 
894  // custom fields
895  if($a_include_udf)
896  {
897  $user_defined_data = $a_user->getUserDefinedData();
898 
899  include_once './Services/User/classes/class.ilUserDefinedFields.php';
900  $user_defined_fields = ilUserDefinedFields::_getInstance();
901  foreach($user_defined_fields->getRequiredDefinitions() as $field => $definition)
902  {
903  // only if visible in personal data
904  if($a_personal_data_only && !$definition["visible"])
905  {
906  continue;
907  }
908 
909  if(!$user_defined_data["f_".$field])
910  {
911  return true;
912  }
913  }
914  }
915 
916  return false;
917  }
static _getInstance()
Get instance.
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAjaxCallback()

ilUserProfile::setAjaxCallback (   $a_href)

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

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

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

References $lng, and $mode.

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

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

414  {
415  $this->skip_fields[] = $a_field;
416  }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

406  {
407  $this->skip_groups[] = $a_group;
408  }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

References $ilSetting.

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

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