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