ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\User\Profile\Visibility as ProfileVisibility;
29use ILIAS\UI\Factory as UIFactory;
30use ILIAS\UI\Renderer as UIRenderer;
32use Psr\Http\Message\ServerRequestInterface;
33
35{
36 public function __construct(
37 private readonly \ilLanguage $lng,
38 private readonly \ilCtrl $ctrl,
39 private readonly \ilAppEventHandler $event,
40 private readonly ServerRequestInterface $request,
41 private readonly \ilObjUser $user,
42 private readonly \ilSetting $settings,
43 private readonly \ilGlobalTemplateInterface $tpl,
44 private readonly UIFactory $ui_factory,
45 private readonly UIRenderer $ui_renderer,
46 private readonly SettingsImplementation $user_settings,
47 private readonly ProfileVisibility $profile_mode,
48 private readonly ChecklistStatus $checklist_status,
49 private readonly \ilSetting $chat_settings,
50 private readonly \ilSetting $notification_settings
51 ) {
52 }
53
54 public function executeCommand(): void
55 {
56 $cmd = $this->ctrl->getCmd('show') . 'Cmd';
57 $this->$cmd();
58 $this->tpl->printToStdout();
59 }
60
61 public function showCmd(
62 ?StandardForm $form = null
63 ): void {
64 $this->tpl->setContent(
65 $this->buildPrivacySettingsForm($form)
67 . $this->buildChatJsTemplate($this->tpl)
68 );
69 }
70
71 public function saveCmd(): void
72 {
73 $form = $this->initForm()->withRequest($this->request);
74 $form_data = [
75 'privacy' => $form->getData()
76 ];
77
78 $updated_user = $this->user_settings->saveForm(
79 $form_data,
80 [AvailablePages::PrivacySettings],
81 Context::User,
82 $this->user
83 );
84
85 $this->checklist_status->setStepSucessOnUser(
87 $updated_user
88 )->update();
89
90 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
91 $this->ctrl->redirectByClass(self::class, '');
92 }
93
94 private function buildPrivacySettingsForm(
95 ?StandardForm $form
96 ): string {
97 if ($form === null) {
98 $form = $this->initForm();
99 }
100 return $this->ui_renderer->render($form);
101 }
102
103 private function buildPublicProfilePresentation(): string
104 {
105 if ($this->profile_mode->isEnabled()) {
106 $pub_profile_legacy = $this->ui_factory->legacy()->content(
107 (new PublicProfileGUI(
108 $this->user->getId()
109 ))->getEmbeddable()
110 );
111 return $this->ui_renderer->render($this->ui_factory->panel()->standard(
112 $this->lng->txt('user_profile_preview'),
113 $pub_profile_legacy
114 ));
115 }
116
117 if (!$this->checklist_status->anyVisibilitySettings()) {
118 return $this->ui_renderer->render(
119 $this->ui_factory->messageBox()->info(
120 $this->lng->txt('usr_public_profile_disabled')
121 )
122 );
123 }
124
125 return '';
126 }
127
133 private function buildChatJsTemplate(
134 \ilGlobalTemplateInterface $global_template
135 ): string {
136 if (!$this->shouldShowOnScreenChatOptions()
137 || $this->chat_settings->get('enable_browser_notifications', '0') !== '1') {
138 return '';
139 }
140 $global_template->addJavaScript('assets/js/BrowserNotifications.min.js');
141 $this->lng->toJSMap([
142 'osc_browser_noti_no_permission_error' => $this->lng->txt('osc_browser_noti_no_permission_error'),
143 'osc_browser_noti_no_support_error' => $this->lng->txt('osc_browser_noti_no_support_error'),
144 'osc_browser_noti_req_permission_error' => $this->lng->txt('osc_browser_noti_req_permission_error'),
145 ], $global_template);
146
147 $tpl = new \ilTemplate('tpl.personal_chat_settings_form.html', true, true, 'components/ILIAS/Chatroom');
148 $tpl->setVariable('ALERT_IMAGE_SRC', \ilUtil::getImagePath('standard/icon_alert.svg'));
149 $tpl->setVariable('BROWSER_NOTIFICATION_TOGGLE_LABEL', $this->lng->txt('osc_enable_browser_notifications_label'));
150 return $tpl->get();
151 }
152
153 private function initForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
154 {
155 return $this->ui_factory->input()->container()->form()->standard(
156 $this->ctrl->getLinkTarget($this, 'save'),
157 $this->user_settings->buildFormInputs(
158 [AvailablePages::PrivacySettings],
159 Context::User,
160 $this->user
161 )
162 );
163 }
164
165 private function shouldShowOnScreenChatOptions(): bool
166 {
167 return $this->chat_settings->get('enable_osc', '0') &&
168 $this->settings->get('usr_settings_hide_chat_osc_accept_msg', '0') !== 1;
169 }
170
171 private function shouldShowChatTypingBroadcastOption(): bool
172 {
173 return $this->settings->get('usr_settings_hide_chat_broadcast_typing', '0') !== '1';
174 }
175
176 public function shouldDisplayChatSection(): bool
177 {
178 return (bool) $this->chat_settings->get('chat_enabled', '0');
179 }
180
181 private function shouldShowNotificationOptions(): bool
182 {
183 return (bool) $this->notification_settings->get('osd_play_sound', '0');
184 }
185
186 public function shouldDisplayNotificationSection(): bool
187 {
188 return (bool) $this->notification_settings->get('enable_osd', '0');
189 }
190}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Definition: UI.php:24
buildChatJsTemplate(\ilGlobalTemplateInterface $global_template)
showCmd(?StandardForm $form=null)
__construct(private readonly \ilLanguage $lng, private readonly \ilCtrl $ctrl, private readonly \ilAppEventHandler $event, private readonly ServerRequestInterface $request, private readonly \ilObjUser $user, private readonly \ilSetting $settings, private readonly \ilGlobalTemplateInterface $tpl, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly SettingsImplementation $user_settings, private readonly ProfileVisibility $profile_mode, private readonly ChecklistStatus $checklist_status, private readonly \ilSetting $chat_settings, private readonly \ilSetting $notification_settings)
buildPrivacySettingsForm(?StandardForm $form)
GUI class for public user profile presentation.
Personal profile publishing mode of a user.
Definition: Visibility.php:30
Global event handler.
Class ilCtrl provides processing control methods.
language handling
User class.
ILIAS Setting Class.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This describes a standard form.
Definition: Standard.php:29
An entity that renders components to a string output.
Definition: Renderer.php:31
get(string $class_name)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))