ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.PersonalProfileGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\User\Profile;
22
25use ILIAS\User\Privacy\SettingsGUI as PrivacySettingsGUI;
26use ILIAS\User\Profile\ChangeMail\Repository as ChangeMailRepository;
27use ILIAS\User\Profile\ChangeMail\DBRepository as ChangeMailDBRepository;
28use ILIAS\User\Profile\ChangeMail\Status as ChangeMailStatus;
29use ILIAS\User\Profile\ChangeMail\Mail as ChangeMailMail;
30use ILIAS\User\Profile\Prompt\Repository as PromptRepository;
31use ILIAS\User\Profile\Fields\Field as ProfileField;
38use ILIAS\User\Settings\Settings as UserSettings;
41use ILIAS\UI\Factory as UIFactory;
42use ILIAS\UI\Renderer as UIRenderer;
44use ILIAS\Refinery\Factory as Refinery;
45use ILIAS\StaticURL\Services as StaticUrlServices;
46use ILIAS\HTTP\Services as HTTP;
47
56{
57 private const PERSONAL_DATA_FORM_ID = 'pd';
58 private const PUBLISH_SETTINGS_PREFIX = 'chk_';
59 public const CHANGE_EMAIL_CMD = 'changeEmail';
60
61 private \ilGlobalTemplateInterface $tpl;
62 private \ilAppEventHandler $event;
63 private \ilPropertyFormGUI $form;
64 private \ilSetting $settings;
65 private \ilObjUser $user;
66 private \ilAuthSession $auth_session;
67 private StaticUrlServices $static_url;
68 private Language $lng;
69 private \ilCtrl $ctrl;
70 private \ilTabsGUI $tabs;
71 private \ilToolbarGUI $toolbar;
72 private \ilHelpGUI $help;
73 private HTTP $http;
74 private \ilErrorHandling $error_handler;
77 private UIFactory $ui_factory;
78 private UIRenderer $ui_renderer;
80
81 private ChangeMailRepository $change_mail_token_repo;
82 private PromptRepository $prompt_repository;
86
87 private \ilLogger $logger;
89
91
92 public function __construct()
93 {
95 global $DIC;
96
97 $this->tabs = $DIC['ilTabs'];
98 $this->toolbar = $DIC['ilToolbar'];
99 $this->help = $DIC['ilHelp'];
100 $this->http = $DIC['http'];
101 $this->user = $DIC['ilUser'];
102 $this->auth_session = $DIC['ilAuthSession'];
103 $this->lng = $DIC['lng'];
104 $this->settings = $DIC['ilSetting'];
105 $this->tpl = $DIC['tpl'];
106 $this->ctrl = $DIC['ilCtrl'];
107 $this->error_handler = $DIC['ilErr'];
108 $this->event = $DIC['ilAppEventHandler'];
109 $this->ui_factory = $DIC['ui.factory'];
110 $this->ui_renderer = $DIC['ui.renderer'];
111 $this->uploads = $DIC['upload'];
112 $this->ui_factory = $DIC['ui.factory'];
113 $this->ui_renderer = $DIC['ui.renderer'];
114 $this->refinery = $DIC['refinery'];
115 $this->auth_session = $DIC['ilAuthSession'];
116 $this->static_url = $DIC['static_url'];
117
118 $this->logger = \ilLoggerFactory::getLogger('user');
119 $local_dic = LocalDIC::dic();
120 $this->profile = $local_dic[Profile::class];
121 $this->user_settings = $local_dic[UserSettings::class];
122 $this->change_mail_token_repo = new ChangeMailDBRepository(
123 $DIC['ilDB'],
124 $this->settings
125 );
126 $this->checklist = new ChecklistGUI();
127 $this->checklist_status = new ChecklistStatus(
128 $this->lng,
129 $this->settings,
130 $this->user,
131 new Visibility($this->lng, $this->settings, $this->user)
132 );
133 $this->prompt_repository = new PromptRepository(
134 $DIC['ilDB'],
135 $this->lng,
136 new \ilSetting('user')
137 );
138 $this->profile_request = new GUIRequest(
139 $this->http,
140 $DIC['refinery']
141 );
142
143 $this->lng->loadLanguageModule('jsmath');
144 $this->lng->loadLanguageModule('awrn');
145 $this->lng->loadLanguageModule('pd');
146 $this->lng->loadLanguageModule('user');
147 $this->lng->loadLanguageModule('maps');
148 $this->ctrl->saveParameter($this, 'prompted');
149 }
150
151 public function executeCommand(): void
152 {
153 $next_class = $this->ctrl->getNextClass();
154
155 switch ($next_class) {
156 case strtolower(PublicProfileGUI::class):
157 $pub_profile_gui = new PublicProfileGUI($this->user->getId());
158 $pub_profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showPersonalData'));
159 $this->ctrl->forwardCommand($pub_profile_gui);
160 $this->tpl->printToStdout();
161 break;
162
163 case strtolower(PrivacySettingsGUI::class):
164 $this->setHeader();
165 $this->setTabs();
166 $this->tabs->activateTab('visibility_settings');
168 $this->ctrl->forwardCommand(
169 new PrivacySettingsGUI(
170 $this->lng,
171 $this->ctrl,
172 $this->event,
173 $this->http->request(),
174 $this->user,
175 $this->settings,
176 $this->tpl,
177 $this->ui_factory,
178 $this->ui_renderer,
179 $this->user_settings,
180 new Visibility(
181 $this->lng,
182 $this->settings,
183 $this->user
184 ),
185 $this->checklist_status,
186 new \ilSetting('chatroom'),
187 new \ilSetting('notifications')
188 )
189 );
190 break;
191
192 case strtolower(\ilLegalDocumentsAgreementGUI::class):
193 $this->ctrl->forwardCommand(new \ilLegalDocumentsAgreementGUI());
194 $this->tpl->printToStdout();
195 break;
196
197 case strtolower(\ilLegalDocumentsWithdrawalGUI::class):
198 $this->ctrl->forwardCommand(new \ilLegalDocumentsWithdrawalGUI());
199 $this->tpl->printToStdout();
200 break;
201
202 default:
203 $this->setTabs();
204 $cmd = $this->ctrl->getCmd('showPersonalData');
205 $this->$cmd();
206 break;
207 }
208 }
209
215 public function showProfile(): void
216 {
217 $this->showPersonalData();
218 }
219
220 // init sub tabs
221 public function setTabs(): void
222 {
223 $this->help->setScreenIdComponent('user');
224
225 // personal data
226 $this->tabs->addTab(
227 'personal_data',
228 $this->lng->txt('user_profile_data'),
229 $this->ctrl->getLinkTarget($this, 'showPersonalData')
230 );
231
232 // publishing options
233 $this->tabs->addTab(
234 'public_profile',
235 $this->lng->txt('user_publish_options'),
236 $this->ctrl->getLinkTarget($this, 'showPublicProfile')
237 );
238
239 // visibility settings
240 $txt_visibility = $this->checklist_status->anyVisibilitySettings()
241 ? $this->lng->txt('user_visibility_settings')
242 : $this->lng->txt('preview');
243 $this->tabs->addTab(
244 'visibility_settings',
245 $txt_visibility,
246 $this->ctrl->getLinkTargetByClass(PrivacySettingsGUI::class, '')
247 );
248
249 // export
250 $this->tabs->addTab(
251 'export',
252 $this->lng->txt('export') . '/' . $this->lng->txt('import'),
253 $this->ctrl->getLinkTarget($this, 'showExportImport')
254 );
255 }
256
257 public function setHeader(): void
258 {
259 $this->tpl->setTitle($this->lng->txt('personal_profile'));
260 }
261
262 public function showPersonalData(
263 bool $a_no_init = false
264 ): void {
265 $this->tabs->activateTab('personal_data');
266
267 $this->setHeader();
268
270
271 if (!$a_no_init) {
272 $this->initPersonalDataForm();
273 // catch feedback message
274 if ($this->user->getProfileIncomplete()) {
275 $this->tpl->setOnScreenMessage('info', $this->lng->txt('profile_incomplete'));
276 }
277 }
278
279 $modal = '';
280 if ($this->email_change_confirmation_modal !== null) {
281 $modal = $this->ui_renderer->render($this->email_change_confirmation_modal);
282 }
283
284 $this->tpl->setContent($this->buildInfoText() . $this->form->getHTML() . $modal);
285
286 $this->tpl->printToStdout();
287 }
288
289 private function buildInfoText(): string
290 {
291 $change_mail_info = '';
292 if ($this->change_mail_token_repo->hasUserValidEmailConfirmationToken($this->user)) {
293 $change_mail_info = $this->lng->txt('change_email_info_message');
294 }
295
296 $it = '';
297 if ($this->profile_request->getPrompted() === 1) {
298 $it = $this->prompt_repository->getSettings()->getPromptText($this->user->getLanguage());
299 }
300 if ($it === '') {
301 $it = $this->prompt_repository->getSettings()->getInfoText($this->user->getLanguage());
302 }
303 if (trim($it) === '') {
304 return $change_mail_info === ''
305 ? ''
306 : $this->ui_renderer->render($this->ui_factory->messageBox()->info($change_mail_info));
307 }
308
309 if ($change_mail_info !== '') {
310 $it .= '<br>' . $change_mail_info;
311 }
312
313 $pub_prof = in_array($this->user->getPref('public_profile'), ['y', 'n', 'g'])
314 ? $this->user->getPref('public_profile')
315 : 'n';
316 $box = $this->ui_factory->messageBox()->info($it);
317 if ($pub_prof === 'n') {
318 $box = $box->withLinks(
319 [$this->ui_factory->link()->standard(
320 $this->lng->txt('user_make_profile_public'),
321 $this->ctrl->getLinkTarget($this, 'showPublicProfile')
322 )]
323 );
324 }
325 return $this->ui_renderer->render($box);
326 }
327
328 public function initPersonalDataForm(): void
329 {
330 $this->form = new \ilPropertyFormGUI();
331 $this->form->setFormAction($this->ctrl->getFormAction($this));
332 $this->form->setId(self::PERSONAL_DATA_FORM_ID);
333
334 $this->form = $this->profile->addFieldsToForm($this->form, Context::User, true, $this->user);
335
336 $this->form->addCommandButton('savePersonalData', $this->lng->txt('user_save_continue'));
337 }
338
339 public function savePersonalData(): void
340 {
341 $this->initPersonalDataForm();
342 $this->uploads->process();
343
344 if (!$this->form->checkInput()
345 || !$this->emailCompletionForced()
346 && $this->emailChanged()
347 && $this->addEmailChangeModal()
348 || $this->loginChanged() && !$this->updateLoginOrSetErrorMessages()) {
349 $this->form->setValuesByPost();
350 $this->profile->tempStorePicture($this->form);
351 $this->showPersonalData(true);
352 return;
353 }
354
355 $this->addDataFromFormToUser();
356
357 $this->user = $this->checklist_status->setStepSucessOnUser(
359 $this->user
360 );
361 $this->user->update();
362
363 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
364 $this->ctrl->redirect($this, 'showPublicProfile');
365 }
366
367 private function emailChanged(): bool
368 {
369 $identifier_email = $this->profile->getFieldByClass(Email::class)->getIdentifier();
370 $email_input = $this->form->getItemByPostVar($identifier_email);
371 if ($email_input !== null && !$email_input->getDisabled()
372 && $this->form->getInput($identifier_email) !== $this->user->getEmail()) {
373 return true;
374 }
375
376 return false;
377 }
378
379 private function emailCompletionForced(): bool
380 {
381 $current_email = $this->user->getEmail();
382 if (
383 $this->user->getProfileIncomplete()
384 && $this->profile->getFieldByClass(Email::class)->isRequired()
385 && ($current_email === null || $current_email === '')
386 ) {
387 return true;
388 }
389
390 return false;
391 }
392
393 private function addEmailChangeModal(): bool
394 {
395 $form_id = 'form_' . self::PERSONAL_DATA_FORM_ID;
396
397 $message = $this->lng->txt('confirm_logout_for_email_change');
398 if ((int) $this->settings->get('new_registration_type', '1') === \ilRegistrationSettings::IL_REG_ACTIVATION) {
399 $message .= '<br>' . $this->lng->txt('confirm_logout_for_email_change_with_confirmation');
400 }
401
402 $modal = $this->ui_factory->modal()->interruptive(
403 $this->lng->txt('confirm'),
404 $message,
405 ''
406 )->withActionButtonLabel($this->lng->txt('change'));
407 $this->email_change_confirmation_modal = $modal->withOnLoad($modal->getShowSignal())
408 ->withAdditionalOnLoadCode(
409 static function ($id) use ($form_id) {
410 return "var button = {$id}.querySelector('input[type=\"submit\"]'); "
411 . "button.addEventListener('click', (e) => {e.preventDefault();"
412 . "document.getElementById('{$form_id}').submit();});";
413 }
414 );
415
416 $this->form->setFormAction($this->ctrl->getFormActionByClass(self::class, 'goToEmailConfirmation'));
417 return true;
418 }
419
420 private function loginChanged(): bool
421 {
422 if ($this->profile->userFieldEditableByUser('username')
423 && $this->form->getInput('username') !== $this->user->getLogin()) {
424 return true;
425 }
426
427 return false;
428 }
429
430 private function updateLoginOrSetErrorMessages(): bool
431 {
432 $login = $this->form->getInput('username');
433 if ($login === '' || !\ilUtil::isLogin($login)) {
434 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
435 $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('login_invalid'));
436 return false;
437 }
438
439 if (\ilObjUser::_loginExists($login, $this->user->getId())) {
440 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
441 $this->form->getItemByPostVar('username')->setAlert($this->lng->txt('loginname_already_exists'));
442 return false;
443 }
444
445 try {
446 $this->user->updateLogin($login, Context::User);
447 return true;
448 } catch (\ilUserException $e) {
449 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
450 $this->form->getItemByPostVar('username')->setAlert($e->getMessage());
451 return false;
452 }
453 }
454
455 public function goToEmailConfirmation(): void
456 {
457 $this->initPersonalDataForm();
458 if (!$this->form->checkInput()
459 || $this->loginChanged() && !$this->updateLoginOrSetErrorMessages()) {
460 $this->form->setValuesByPost();
461 $this->showPersonalData(true);
462 return;
463 }
464 $this->addDataFromFormToUser([Email::class]);
465 $this->user->update();
466
468 $this->auth_session->logout();
469 session_unset();
470 $token = $this->change_mail_token_repo->getNewTokenForUser(
471 $this->user,
472 $this->form->getInput(
473 $this->profile->getFieldByClass(Email::class)->getIdentifier()
474 ),
475 time()
476 );
477 $this->ctrl->redirectToURL(
478 $token->getUriForStatus($this->static_url->builder())->__toString()
479 );
480 }
481
482 private function addDataFromFormToUser(
483 array $skip_fields = []
484 ): void {
485 $this->user = $this->profile->addFormValuesToUser($this->form, Context::User, $this->user, $skip_fields);
486 $this->user->setProfileIncomplete(false);
487
488 $this->user->setTitle($this->user->getFullname());
489 $this->user->setDescription($this->user->getEmail());
490 }
491
492 public function changeEmail(): void
493 {
494 $token = $this->change_mail_token_repo->getTokenForTokenString(
495 $this->profile_request->getToken(),
496 $this->user
497 );
498
499 if ($token === null) {
500 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('email_could_not_be_changed'));
501 $this->showPublicProfile();
502 return;
503 }
504
505 if ($token->getStatus() === ChangeMailStatus::Login
506 && (int) $this->settings->get('new_registration_type', '1') === \ilRegistrationSettings::IL_REG_ACTIVATION) {
507 (new ChangeMailMail(
508 $this->user,
509 $this->change_mail_token_repo->moveToNextStep($token, time())
510 ->getUriForStatus($this->static_url->builder()),
511 $this->lng,
512 $this->logger
513 ))->send($token->getNewEmail(), ChangeMailStatus::EmailConfirmation->getValidity($this->settings));
514 $this->tpl->setOnScreenMessage('info', $this->lng->txt('change_email_email_sent'));
515 $this->showPublicProfile();
516 return;
517 }
518
519 $this->user->setEmail($token->getNewEmail());
520 $this->user->update();
521 $this->change_mail_token_repo->deleteEntryByToken($token->getToken());
522 $this->change_mail_token_repo->deleteExpiredEntries();
523
524 $this->tpl->setOnScreenMessage(
525 'success',
526 $this->lng->txt('saved_successfully')
527 );
528 $this->showPublicProfile();
529 return;
530 }
531
532 public function showPublicProfile(bool $a_no_init = false): void
533 {
534 $this->tabs->activateTab('public_profile');
535 $this->showChecklist(ChecklistStatus::STEP_PUBLISH_OPTIONS);
536
537 $this->setHeader();
538
539 if (!$a_no_init) {
540 $this->initPublicProfileForm();
541 }
542
543 $this->tpl->setContent($this->form->getHTML());
544 $this->tpl->printToStdout();
545 }
546
547 private function getProfilePortfolio(): ?int
548 {
549 if ($this->settings->get('user_portfolios')) {
550 return \ilObjPortfolio::getDefaultPortfolio($this->user->getId());
551 }
552 return null;
553 }
554
555 private function initPublicProfileForm(): void
556 {
557 $this->form = new \ilPropertyFormGUI();
558
559 $this->form->setTitle($this->lng->txt('user_publish_options'));
560 $this->form->setDescription($this->lng->txt('user_public_profile_info'));
561 $this->form->setFormAction($this->ctrl->getFormAction($this));
562
563 $portfolio_id = $this->getProfilePortfolio();
564
565 if (!$portfolio_id) {
566 // Activate public profile
567 $radg = new \ilRadioGroupInputGUI($this->lng->txt('user_activate_public_profile'), 'public_profile');
568 $info = $this->lng->txt('user_activate_public_profile_info');
569 $radg->setValue(
570 (new Visibility($this->lng, $this->settings, $this->user))->getMode()
571 );
572 $op1 = new \ilRadioOption($this->lng->txt('usr_public_profile_disabled'), 'n', $this->lng->txt('usr_public_profile_disabled_info'));
573 $radg->addOption($op1);
574 $op2 = new \ilRadioOption($this->lng->txt('usr_public_profile_logged_in'), 'y');
575 $radg->addOption($op2);
576 if ($this->settings->get('enable_global_profiles')) {
577 $op3 = new \ilRadioOption($this->lng->txt('usr_public_profile_global'), 'g');
578 $radg->addOption($op3);
579 }
580 $this->form->addItem($radg);
581
582 // #11773
583 if ($this->settings->get('user_portfolios')) {
584 // #10826
585 $href = $this->ctrl->getLinkTargetByClass(\ilDashboardGUI::class, 'jumpToPortfolio');
586 $prtf = '<br />' . $this->lng->txt('user_profile_portfolio');
587 $prtf .= '<br /><a href="' . $href . '">&raquo; ' .
588 $this->lng->txt('user_portfolios') . '</a>';
589 $info .= $prtf;
590 }
591
592 $radg->setInfo($info);
593 } else {
594 $this->ctrl->setParameterByClass(\ilDashboardGUI::class, 'prt_id', $portfolio_id);
595 $href = $this->ctrl->getLinkTargetByClass(\ilDashboardGUI::class, 'jumpToPortfolio');
596 $this->ctrl->clearParameterByClass(\ilDashboardGUI::class, 'prt_id');
597 $prtf = $this->lng->txt('user_profile_portfolio_selected');
598 $prtf .= '<br /><a href="' . $href . '">&raquo; ' .
599 $this->lng->txt('portfolio') . '</a>';
600
601 $info = new \ilCustomInputGUI($this->lng->txt('user_activate_public_profile'));
602 $info->setHtml($prtf);
603 $this->form->addItem($info);
604 $this->showPublicProfileFields($this->form);
605 }
606
607 if (isset($op2)) {
608 $this->showPublicProfileFields($this->form, null, $op2, false, '-1');
609 }
610 if (isset($op3)) {
611 $this->showPublicProfileFields($this->form, null, $op3, false, '-2');
612 }
613 $this->form->setForceTopButtons(true);
614 $this->form->addCommandButton('savePublicProfile', $this->lng->txt('user_save_continue'));
615 }
616
617 public function showPublicProfileFields(
618 \ilPropertyFormGUI $form,
619 ?array $prefs = null,
620 \ilRadioOption|\ilCheckboxGroupInputGUI|null $parent = null,
621 bool $anonymized = false,
622 string $key_suffix = ''
623 ): void {
624 foreach ($this->profile->getVisibleFields(
625 Context::User,
626 null,
627 [],
628 [FirstName::class, LastName::class, Alias::class, OrganisationalUnits::class, Roles::class]
629 ) as $field) {
630 $value = $field->retrieveValueFromUser($this->user);
631 if (!$anonymized && ($value === '' || $value === '-' || $value === null)) {
632 continue;
633 }
634 if ($anonymized) {
635 $value = null;
636 }
637
638 if ($field->isVisibleToUser()) {
639 // #18795 - we should use ilUserProfile
640 switch ($field->getIdentifier()) {
641 case 'avatar':
642 $caption = $this->lng->txt('personal_picture');
643 $value = "<img src='{$value}' alt='{$this->lng->txt('user_avatar')}' />";
644 break;
645
646 default:
647 $caption = $field->getLabel($this->lng);
648 }
649 $cb = new \ilCheckboxInputGUI($caption, self::PUBLISH_SETTINGS_PREFIX . $field->getIdentifier() . $key_suffix);
650 $cb->setChecked(
651 $prefs === null
652 ? $field->isPublishedByUser($this->user)
653 : $prefs["public_{$field->getIdentifier()}"] ?? false
654 );
655
656 $cb->setOptionTitle(
657 $this->refinery->byTrying([
658 $this->refinery->kindlyTo()->string(),
659 $this->refinery->custom()->transformation(
660 function (mixed $v): string {
661 return array_reduce(
662 $this->refinery->kindlyTo()->listOf(
663 $this->refinery->kindlyTo()->string()
664 )->transform($v),
665 static fn(string $c, string $v): string => $c === ''
666 ? $v : "{$c}, {$v}",
667 ''
668 );
669 }
670 ),
671 $this->refinery->always('')
672 ])->transform($value)
673 );
674
675 if (!$parent) {
676 $form->addItem($cb);
677 } else {
678 $parent->addSubItem($cb);
679 }
680 }
681 }
682
683 if (!$anonymized) {
685 if ($handler->isActive()) {
686 $badge_options = [];
687
688 foreach (\ilBadgeAssignment::getInstancesByUserId($this->user->getId()) as $ass) {
689 // only active
690 if ($ass->getPosition()) {
691 $badge = new \ilBadge($ass->getBadgeId());
692 $badge_options[] = $badge->getTitle();
693 }
694 }
695
696 if (count($badge_options) > 1) {
697 $badge_order = new \ilNonEditableValueGUI($this->lng->txt('obj_bdga'), 'bpos' . $key_suffix);
698 $badge_order->setMultiValues($badge_options);
699 $badge_order->setValue(array_shift($badge_options));
700 $badge_order->setMulti(true, true, false);
701
702 if (!$parent) {
703 $form->addItem($badge_order);
704 } else {
705 $parent->addSubItem($badge_order);
706 }
707 }
708 }
709 }
710
711 // permalink
712 $ne = new \ilNonEditableValueGUI($this->lng->txt('perma_link'), '');
713 $ne->setValue(\ilLink::_getLink($this->user->getId(), 'usr'));
714 if (!$parent) {
715 $form->addItem($ne);
716 } else {
717 $parent->addSubItem($ne);
718 }
719 }
720
721 public function savePublicProfile(): void
722 {
723 $this->initPublicProfileForm();
724 if (!$this->form->checkInput()) {
725 $this->form->setValuesByPost();
726 $this->tpl->showPublicProfile(true);
727 }
728
729 if ($this->form->getInput('public_profile') !== '') {
730 $this->user->setPref('public_profile', $this->form->getInput('public_profile'));
731 }
732
733 $this->user = array_reduce(
734 $this->profile->getVisibleFields(Context::User, $this->user),
735 fn(\ilObjUser $c, ProfileField $v): \ilObjUser =>
736 $v->setPublishedOnUser($c, $this->getPublishedFromPost($v->getIdentifier())),
737 $this->user
738 );
739
740 if (\ilBadgeHandler::getInstance()->isActive()) {
741 $badge_positions = $this->form->getInput('bpos' . $this->buildKeySuffix()) ?? [];
742 if (is_array($badge_positions) && $badge_positions !== []) {
743 \ilBadgeAssignment::updatePositions($this->user->getId(), $badge_positions);
744 }
745 }
746
747 $this->user = $this->checklist_status->setStepSucessOnUser(
748 ChecklistStatus::STEP_PUBLISH_OPTIONS,
749 $this->user
750 );
751 $this->user->update();
752
753 // update lucene index
754 \ilLuceneIndexer::updateLuceneIndex([(int) $this->user->getId()]);
755 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
756
757 if (\ilSession::get('orig_request_target')) {
758 $target = \ilSession::get('orig_request_target');
759 \ilSession::set('orig_request_target', '');
760 \ilUtil::redirect($target);
761 }
762
763 $this->ctrl->redirectByClass([self::class, PrivacySettingsGUI::class], '');
764 }
765
766 public function showExportImport(): void
767 {
768 $this->tabs->activateTab('export');
769 $this->setHeader();
770
771 $button = $this->ui_factory->link()->standard(
772 $this->lng->txt('pd_export_profile'),
773 $this->ctrl->getLinkTarget($this, 'exportPersonalData')
774 );
775 $this->toolbar->addStickyItem($button);
776
777 $exp_file = $this->user->getPersonalDataExportFile();
778 if ($exp_file != '') {
779 $this->toolbar->addSeparator();
780 $this->toolbar->addComponent(
781 $this->ui_factory->link()->standard(
782 $this->lng->txt("pd_download_last_export_file"),
783 $this->ctrl->getLinkTarget($this, "downloadPersonalData")
784 )
785 );
786 }
787
788 $this->toolbar->addSeparator();
789 $this->toolbar->addComponent(
790 $this->ui_factory->link()->standard(
791 $this->lng->txt("pd_import_personal_data"),
792 $this->ctrl->getLinkTarget($this, "importPersonalDataSelection")
793 )
794 );
795
796 $this->tpl->printToStdout();
797 }
798
799 public function exportPersonalData(): void
800 {
801 $this->user->exportPersonalData();
802 $this->user->sendPersonalDataFile();
803 $this->ctrl->redirect($this, 'showExportImport');
804 }
805
809 public function downloadPersonalData(): void
810 {
811 $this->user->sendPersonalDataFile();
812 }
813
814 public function importPersonalDataSelection(): void
815 {
816 $this->tabs->activateTab('export');
817 $this->setHeader();
818
819 $this->initPersonalDataImportForm();
820
821 $this->tpl->setContent($this->form->getHTML());
822 $this->tpl->printToStdout();
823 }
824
825 public function initPersonalDataImportForm(): void
826 {
827 $this->form = new \ilPropertyFormGUI();
828
829 // input file
830 $fi = new \ilFileInputGUI($this->lng->txt('file'), 'file');
831 $fi->setRequired(true);
832 $fi->setSuffixes(['zip']);
833 $this->form->addItem($fi);
834
835 // profile data
836 $cb = new \ilCheckboxInputGUI($this->lng->txt('pd_profile_data'), 'profile_data');
837 $this->form->addItem($cb);
838
839 // settings
840 $cb = new \ilCheckboxInputGUI($this->lng->txt('settings'), 'settings');
841 $this->form->addItem($cb);
842
843 // personal notes
844 $cb = new \ilCheckboxInputGUI($this->lng->txt('notes'), 'notes');
845 $this->form->addItem($cb);
846
847 // calendar entries
848 $cb = new \ilCheckboxInputGUI($this->lng->txt('pd_private_calendars'), 'calendar');
849 $this->form->addItem($cb);
850
851 $this->form->addCommandButton('importPersonalData', $this->lng->txt('import'));
852 $this->form->addCommandButton('showExportImport', $this->lng->txt('cancel'));
853
854 $this->form->setTitle($this->lng->txt('pd_import_personal_data'));
855 $this->form->setFormAction($this->ctrl->getFormAction($this));
856 }
857
858 public function importPersonalData(): void
859 {
860 $this->initPersonalDataImportForm();
861 if ($this->form->checkInput()) {
862 $this->user->importPersonalData(
863 $_FILES['file'],
864 (bool) $this->form->getInput('profile_data'),
865 (bool) $this->form->getInput('settings'),
866 (bool) $this->form->getInput('notes'),
867 (bool) $this->form->getInput('calendar')
868 );
869 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
870 $this->ctrl->redirect($this, '');
871 } else {
872 $this->tabs->activateTab('export');
873 $this->setHeader();
874 $this->form->setValuesByPost();
875 $this->tpl->setContent($this->form->getHTML());
876 $this->tpl->printToStdout();
877 }
878 }
879
880 private function showChecklist(int $active_step): void
881 {
882 $main_tpl = $this->tpl;
883 $main_tpl->setRightContent($this->checklist->render($active_step));
884 }
885
886 private function getPublishedFromPost(string $identifier): bool
887 {
888 $key = self::PUBLISH_SETTINGS_PREFIX . $identifier . $this->buildKeySuffix();
889
890 if (!$this->http->wrapper()->post()->has($key)) {
891 return false;
892 }
893
894 return $this->http->wrapper()->post()->retrieve(
895 $key,
896 $this->refinery->kindlyTo()->string()
897 ) === '1';
898 }
899
900 private function buildKeySuffix(): string
901 {
902 switch ($this->form->getInput('public_profile')) {
903 case 'y':
904 return '-1';
905 case 'g':
906 return '-2';
907 default:
908 return '';
909 }
910 }
911}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
downloadPersonalData()
Download personal data export file.
showPublicProfileFields(\ilPropertyFormGUI $form, ?array $prefs=null, \ilRadioOption|\ilCheckboxGroupInputGUI|null $parent=null, bool $anonymized=false, string $key_suffix='')
GUI class for public user profile presentation.
Personal profile publishing mode of a user.
Definition: Visibility.php:30
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
static updatePositions(int $a_user_id, array $a_positions)
static getInstancesByUserId(int $a_user_id)
This class represents a property in a property form.
static getLogger(string $a_component_id)
Get component logger.
static updateLuceneIndex(array $a_obj_ids)
Update lucene index.
User class.
static _loginExists(string $a_login, int $a_user_id=0)
This class represents a property form user interface.
This class represents an option in a radio group.
static get(string $a_var)
static setClosingContext(int $a_context)
set closing context (for statistics)
static set(string $a_var, $a_val)
Set a value.
const int SESSION_CLOSE_USER
ILIAS Setting Class.
static isLogin(string $a_login)
static redirect(string $a_script)
$c
Definition: deliver.php:25
$info
Definition: entry_point.php:21
An entity that renders components to a string output.
Definition: Renderer.php:31
addFormValuesToUser(\ilPropertyFormGUI $form, Context $context, \ilObjUser $current_user)
static http()
Fetches the global http state from ILIAS.
form(?array $class_path, string $cmd, string $submit_caption="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$handler
Definition: oai.php:29
global $DIC
Definition: shib_login.php:26
$token
Definition: xapitoken.php:67
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:97