ILIAS  release_4-4 Revision
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...
 

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

306  {
307  $this->skip_groups = array();
308  $this->skip_fields = array();
309  }

Member Function Documentation

◆ addStandardFieldsToForm()

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

Add standard fields to form.

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

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

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

References $ilSetting.

Referenced by ilObjUserGUI\handleIgnoredRequiredFields().

907  {
913  global $ilSetting;
914 
915  $ignorableSettings = array();
916 
917  foreach(self::$user_field as $field => $definition)
918  {
919  // !!!username and password must not be ignored!!!
920  if( 'username' == $field ||
921  'password' == $field )
922  {
923  continue;
924  }
925 
926  // Field is not required -> continue
927  if( !$ilSetting->get('require_'.$field) )
928  {
929  continue;
930  }
931 
932  if( self::isEditableByUser($field) )
933  {
934  $ignorableSettings[] = $field;
935  }
936  }
937 
938  return $ignorableSettings;
939  }
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 334 of file class.ilUserProfile.php.

References $ilSetting, and getStandardFields().

335  {
336  global $ilSetting;
337 
338  $settings = $ilSetting->getAll();
339 
340  $fields = array();
341  foreach($this->getStandardFields() as $field => $info)
342  {
343  if($ilSetting->get('usr_settings_visib_lua_'.$field,1))
344  {
345  $fields[$field] = $info;
346  }
347  elseif($info['visib_lua_fix_value'])
348  {
349  $fields[$field] = $info;
350  }
351  }
352  return $fields;
353  }
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 314 of file class.ilUserProfile.php.

Referenced by addStandardFieldsToForm(), and getLocalUserAdministrationFields().

315  {
316  $fields = array();
317  foreach (self::$user_field as $f => $p)
318  {
319  // skip hidden groups
320  if (in_array($p["group"], $this->skip_groups) ||
321  in_array($f, $this->skip_fields))
322  {
323  continue;
324  }
325  $fields[$f] = $p;
326  }
327  return $fields;
328  }
+ 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 877 of file class.ilUserProfile.php.

References $ilSetting.

878  {
884  global $ilSetting;
885 
886  // Not visible in personal data or not changeable
887  if( $ilSetting->get('usr_settings_hide_'.$setting) == 1 ||
888  $ilSetting->get('usr_settings_disable_'.$setting) == 1 )
889  {
890  // User has no chance to edit this field
891  return false;
892  }
893 
894  return true;
895  }
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 819 of file class.ilUserProfile.php.

References $ilSetting, and ilUserDefinedFields\_getInstance().

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

820  {
821  global $ilSetting;
822 
823  // standard fields
824  foreach(self::$user_field as $field => $definition)
825  {
826  // only if visible in personal data
827  if($a_personal_data_only && $ilSetting->get("usr_settings_hide_".$field))
828  {
829  continue;
830  }
831 
832  if($ilSetting->get("require_".$field) && $definition["method"])
833  {
834  $value = $a_user->{$definition["method"]}();
835  if($value == "")
836  {
837  return true;
838  }
839  }
840  }
841 
842  // custom fields
843  if($a_include_udf)
844  {
845  $user_defined_data = $a_user->getUserDefinedData();
846 
847  include_once './Services/User/classes/class.ilUserDefinedFields.php';
848  $user_defined_fields = ilUserDefinedFields::_getInstance();
849  foreach($user_defined_fields->getRequiredDefinitions() as $field => $definition)
850  {
851  // only if visible in personal data
852  if($a_personal_data_only && !$definition["visible"])
853  {
854  continue;
855  }
856 
857  if(!$user_defined_data["f_".$field])
858  {
859  return true;
860  }
861  }
862  }
863 
864  return false;
865  }
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:

◆ setMode()

static ilUserProfile::setMode (   $mode)
static

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

References $lng, and $mode.

800  {
801  global $lng;
802 
803  if(in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION)))
804  {
805  self::$mode = $mode;
806  return true;
807  }
808  return false;
809  }
global $lng
Definition: privfeed.php:40

◆ skipField()

ilUserProfile::skipField (   $a_field)

Skip a field.

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

368  {
369  $this->skip_fields[] = $a_field;
370  }

◆ skipGroup()

ilUserProfile::skipGroup (   $a_group)

Skip a group.

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

360  {
361  $this->skip_groups[] = $a_group;
362  }

◆ userSettingVisible()

static ilUserProfile::userSettingVisible (   $a_setting)
static

Checks whether user setting is visible.

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

References $ilSetting.

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

782  {
783  global $ilSetting;
784 
785  if(self::$mode == self::MODE_DESKTOP)
786  {
787  return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
788  }
789  else
790  {
791  if(isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true)
792  {
793  return true;
794  }
795  return ($ilSetting->get("usr_settings_visib_reg_".$a_setting, "1") || $ilSetting->get("require_".$a_setting, "0"));
796  }
797  }
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: