ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ShowStatusInWhoIsOnline.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29use ILIAS\Refinery\Factory as Refinery;
30
32{
33 public function getIdentifier(): string
34 {
35 return 'awrn_user_show';
36 }
37
38 public function isAvailable(): bool
39 {
40 return (new \ilSetting('awrn'))->get('awrn_enabled', '0') === '1';
41 }
42
43 public function getLabel(Language $lng): string
44 {
45 return $lng->txt($this->getIdentifier());
46 }
47
49 {
50 return AvailablePages::PrivacySettings;
51 }
52
53 public function getSection(): AvailableSections
54 {
55 return AvailableSections::Main;
56 }
57
58 public function getInput(
59 FieldFactory $field_factory,
62 \ilSetting $settings,
63 ?\ilObjUser $user = null
64 ): Input {
65 $default = $settings->get('hide_own_online_status') === 'n'
66 ? $lng->txt('user_awrn_show')
67 : $lng->txt('user_awrn_hide');
68
69 return $field_factory->select(
70 $lng->txt('awrn_user_show'),
71 [
72 'x' => "{$lng->txt('user_awrn_default')} ({$default})",
73 'n' => $lng->txt('user_awrn_show'),
74 'y' => $lng->txt('user_awrn_hide')
75 ],
76 $lng->txt('awrn_hide_from_awareness_info')
77 )->withRequired(true)
78 ->withValue($this->buildSetterValue($settings, $user));
79 }
80
81 public function getLegacyInput(
83 \ilSetting $settings,
84 ?\ilObjUser $user = null
86 $lng->loadLanguageModule('awrn');
87
88 $default = ($settings->get('hide_own_online_status') == 'n')
89 ? $lng->txt('user_awrn_show')
90 : $lng->txt('user_awrn_hide');
91
92 $input = new \ilSelectInputGUI($lng->txt('awrn_user_show'), 'hide_own_online_status');
93 $input->setOptions(
94 [
95 '' => $lng->txt('user_awrn_default') . ' (' . $default . ')',
96 'n' => $lng->txt('user_awrn_show'),
97 'y' => $lng->txt('user_awrn_hide')
98 ]
99 );
100 $input->setDisabled((bool) $settings->get('usr_settings_disable_hide_own_online_status'));
101 $input->setInfo($lng->txt('awrn_hide_from_awareness_info'));
102 $input->setValue(
103 $user !== null
104 ? $user->getPref('chat_osc_accept_msg') === 'y'
105 : $settings->get('chat_osc_accept_msg') === 'y'
106 );
107 return $input;
108 }
109
112 \ilSetting $settings
113 ): string {
114 return $settings->get('hide_own_online_status') === 'n'
115 ? $lng->txt('user_awrn_show')
116 : $lng->txt('user_awrn_hide');
117 }
118
120 \ilSetting $settings,
121 \ilObjUser $user
122 ): bool {
123 return $this->retrieveValueFromUser($user) !== $settings->get('hide_own_online_status');
124 }
125
126 public function persistUserInput(
127 \ilObjUser $user,
128 mixed $input
129 ): \ilObjUser {
130 if ($input === null) {
131 $user->deletePref('hide_own_online_status');
132 return $user;
133 }
134 $user->setPref('hide_own_online_status', $input);
135 return $user;
136 }
137
138 public function retrieveValueFromUser(\ilObjUser $user): ?bool
139 {
140 $value = $user->getPref('hide_own_online_status');
141 return $value !== null ? $value === 'n' : null;
142 }
143
144 private function buildSetterValue(
145 \ilSetting $settings,
146 ?\ilObjUser $user
147 ): string {
148 if ($user === null) {
149 return $settings->get('hide_own_online_status', 'x');
150 }
151
152 $user_value = $user->getPref('hide_own_online_status');
153 if (!empty($user_value)) {
154 return $user_value;
155 }
156
157 return 'x';
158 }
159}
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
buildSetterValue(\ilSetting $settings, ?\ilObjUser $user)
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
Builds data types.
Definition: Factory.php:36
This class represents a property in a property form.
User class.
setPref(string $a_keyword, ?string $a_value)
getPref(string $a_keyword)
deletePref(string $keyword)
ILIAS Setting Class.
get(string $a_keyword, ?string $a_default_value=null)
get setting
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
get(string $class_name)
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))