ILIAS  release_8 Revision v8.24
class.ilUserProfile.php
Go to the documentation of this file.
1<?php
2
20
26{
27 public const MODE_DESKTOP = 1;
28 public const MODE_REGISTRATION = 2;
29
30 private static int $mode = self::MODE_DESKTOP;
31
32 // this array should be used in all places where user data is tackled
33 // in the future: registration, personal profile, user administration
34 // public profile, user import/export
35 // for now this is not implemented yet. Please list places, that already use it:
36 //
37 // - personal profile
38 // - (global) standard user profile fields settings
39 //
40 // the following attributes are defined (can be extended if needed):
41 // - input: input type
42 // standard inputs: text, radio, selection, textarea
43 // special inputs: login
44 // - input dependend attributes
45 // - maxlength, sizte for text
46 // - values array for radio
47 // - cols/rows for text areas
48 // - options array for selections
49 // - method: ilObjUser get-method, e.g. getFirstname
50 // - group: group id (id is also used as lang_var for sub headers in forms
51 // - lang_var: if key should not be used as lang var, this overwrites the usage in forms
52 // - settings property related attributes, settingsproperties are ("visible", "changeable",
53 // "searchable", "required", "export", "course_export" and "registration")
54 // - <settingsproperty>_hide: hide this property in settings (not implemented)
55 // - <settingsproperty>_fix_value: property has a fix value (cannot be changed)
56 private static array $user_field = array(
57 "username" => array(
58 "input" => "login",
59 "maxlength" => 190,
60 "size" => 190,
61 "method" => "getLogin",
62 "course_export_fix_value" => 1,
63 "group_export_fix_value" => 1,
64 "changeable_hide" => true,
65 "required_hide" => true,
66 "group" => "personal_data"),
67 "password" => array(
68 "input" => "password",
69 "required_hide" => true,
70 "visib_reg_hide" => true,
71 'visib_lua_fix_value' => 0,
72 "course_export_hide" => true,
73 "export_hide" => false,
74 "group_export_hide" => true,
75 "lists_hide" => true,
76 "group" => "personal_data"),
77 "firstname" => array(
78 "input" => "text",
79 "maxlength" => 128,
80 "size" => 40,
81 "method" => "getFirstname",
82 "required_fix_value" => 1,
83 "visib_reg_fix_value" => 1,
84 'visib_lua_fix_value' => 1,
85 "course_export_fix_value" => 1,
86 "group_export_fix_value" => 1,
87 "group" => "personal_data"),
88 "lastname" => array(
89 "input" => "text",
90 "maxlength" => 128,
91 "size" => 40,
92 "method" => "getLastname",
93 "required_fix_value" => 1,
94 "visib_reg_fix_value" => 1,
95 'visib_lua_fix_value' => 1,
96 "course_export_fix_value" => 1,
97 "group_export_fix_value" => 1,
98 "group" => "personal_data"),
99 "title" => array(
100 "input" => "text",
101 "lang_var" => "person_title",
102 "maxlength" => 32,
103 "size" => 40,
104 "method" => "getUTitle",
105 "group" => "personal_data"),
106 "birthday" => array(
107 "input" => "birthday",
108 "lang_var" => "birthday",
109 "maxlength" => 32,
110 "size" => 40,
111 "method" => "getBirthday",
112 "group" => "personal_data"),
113 "gender" => array(
114 "input" => "radio",
115 "values" => array("n" => "salutation_n", "f" => "salutation_f", "m" => "salutation_m"),
116 "method" => "getGender",
117 "group" => "personal_data"),
118 "upload" => array(
119 "input" => "picture",
120 "required_hide" => true,
121 "visib_reg_hide" => true,
122 "course_export_hide" => true,
123 "group_export_hide" => true,
124 "lists_hide" => true,
125 "lang_var" => "personal_picture",
126 "group" => "personal_data"),
127 "roles" => array(
128 "input" => "roles",
129 "changeable_hide" => true,
130 "required_hide" => true,
131 "visib_reg_hide" => true,
132 "export_hide" => true,
133 "course_export_hide" => true,
134 "group_export_hide" => true,
135 "lists_hide" => true,
136 "group" => "personal_data"),
137 "interests_general" => array(
138 "input" => "multitext",
139 "maxlength" => 40,
140 "size" => 40,
141 "method" => "getGeneralInterests",
142 "course_export_hide" => true,
143 "group_export_hide" => true,
144 "lists_hide" => true,
145 "group" => "interests"),
146 "interests_help_offered" => array(
147 "input" => "multitext",
148 "maxlength" => 40,
149 "size" => 40,
150 "method" => "getOfferingHelp",
151 "course_export_hide" => true,
152 "group_export_hide" => true,
153 "lists_hide" => true,
154 "group" => "interests"),
155 "interests_help_looking" => array(
156 "input" => "multitext",
157 "maxlength" => 40,
158 "size" => 40,
159 "method" => "getLookingForHelp",
160 "course_export_hide" => true,
161 "group_export_hide" => true,
162 "lists_hide" => true,
163 "group" => "interests"),
164 "org_units" => array(
165 "input" => "noneditable",
166 "lang_var" => "objs_orgu",
167 "required_hide" => true,
168 "visib_reg_hide" => true,
169 "course_export_hide" => false,
170 "group_export_hide" => false,
171 "export_hide" => true,
172 "changeable_hide" => true,
173 "changeable_fix_value" => 0,
174 "changeable_lua_hide" => true,
175 "changeable_lua_fix_value" => 0,
176 "method" => "getOrgUnitsRepresentation",
177 "group" => "contact_data"),
178 "institution" => array(
179 "input" => "text",
180 "maxlength" => 80,
181 "size" => 40,
182 "method" => "getInstitution",
183 "group" => "contact_data"),
184 "department" => array(
185 "input" => "text",
186 "maxlength" => 80,
187 "size" => 40,
188 "method" => "getDepartment",
189 "group" => "contact_data"),
190 "street" => array(
191 "input" => "text",
192 "maxlength" => 40,
193 "size" => 40,
194 "method" => "getStreet",
195 "group" => "contact_data"),
196 "zipcode" => array(
197 "input" => "text",
198 "maxlength" => 10,
199 "size" => 10,
200 "method" => "getZipcode",
201 "group" => "contact_data"),
202 "city" => array(
203 "input" => "text",
204 "maxlength" => 40,
205 "size" => 40,
206 "method" => "getCity",
207 "group" => "contact_data"),
208 "country" => array(
209 "input" => "text",
210 "maxlength" => 40,
211 "size" => 40,
212 "method" => "getCountry",
213 "group" => "contact_data"),
214 "sel_country" => array(
215 "input" => "sel_country",
216 "method" => "getSelectedCountry",
217 "group" => "contact_data"),
218 "phone_office" => array(
219 "input" => "text",
220 "maxlength" => 40,
221 "size" => 40,
222 "method" => "getPhoneOffice",
223 "group" => "contact_data"),
224 "phone_home" => array(
225 "input" => "text",
226 "maxlength" => 40,
227 "size" => 40,
228 "method" => "getPhoneHome",
229 "group" => "contact_data"),
230 "phone_mobile" => array(
231 "input" => "text",
232 "maxlength" => 40,
233 "size" => 40,
234 "method" => "getPhoneMobile",
235 "group" => "contact_data"),
236 "fax" => array(
237 "input" => "text",
238 "maxlength" => 40,
239 "size" => 40,
240 "method" => "getFax",
241 "group" => "contact_data"),
242 "email" => array(
243 "input" => "email",
244 "maxlength" => 128,
245 "size" => 40,
246 "method" => "getEmail",
247 "group" => "contact_data"),
248 "second_email" => array(
249 "input" => "second_email",
250 "maxlength" => 40,
251 "size" => 40,
252 "method" => "getSecondEmail",
253 "group" => "contact_data",
254 "change_listeners" => [
255 ilMailUserFieldChangeListener::class,
256 ]),
257 "hobby" => array(
258 "input" => "textarea",
259 "rows" => 3,
260 "cols" => 45,
261 "method" => "getHobby",
262 "lists_hide" => true,
263 "group" => "contact_data"),
264 "referral_comment" => array(
265 "input" => "textarea",
266 "rows" => 3,
267 "cols" => 45,
268 "method" => "getComment",
269 "course_export_hide" => true,
270 "group_export_hide" => true,
271 "lists_hide" => true,
272 "group" => "contact_data"),
273 "matriculation" => array(
274 "input" => "text",
275 "maxlength" => 40,
276 "size" => 40,
277 "method" => "getMatriculation",
278 "group" => "other"),
279 "language" => array(
280 "input" => "language",
281 "method" => "getLanguage",
282 "required_hide" => true,
283 "visib_reg_hide" => true,
284 "course_export_hide" => true,
285 "group_export_hide" => true,
286 "group" => "settings"),
287 "skin_style" => array(
288 "input" => "skinstyle",
289 "required_hide" => true,
290 "visib_reg_hide" => true,
291 "course_export_hide" => true,
292 "group_export_hide" => true,
293 "group" => "settings"),
294 "hits_per_page" => array(
295 "input" => "hitsperpage",
296 "default" => 10,
297 "options" => array(
298 10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40,
299 50 => 50, 100 => 100, 9999 => 9999),
300 "required_hide" => true,
301 "visib_reg_hide" => true,
302 "course_export_hide" => true,
303 "group_export_hide" => true,
304 "group" => "settings"),
305 /*"show_users_online" => array(
306 "input" => "selection",
307 "default" => "y",
308 "options" => array(
309 "y" => "users_online_show_short_y",
310 "associated" => "users_online_show_short_associated",
311 "n" => "users_online_show_short_n"),
312 "required_hide" => true,
313 "visib_reg_hide" => true,
314 "course_export_hide" => true,
315 "group_export_hide" => true,
316 "group" => "settings"),*/
317 "hide_own_online_status" => array(
318 "input" => "selection",
319 "lang_var" => "awrn_user_show",
320 "required_hide" => true,
321 "visib_reg_hide" => true,
322 "course_export_hide" => true,
323 "group_export_hide" => true,
324 "group" => "settings",
325 "default" => "y",
326 "options" => array(
327 "y" => "user_awrn_hide",
328 "n" => "user_awrn_show"
329 )),
330 "bs_allow_to_contact_me" => array(
331 "input" => "selection",
332 "lang_var" => "buddy_allow_to_contact_me",
333 "required_hide" => true,
334 "visib_reg_hide" => true,
335 "course_export_hide" => true,
336 "group_export_hide" => true,
337 "group" => "settings",
338 "default" => "y",
339 "options" => array(
340 "n" => "buddy_allow_to_contact_me_no",
341 "y" => "buddy_allow_to_contact_me_yes"
342 )
343 ),
344 "chat_osc_accept_msg" => array(
345 "input" => "selection",
346 "lang_var" => "chat_osc_accept_msg",
347 "required_hide" => true,
348 "visib_reg_hide" => true,
349 "course_export_hide" => true,
350 "group_export_hide" => true,
351 "group" => "settings",
352 "default" => "y",
353 "options" => array(
354 "n" => "chat_osc_accepts_messages_no",
355 "y" => "chat_osc_accepts_messages_yes"
356 )
357 ),
358 "chat_broadcast_typing" => array(
359 "input" => "selection",
360 "lang_var" => "chat_broadcast_typing",
361 "required_hide" => true,
362 "visib_reg_hide" => true,
363 "course_export_hide" => true,
364 "group_export_hide" => true,
365 "group" => "settings",
366 "default" => "y",
367 "options" => array(
368 "n" => "chat_no_use_typing_broadcast",
369 "y" => "chat_use_typing_broadcast"
370 )
371 ),
372 "preferences" => array(
373 "visible_fix_value" => 1,
374 "changeable_fix_value" => 1,
375 "required_hide" => true,
376 "visib_reg_hide" => true,
377 "course_export_hide" => true,
378 "group_export_hide" => true,
379 "group" => "preferences"),
380 "mail_incoming_mail" => array(
381 "input" => "selection",
382 "default" => "y",
383 "options" => array(
384 ilMailOptions::INCOMING_LOCAL => "mail_incoming_local",
385 ilMailOptions::INCOMING_EMAIL => "mail_incoming_smtp",
386 ilMailOptions::INCOMING_BOTH => "mail_incoming_both"),
387 "required_hide" => true,
388 "visib_reg_hide" => true,
389 "course_export_hide" => true,
390 "group_export_hide" => true,
391 "export_hide" => true,
392 "search_hide" => true,
393 "group" => "settings")
394
395 );
396 protected string $ajax_href;
397 protected array $skip_fields; // Missing array type.
398 protected array $skip_groups; // Missing array type.
399
401
402 public function __construct()
403 {
404 global $DIC;
405
406 $lng = $DIC->language();
407
408 $this->skip_groups = array();
409 $this->skip_fields = array();
410
411 // for hide me from awareness tool text
412 // not nicest workaround, but better than using common block
413 $lng->loadLanguageModule("awrn");
414 $lng->loadLanguageModule("buddysystem");
415
416 $this->user_settings_config = new ilUserSettingsConfig();
417 }
418
422 public function getStandardFields(): array // Missing array type.
423 {
424 $fields = array();
425 foreach (self::$user_field as $f => $p) {
426 // skip hidden groups
427 if (in_array($p["group"], $this->skip_groups) ||
428 in_array($f, $this->skip_fields)) {
429 continue;
430 }
431 $fields[$f] = $p;
432 }
433 return $fields;
434 }
435
439 public function getLocalUserAdministrationFields(): array // Missing array type.
440 {
441 global $DIC;
442
443 $ilSetting = $DIC->settings();
444
445 $fields = array();
446 foreach ($this->getStandardFields() as $field => $info) {
447 if ($ilSetting->get('usr_settings_visib_lua_' . $field, '1')) {
448 $fields[$field] = $info;
449 } elseif ($info['visib_lua_fix_value'] ?? false) {
450 $fields[$field] = $info;
451 }
452 }
453 return $fields;
454 }
455
456
460 public function skipGroup(string $a_group): void
461 {
462 $this->skip_groups[] = $a_group;
463 }
464
468 public function skipField(string $a_field): void
469 {
470 $this->skip_fields[] = $a_field;
471 }
472
476 public function addStandardFieldsToForm(
477 ilPropertyFormGUI $a_form,
478 ?ilObjUser $a_user = null,
479 array $custom_fields = null
480 ): void {
481 global $DIC;
482
483 $ilSetting = $DIC['ilSetting'];
484 $lng = $DIC['lng'];
485 $rbacreview = $DIC['rbacreview'];
486
487 $registration_settings = null;
488
489 // custom registration settings
490 if (self::$mode == self::MODE_REGISTRATION) {
491 $registration_settings = new ilRegistrationSettings();
492
493 self::$user_field["username"]["group"] = "login_data";
494 self::$user_field["password"]["group"] = "login_data";
495 self::$user_field["language"]["default"] = $lng->lang_key;
496
497 // different position for role
498 $roles = self::$user_field["roles"];
499 unset(self::$user_field["roles"]);
500 self::$user_field["roles"] = $roles;
501 self::$user_field["roles"]["group"] = "settings";
502 }
503
504 $fields = $this->getStandardFields();
505 $current_group = "";
506 $custom_fields_done = false;
507 foreach ($fields as $f => $p) {
508 // next group? -> diplay subheader
509 if (($p["group"] != $current_group) &&
510 self::userSettingVisible($f)) {
511 if (is_array($custom_fields) && $custom_fields !== [] && !$custom_fields_done) {
512 // should be appended to "other" or at least before "settings"
513 if ($current_group == "other" || $p["group"] == "settings") {
514 // add "other" subheader
515 if ($current_group != "other") {
516 $sh = new ilFormSectionHeaderGUI();
517 $sh->setTitle($lng->txt("other"));
518 $a_form->addItem($sh);
519 }
520 foreach ($custom_fields as $custom_field) {
521 $a_form->addItem($custom_field);
522 }
523 $custom_fields_done = true;
524 }
525 }
526
527 $sh = new ilFormSectionHeaderGUI();
528 $sh->setTitle($lng->txt($p["group"]));
529 $a_form->addItem($sh);
530 $current_group = $p["group"];
531 }
532
533 $m = $p["method"] ?? "";
534
535 $lv = (isset($p["lang_var"]) && $p["lang_var"] != "")
536 ? $p["lang_var"]
537 : $f;
538
539 switch ($p["input"]) {
540 case "login":
541 if ((int) $ilSetting->get('allow_change_loginname') || self::$mode == self::MODE_REGISTRATION) {
542 $val = new ilTextInputGUI($lng->txt('username'), 'username');
543 if ($a_user) {
544 $val->setValue($a_user->getLogin());
545 }
546 $val->setMaxLength((int) $p['maxlength']);
547 $val->setSize(255);
548 $val->setRequired(true);
549 } else {
550 // user account name
551 $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un');
552 if ($a_user) {
553 $val->setValue($a_user->getLogin());
554 }
555 }
556 $a_form->addItem($val);
557 break;
558
559 case "text":
560 if (self::userSettingVisible($f)) {
561 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
562 $value = '';
563 if ($a_user) {
564 $value = $a_user->$m() ?? '';
565 }
566 $ti->setValue($value);
567 $ti->setMaxLength($p["maxlength"]);
568 $ti->setSize($p["size"]);
569 $ti->setRequired((bool) $ilSetting->get("require_" . $f));
570 if (!$ti->getRequired() || $ti->getValue()) {
571 $ti->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
572 }
573 $a_form->addItem($ti);
574 }
575 break;
576
577 case "sel_country":
578 if (self::userSettingVisible($f)) {
579 $ci = new ilCountrySelectInputGUI($lng->txt($lv), "usr_" . $f);
580 if ($a_user) {
581 $ci->setValue($a_user->$m());
582 }
583 $ci->setRequired((bool) $ilSetting->get("require_" . $f));
584 if (!$ci->getRequired() || $ci->getValue()) {
585 $ci->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
586 }
587 $a_form->addItem($ci);
588 }
589 break;
590
591 case "birthday":
592 if (self::userSettingVisible($f)) {
593 $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_" . $f);
594 $date = null;
595 if ($a_user && strlen($a_user->$m())) {
596 $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
597 $bi->setDate($date);
598 }
599 $bi->setRequired((bool) $ilSetting->get("require_" . $f));
600 if (!$bi->getRequired() || $date) {
601 $bi->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
602 }
603 $a_form->addItem($bi);
604 }
605 break;
606
607 case "radio":
608 if (self::userSettingVisible($f)) {
609 $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_" . $f);
610 if ($a_user) {
611 $rg->setValue($a_user->$m());
612 }
613 foreach ($p["values"] as $k => $v) {
614 $op = new ilRadioOption($lng->txt($v), $k);
615 $rg->addOption($op);
616 }
617 $rg->setRequired((bool) $ilSetting->get("require_" . $f));
618 if (!$rg->getRequired() || $rg->getValue()) {
619 $rg->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
620 }
621 $a_form->addItem($rg);
622 }
623 break;
624
625 case "picture":
626 if (self::userSettingVisible("upload") && $a_user) {
627 $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
628 $ii->setAllowCapture(true);
629 $ii->setDisabled((bool) $ilSetting->get("usr_settings_disable_upload"));
630
631 $upload = $a_form->getFileUpload("userfile");
632 if ($upload["name"] ?? false) {
633 $ii->setPending($upload["name"]);
634 } else {
636 $a_user->getId(),
637 "small",
638 true,
639 true
640 );
641 if ($im != "") {
642 $ii->setImage($im);
643 $ii->setAlt($lng->txt("personal_picture"));
644 }
645 }
646
647 $a_form->addItem($ii);
648 }
649 break;
650
651 case "roles":
652 $role_names = "";
653 if (self::$mode == self::MODE_DESKTOP) {
654 if (self::userSettingVisible("roles")) {
655 $global_roles = $rbacreview->getGlobalRoles();
656 foreach ($global_roles as $role_id) {
657 if (in_array($role_id, $rbacreview->assignedRoles($a_user->getId()))) {
658 $roleObj = ilObjectFactory::getInstanceByObjId($role_id);
659 $role_names .= $roleObj->getTitle() . ", ";
660 unset($roleObj);
661 }
662 }
663 $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
664 $dr->setValue(substr($role_names, 0, -2));
665 $a_form->addItem($dr);
666 }
667 } elseif (self::$mode == self::MODE_REGISTRATION) {
668 if ($registration_settings->roleSelectionEnabled()) {
669 $options = array();
670 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
671 $options[$role["id"]] = $role["title"];
672 }
673 // registration form validation will take care of missing field / value
674 if ($options) {
675 if (count($options) > 1) {
676 $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_" . $f);
677 $ta->setOptions($options);
678 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
679 if (!$ta->getRequired()) {
680 $ta->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
681 }
682 }
683 // no need for select if only 1 option
684 else {
685 $ta = new ilHiddenInputGUI("usr_" . $f);
686 $keys = array_keys($options);
687 $ta->setValue(array_shift($keys));
688 }
689 $a_form->addItem($ta);
690 }
691 }
692 }
693 break;
694
695 case "second_email":
696 case "email":
697 if (self::userSettingVisible($f)) {
698 $em = new ilEMailInputGUI($lng->txt($lv), "usr_" . $f);
699 if ($a_user) {
700 $em->setValue($a_user->$m());
701 }
702 $em->setRequired((bool) $ilSetting->get("require_" . $f));
703 if (!$em->getRequired() || $em->getValue()) {
704 $em->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
705 }
706 if (self::MODE_REGISTRATION == self::$mode) {
707 $em->setRetype(true);
708 }
709 $em->setMaxLength((int) $p['maxlength']);
710 $a_form->addItem($em);
711 }
712 break;
713 case "textarea":
714 if (self::userSettingVisible($f)) {
715 $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_" . $f);
716 if ($a_user) {
717 $ta->setValue($a_user->$m() ?? '');
718 }
719 $ta->setRows($p["rows"]);
720 $ta->setCols($p["cols"]);
721 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
722 if (!$ta->getRequired() || $ta->getValue()) {
723 $ta->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
724 }
725 $a_form->addItem($ta);
726 }
727 break;
728
729 case "password":
730 if (self::$mode == self::MODE_REGISTRATION) {
731 if (!$registration_settings->passwordGenerationEnabled()) {
732 $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_" . $f);
733 $ta->setUseStripSlashes(false);
734 $ta->setRequired(true);
736 // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
737 } else {
738 $ta = new ilNonEditableValueGUI($lng->txt($lv));
739 $ta->setValue($lng->txt("reg_passwd_via_mail"));
740 }
741 $a_form->addItem($ta);
742 }
743 break;
744
745 case "language":
746 if (self::userSettingVisible($f)) {
747 $ta = new ilSelectInputGUI($lng->txt($lv), "usr_" . $f);
748 if ($a_user) {
749 $ta->setValue($a_user->$m());
750 }
751 $options = array();
752 $lng->loadLanguageModule("meta");
753 foreach ($lng->getInstalledLanguages() as $lang_key) {
754 $options[$lang_key] = $lng->txt("meta_l_" . $lang_key);
755 }
756 asort($options); // #9728
757 $ta->setOptions($options);
758 $ta->setRequired((bool) $ilSetting->get("require_" . $f));
759 if (!$ta->getRequired() || $ta->getValue()) {
760 $ta->setDisabled(
761 $ilSetting->get("usr_settings_disable_" . $f) === '1'
762 || count($options) <= 1
763 );
764 }
765 $a_form->addItem($ta);
766 }
767 break;
768
769 case "multitext":
770 if (self::userSettingVisible($f)) {
771 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
772 $ti->setMulti(true);
773 if ($a_user) {
774 $ti->setValue($a_user->$m());
775 }
776 $ti->setMaxLength($p["maxlength"]);
777 $ti->setSize($p["size"]);
778 $ti->setRequired((bool) $ilSetting->get("require_" . $f));
779 if (!$ti->getRequired() || $ti->getValue()) {
780 $ti->setDisabled((bool) $ilSetting->get("usr_settings_disable_" . $f));
781 }
782 if ($this->ajax_href) {
783 // add field to ajax call
784 $ti->setDataSource($this->ajax_href . "&f=" . $f);
785 }
786 $a_form->addItem($ti);
787 }
788 break;
789 case "noneditable":
790 if (self::$mode == self::MODE_DESKTOP && self::userSettingVisible($f)) {
791 $ne = new ilNonEditableValueGUI($lng->txt($lv));
792 $ne->setValue($a_user->$m());
793 $a_form->addItem($ne);
794 }
795 break;
796 }
797 }
798
799 // append custom fields as "other"
800 if (is_array($custom_fields) && $custom_fields !== [] && !$custom_fields_done) {
801 // add "other" subheader
802 if ($current_group != "other") {
803 $sh = new ilFormSectionHeaderGUI();
804 $sh->setTitle($lng->txt("other"));
805 $a_form->addItem($sh);
806 }
807 foreach ($custom_fields as $custom_field) {
808 $a_form->addItem($custom_field);
809 }
810 }
811 }
812
813 public function setAjaxCallback(string $a_href): void
814 {
815 $this->ajax_href = $a_href;
816 }
817
821 public static function userSettingVisible(string $a_setting): bool
822 {
823 global $DIC;
824
825 $ilSetting = $DIC['ilSetting'];
826
827
828 $user_settings_config = new ilUserSettingsConfig();
829
830 if (self::$mode == self::MODE_DESKTOP) {
831 return ($user_settings_config->isVisible($a_setting));
832 } else {
833 if (isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true) {
834 return true;
835 }
836 return ($ilSetting->get("usr_settings_visib_reg_" . $a_setting, "1") || $ilSetting->get("require_" . $a_setting, "0"));
837 }
838 }
839
840 public static function setMode(int $mode): bool
841 {
842 if (in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION))) {
843 self::$mode = $mode;
844 return true;
845 }
846 return false;
847 }
848
857 public static function isProfileIncomplete(
858 ilObjUser $a_user,
859 bool $a_include_udf = true,
860 bool $a_personal_data_only = true
861 ): bool {
862 global $DIC;
863
864 $ilSetting = $DIC['ilSetting'];
865
866 $user_settings_config = new ilUserSettingsConfig();
867
868 // standard fields
869 foreach (self::$user_field as $field => $definition) {
870 // only if visible in personal data
871 if ($a_personal_data_only && !$user_settings_config->isVisible($field)) {
872 continue;
873 }
874
875 if ($ilSetting->get("require_" . $field) && $definition["method"]) {
876 $value = $a_user->{$definition["method"]}();
877 if ($value == "") {
878 return true;
879 }
880 }
881 }
882
883 // custom fields
884 if ($a_include_udf) {
885 $user_defined_data = $a_user->getUserDefinedData();
886
887 $user_defined_fields = ilUserDefinedFields::_getInstance();
888 foreach ($user_defined_fields->getRequiredDefinitions() as $field => $definition) {
889 // only if visible in personal data
890 if ($a_personal_data_only && !$definition["visible"]) {
891 continue;
892 }
893
894 if (!($user_defined_data["f_" . $field] ?? false)) {
895 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
896 return true;
897 }
898 }
899 }
900
901 return false;
902 }
903
907 protected static function isEditableByUser(string $setting): bool
908 {
909 $user_settings_config = new ilUserSettingsConfig();
910 return $user_settings_config->isVisibleAndChangeable($setting);
911 }
912
916 public static function getIgnorableRequiredSettings(): array // Missing array type.
917 {
918 global $DIC;
919
920 $ilSetting = $DIC->settings();
921
922 $ignorableSettings = array();
923
924 foreach (self::$user_field as $field => $definition) {
925 // !!!username and password must not be ignored!!!
926 if ('username' == $field ||
927 'password' == $field) {
928 continue;
929 }
930
931 // Field is not required -> continue
932 if (!$ilSetting->get('require_' . $field)) {
933 continue;
934 }
935
936 if (self::isEditableByUser($field)) {
937 $ignorableSettings[] = $field;
938 }
939 }
940
941 return $ignorableSettings;
942 }
943}
const IL_CAL_DATE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupRegisterAllowed()
get all roles that are activated in user registration
User class.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
getFileUpload(string $a_field, ?string $a_index=null, ?string $a_sub_index=null)
Get file upload data.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjAuthSettingsGUI.
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
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.
Class ilUserProfile.
static isEditableByUser(string $setting)
Returns whether a profile setting is editable by an user in the profile gui.
getStandardFields()
Get standard user fields array.
getLocalUserAdministrationFields()
Get visible fields in local user administration.
static setMode(int $mode)
setAjaxCallback(string $a_href)
skipField(string $a_field)
Skip a field.
static userSettingVisible(string $a_setting)
Checks whether user setting is visible.
static array $user_field
static isProfileIncomplete(ilObjUser $a_user, bool $a_include_udf=true, bool $a_personal_data_only=true)
Check if all required personal data fields are set.
skipGroup(string $a_group)
Skip a group.
ilUserSettingsConfig $user_settings_config
addStandardFieldsToForm(ilPropertyFormGUI $a_form, ?ilObjUser $a_user=null, array $custom_fields=null)
Add standard fields to form.
static getIgnorableRequiredSettings()
Returns an array of all ignorable profiel fields.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isVisibleAndChangeable(string $field)
Is field visible and changeable by user?
isVisible(string $field)
Is setting visible to user?
global $DIC
Definition: feed.php:28
$keys
Definition: metadata.php:204
global $ilSetting
Definition: privfeed.php:17
$lng