ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 334 of file class.ilUserProfile.php.

335  {
336  $this->skip_groups = array();
337  $this->skip_fields = array();
338  }

Member Function Documentation

◆ addStandardFieldsToForm()

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

Add standard fields to form.

Definition at line 404 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().

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

References $ilSetting.

Referenced by ilObjUserGUI\handleIgnoredRequiredFields().

942  {
948  global $ilSetting;
949 
950  $ignorableSettings = array();
951 
952  foreach(self::$user_field as $field => $definition)
953  {
954  // !!!username and password must not be ignored!!!
955  if( 'username' == $field ||
956  'password' == $field )
957  {
958  continue;
959  }
960 
961  // Field is not required -> continue
962  if( !$ilSetting->get('require_'.$field) )
963  {
964  continue;
965  }
966 
967  if( self::isEditableByUser($field) )
968  {
969  $ignorableSettings[] = $field;
970  }
971  }
972 
973  return $ignorableSettings;
974  }
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 363 of file class.ilUserProfile.php.

References $ilSetting, and getStandardFields().

364  {
365  global $ilSetting;
366 
367  $settings = $ilSetting->getAll();
368 
369  $fields = array();
370  foreach($this->getStandardFields() as $field => $info)
371  {
372  if($ilSetting->get('usr_settings_visib_lua_'.$field,1))
373  {
374  $fields[$field] = $info;
375  }
376  elseif($info['visib_lua_fix_value'])
377  {
378  $fields[$field] = $info;
379  }
380  }
381  return $fields;
382  }
getStandardFields()
Get standard user fields array.
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 343 of file class.ilUserProfile.php.

Referenced by addStandardFieldsToForm(), and getLocalUserAdministrationFields().

344  {
345  $fields = array();
346  foreach (self::$user_field as $f => $p)
347  {
348  // skip hidden groups
349  if (in_array($p["group"], $this->skip_groups) ||
350  in_array($f, $this->skip_fields))
351  {
352  continue;
353  }
354  $fields[$f] = $p;
355  }
356  return $fields;
357  }
+ 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 912 of file class.ilUserProfile.php.

References $ilSetting.

913  {
919  global $ilSetting;
920 
921  // Not visible in personal data or not changeable
922  if( $ilSetting->get('usr_settings_hide_'.$setting) == 1 ||
923  $ilSetting->get('usr_settings_disable_'.$setting) == 1 )
924  {
925  // User has no chance to edit this field
926  return false;
927  }
928 
929  return true;
930  }
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 854 of file class.ilUserProfile.php.

References $ilSetting, and ilUserDefinedFields\_getInstance().

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

855  {
856  global $ilSetting;
857 
858  // standard fields
859  foreach(self::$user_field as $field => $definition)
860  {
861  // only if visible in personal data
862  if($a_personal_data_only && $ilSetting->get("usr_settings_hide_".$field))
863  {
864  continue;
865  }
866 
867  if($ilSetting->get("require_".$field) && $definition["method"])
868  {
869  $value = $a_user->{$definition["method"]}();
870  if($value == "")
871  {
872  return true;
873  }
874  }
875  }
876 
877  // custom fields
878  if($a_include_udf)
879  {
880  $user_defined_data = $a_user->getUserDefinedData();
881 
882  include_once './Services/User/classes/class.ilUserDefinedFields.php';
883  $user_defined_fields = ilUserDefinedFields::_getInstance();
884  foreach($user_defined_fields->getRequiredDefinitions() as $field => $definition)
885  {
886  // only if visible in personal data
887  if($a_personal_data_only && !$definition["visible"])
888  {
889  continue;
890  }
891 
892  if(!$user_defined_data["f_".$field])
893  {
894  return true;
895  }
896  }
897  }
898 
899  return false;
900  }
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 808 of file class.ilUserProfile.php.

809  {
810  $this->ajax_href = $a_href;
811  }

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

References $lng, and $mode.

835  {
836  global $lng;
837 
838  if(in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION)))
839  {
840  self::$mode = $mode;
841  return true;
842  }
843  return false;
844  }
global $lng
Definition: privfeed.php:40

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

397  {
398  $this->skip_fields[] = $a_field;
399  }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

389  {
390  $this->skip_groups[] = $a_group;
391  }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

References $ilSetting.

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

817  {
818  global $ilSetting;
819 
820  if(self::$mode == self::MODE_DESKTOP)
821  {
822  return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
823  }
824  else
825  {
826  if(isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true)
827  {
828  return true;
829  }
830  return ($ilSetting->get("usr_settings_visib_reg_".$a_setting, "1") || $ilSetting->get("require_".$a_setting, "0"));
831  }
832  }
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: