ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilUserPrivacySettingsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
12
16 protected $lng;
17
21 protected $ctrl;
22
26 protected $main_tpl;
27
32
36 protected $ui;
37
41 protected $user;
42
46 protected $settings;
47
51 protected $request;
52
57
61 protected $profile_mode;
62
66 public function __construct()
67 {
68 global $DIC;
69
70 $this->main_tpl = $DIC->ui()->mainTemplate();
71 $this->lng = $DIC->language();
72 $this->ctrl = $DIC->ctrl();
73 $this->lng->loadLanguageModule("user");
74 $this->ui = $DIC->ui();
75 $this->user = $DIC->user();
76
77 $this->request = $DIC->http()->request();
78
79 $this->user_settings_config = new ilUserSettingsConfig();
80 $this->settings = $DIC->settings();
81 $this->checklist_status = new ilProfileChecklistStatus();
82 $this->profile_mode = new ilPersonalProfileMode($this->user, $this->settings);
83 }
84
88 public function executeCommand()
89 {
90 $next_class = $this->ctrl->getNextClass();
91
92 switch ($next_class) {
93 default:
94 $cmd = $this->ctrl->getCmd("showPrivacySettings");
95 $this->$cmd();
96 break;
97 }
98 $this->main_tpl->printToStdout();
99 }
100
101
102 //
103 //
104 // GENERAL SETTINGS FORM
105 //
106 //
107
112 public function workWithUserSetting(string $setting) : bool
113 {
114 return $this->user_settings_config->isVisibleAndChangeable($setting);
115 }
116
121 public function userSettingVisible(string $setting) : bool
122 {
123 return $this->user_settings_config->isVisible($setting);
124 }
125
129 public function showPrivacySettings($form = null)
130 {
132 $ui = $this->ui;
135
136 $html = "";
137 if ($this->checklist_status->anyVisibilitySettings()) {
138 if (is_null($form)) {
139 $form = $this->initPrivacySettingsForm();
140 }
141 $html = $ui->renderer()->render([$form]);
142 }
143
144 $pub_profile = new ilPublicUserProfileGUI($user->getId());
145 if ($this->profile_mode->isEnabled()) {
146 $html .= $pub_profile->getEmbeddable();
147 } else {
148 if (!$this->checklist_status->anyVisibilitySettings()) {
149 $html .= $ui->renderer()->render([$ui->factory()->messageBox()->info($lng->txt("usr_public_profile_disabled"))]);
150 }
151 }
152
153 $main_tpl->setContent($html);
154 }
155
161 protected function isAwarnessSettingVisible() : bool
162 {
163 $awrn_set = new ilSetting("awrn");
164 if ($awrn_set->get("awrn_enabled", false) && $this->userSettingVisible("hide_own_online_status")) {
165 return true;
166 }
167 return false;
168 }
169
175 protected function isContactSettingVisible() : bool
176 {
177 if (ilBuddySystem::getInstance()->isEnabled() && $this->userSettingVisible('bs_allow_to_contact_me')) {
178 return true;
179 }
180 return false;
181 }
182
183
188 public function initPrivacySettingsForm()
189 {
190 $ui = $this->ui;
191 $f = $ui->factory();
196
197 $fields = [];
198
199 // hide_own_online_status
200 if ($this->isAwarnessSettingVisible()) {
201 $lng->loadLanguageModule("awrn");
202
203 $default = ($this->settings->get('hide_own_online_status') == "n")
204 ? $this->lng->txt("user_awrn_show")
205 : $this->lng->txt("user_awrn_hide");
206
207 $options = array(
208 "x" => $this->lng->txt("user_awrn_default")." (".$default.")",
209 "n" => $this->lng->txt("user_awrn_show"),
210 "y" => $this->lng->txt("user_awrn_hide"));
211 $val = $user->prefs["hide_own_online_status"];
212 if ($val == "") {
213 $val = "x";
214 }
215 $fields["hide_own_online_status"] = $f->input()->field()->select(
216 $lng->txt("awrn_user_show"),
217 $options,
218 $lng->txt("awrn_hide_from_awareness_info"))
219 ->withValue($val)
220 ->withRequired(true)
221 ->withDisabled($settings->get("usr_settings_disable_hide_own_online_status")
222 );
223 }
224
225 // allow to contact me
226 if ($this->isContactSettingVisible()) {
227 $lng->loadLanguageModule('buddysystem');
228 $fields["bs_allow_to_contact_me"] = $f->input()->field()->checkbox(
229 $lng->txt("buddy_allow_to_contact_me"),
230 $lng->txt("buddy_allow_to_contact_me_info")
231 )
232 ->withValue($user->prefs['bs_allow_to_contact_me'] == 'y')
233 ->withDisabled($settings->get('usr_settings_disable_bs_allow_to_contact_me'));
234 }
235
236 // section
237 $section1 = $f->input()->field()->section($fields, $lng->txt("user_visibility_settings"));
238
239 $form_action = $ctrl->getLinkTarget($this, "savePrivacySettings");
240 return $f->input()->container()->form()->standard($form_action, ["sec" => $section1]);
241 }
242
246 public function savePrivacySettings()
247 {
249 $form = $this->initPrivacySettingsForm();
253
254 if ($request->getMethod() == "POST") {
255 $form = $form->withRequest($request);
256 $data = $form->getData();
257 if (is_array($data["sec"])) {
258 if ($this->isAwarnessSettingVisible() && $this->workWithUserSetting("hide_own_online_status")) {
259 $val = $data["sec"]["hide_own_online_status"];
260 if ($val == "x") {
261 $val = "";
262 }
263 $user->setPref("hide_own_online_status",
264 $val);
265 }
266 if ($this->isContactSettingVisible() && $this->workWithUserSetting("bs_allow_to_contact_me")) {
267 if ($data["sec"]["bs_allow_to_contact_me"]) {
268 $user->setPref("bs_allow_to_contact_me", "y");
269 } else {
270 $user->setPref("bs_allow_to_contact_me", "n");
271 }
272 }
273 $user->update();
274 $this->checklist_status->saveStepSucess(ilProfileChecklistStatus::STEP_VISIBILITY_OPTIONS);
275 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
276 $ctrl->redirect($this, "");
277 }
278 }
279 $this->showPrivacySettings($form);
280 }
281}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Personal profile publishing mode of a iser.
GUI class for public user profile presentation.
ILIAS Setting Class.
User privacy settings (currently located under "Profile and Privacy")
showPrivacySettings($form=null)
General settings form.
isAwarnessSettingVisible()
Is awareness tool setting visible.
isContactSettingVisible()
Is contact setting visible.
savePrivacySettings()
Save privacy settings.
User settings configuration (what preferences can be visible/changed/...)
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46