ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations Class Reference
+ Inheritance diagram for ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations:
+ Collaboration diagram for ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations:

Public Member Functions

 getIdentifier ()
 
 isAvailable ()
 If this function returns false the setting will not be shown, even if it's PropertyAttributes would allow it to be. More...
 
 getLabel (Language $lng)
 
 getSettingsPage ()
 
 getSection ()
 
 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, thus you can also not rely on the post_var anywhere else, as it will be changed. More...
 
 getDefaultValueForDisplay (Language $lng, \ilSetting $settings)
 
 hasUserPersonalizedSetting (\ilSetting $settings, \ilObjUser $user)
 
 persistUserInput (\ilObjUser $user, mixed $input)
 
 retrieveValueFromUser (\ilObjUser $user)
 
 isAvailable ()
 If this function returns false the setting will not be shown, even if it's PropertyAttributes would allow it to be. More...
 
 getSettingsPage ()
 
 getDefaultValueForDisplay (Language $lng, \ilSetting $settings)
 
 hasUserPersonalizedSetting (\ilSetting $settings, \ilObjUser $user)
 
 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, thus you can also not rely on the post_var anywhere else, as it will be changed. More...
 
 persistUserInput (\ilObjUser $user, mixed $input)
 
 getIdentifier ()
 
 getLabel (Language $lng)
 
 getSection ()
 
 retrieveValueFromUser (\ilObjUser $user)
 

Private Member Functions

 buildValueForNotificationGroup (\ilSetting $settings, ?\ilObjUser $user)
 
 updateChatServer (int $user_id, bool $osc_state)
 

Private Attributes

const string KEY_ENABLE_BROWSER_NOTIFICATIONS = 'chat_osc_browser_notifications'
 

Detailed Description

Definition at line 31 of file AllowOnScreenChatConversations.php.

Member Function Documentation

◆ buildValueForNotificationGroup()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::buildValueForNotificationGroup ( \ilSetting  $settings,
?\ilObjUser  $user 
)
private

Definition at line 182 of file AllowOnScreenChatConversations.php.

185 : ?array {
186 $active = $settings->get($this->getIdentifier()) === 'y';
187 $notification = false;
188 if ($user !== null) {
189 $active = $user->getPref($this->getIdentifier()) === 'y';
190 $notification = $user->getPref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS) === 'y';
191 }
192
193 if ($active === false) {
194 return null;
195 }
196
197 return [
198 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $notification
199 ];
200 }

References ilObjUser\getPref().

+ Here is the call graph for this function:

◆ getDefaultValueForDisplay()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getDefaultValueForDisplay ( Language  $lng,
\ilSetting  $settings 
)

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 117 of file AllowOnScreenChatConversations.php.

120 : string {
121 return $lng->txt('chat_osc_accepts_messages_no');
122 }
global $lng
Definition: privfeed.php:31

◆ getIdentifier()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getIdentifier ( )

Implements ILIAS\User\Property.

Definition at line 35 of file AllowOnScreenChatConversations.php.

35 : string
36 {
37 return 'chat_osc_accept_msg';
38 }

◆ getInput()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getInput ( FieldFactory  $field_factory,
Language  $lng,
Refinery  $refinery,
\ilSetting  $settings,
?\ilObjUser  $user = null 
)

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 60 of file AllowOnScreenChatConversations.php.

66 : Input {
67 $chat_settings = new \ilSetting('chatroom');
68 $lng->loadLanguageModule('chatroom_adm');
69
70 if ($chat_settings->get('enable_browser_notifications', '0') !== '1') {
71 return $field_factory->checkbox(
72 $lng->txt('chat_osc_accept_msg'),
73 $lng->txt('chat_osc_accept_msg_info')
74 )->withValue(
75 $user !== null
76 ? $user->getPref('chat_osc_accept_msg') === 'y'
77 : $settings->get('chat_osc_accept_msg') === 'y'
78 );
79 }
80
81 return $field_factory->optionalGroup(
82 [
83 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $field_factory->checkbox(
84 $lng->txt('osc_enable_browser_notifications_label'),
85 \sprintf(
86 $lng->txt('osc_enable_browser_notifications_info'),
87 (int) $chat_settings->get('conversation_idle_state_in_minutes')
88 )
89 )->withDisabled(
90 $settings->get('usr_settings_disable_chat_osc_accept_msg', '0') === '1'
91 )
92 ],
93 $lng->txt('chat_osc_accept_msg'),
94 $lng->txt('chat_osc_accept_msg_info')
95 )->withValue(
96 $this->buildValueForNotificationGroup($settings, $user)
97 );
98 }

References $lng, and ilSetting\get().

+ Here is the call graph for this function:

◆ getLabel()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getLabel ( Language  $lng)

Implements ILIAS\User\Property.

Definition at line 45 of file AllowOnScreenChatConversations.php.

45 : string
46 {
47 return $lng->txt('chat_osc_accept_msg');
48 }

References $lng.

◆ getLegacyInput()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::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, thus you can also not rely on the post_var anywhere else, as it will be changed.

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 100 of file AllowOnScreenChatConversations.php.

105 $lng->loadLanguageModule('chatroom');
106
107 $input = new \ilCheckboxInputGUI($lng->txt('chat_osc_accept_msg'));
108 $input->setChecked(
109 $user !== null
110 ? $user->getPref('chat_osc_accept_msg') === 'y'
111 : $settings->get('chat_osc_accept_msg') === 'y'
112 );
113
114 return $input;
115 }
This class represents a property in a property form.

◆ getSection()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getSection ( )

Implements ILIAS\User\Property.

Definition at line 55 of file AllowOnScreenChatConversations.php.

56 {
57 return AvailableSections::Main;
58 }

◆ getSettingsPage()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::getSettingsPage ( )

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 50 of file AllowOnScreenChatConversations.php.

51 {
52 return AvailablePages::PrivacySettings;
53 }

◆ hasUserPersonalizedSetting()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::hasUserPersonalizedSetting ( \ilSetting  $settings,
\ilObjUser  $user 
)

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 124 of file AllowOnScreenChatConversations.php.

127 : bool {
128 $user_value = $this->retrieveValueFromUser($user);
129 return $user_value[$this->getIdentifier()] !== false;
130 }

◆ isAvailable()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::isAvailable ( )

If this function returns false the setting will not be shown, even if it's PropertyAttributes would allow it to be.

This is meant e.g. to check if the chat server is configured or the badges enabled. Settings that are not available will also not be available on the table to define their PropertyAttributes

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 40 of file AllowOnScreenChatConversations.php.

40 : bool
41 {
42 return (new \ilSetting('chatroom'))->get('enable_osc', '0') === '1';
43 }
ILIAS Setting Class.

◆ persistUserInput()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::persistUserInput ( \ilObjUser  $user,
mixed  $input 
)
Parameters
mixed$inputNull will be handed in, if the user wants to use the system default. If you are able to set the preference on the user without saving it, you can rely on the User-object being saved after the call to this function. If your input has different structures depending on its provenience (KS-Input, Legacy-Input, ...), the function needs to be able to handle them all.

Implements ILIAS\User\Settings\SettingDefinition.

Definition at line 132 of file AllowOnScreenChatConversations.php.

135 : \ilObjUser {
136 if ($input === null) {
137 $user->deletePref($this->getIdentifier());
138 $user->deletePref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS);
139 $this->updateChatServer($user->getId(), false);
140
141 return $user;
142 }
143
144 if ($input === '1' || $input === '0') {
145 $input = $input === '1';
146 }
147
148 if (\is_bool($input)) {
149 $user->setPref($this->getIdentifier(), $input ? 'y' : 'n');
150 $this->updateChatServer($user->getId(), $input);
151
152 return $user;
153 }
154
155 if (\is_array($input)) {
156 $user->setPref($this->getIdentifier(), 'y');
157 $user->setPref(
158 self::KEY_ENABLE_BROWSER_NOTIFICATIONS,
159 $input[self::KEY_ENABLE_BROWSER_NOTIFICATIONS] ? 'y' : 'n'
160 );
161 $this->updateChatServer($user->getId(), true);
162 }
163
164 return $user;
165 }
User class.
deletePref(string $key)

References ilObjUser\deletePref(), and ilObject\getId().

+ Here is the call graph for this function:

◆ retrieveValueFromUser()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::retrieveValueFromUser ( \ilObjUser  $user)

Implements ILIAS\User\Property.

Definition at line 167 of file AllowOnScreenChatConversations.php.

167 : array
168 {
169 if ($user->getPref($this->getIdentifier()) !== 'y') {
170 return [
171 $this->getIdentifier() => false,
172 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => false
173 ];
174 }
175
176 return [
177 $this->getIdentifier() => true,
178 self::KEY_ENABLE_BROWSER_NOTIFICATIONS => $user->getPref(self::KEY_ENABLE_BROWSER_NOTIFICATIONS) === 'y'
179 ];
180 }

References ilObjUser\getPref().

+ Here is the call graph for this function:

◆ updateChatServer()

ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::updateChatServer ( int  $user_id,
bool  $osc_state 
)
private

Definition at line 202 of file AllowOnScreenChatConversations.php.

202 : void
203 {
204 $message = [
205 $user_id => [
206 'acceptsMessages' => $osc_state,
207 ]
208 ];
209
210 $settings = \ilChatroomAdmin::getDefaultConfiguration()->getServerSettings();
211 $connector = new \ilChatroomServerConnector($settings);
212 $connector->sendUserConfigChange(json_encode($message, JSON_THROW_ON_ERROR));
213 }
static getDefaultConfiguration()
Instantiates and returns ilChatroomAdmin object using instance_id and settings from settingsTable.

References $user_id, and ilChatroomAdmin\getDefaultConfiguration().

+ Here is the call graph for this function:

Field Documentation

◆ KEY_ENABLE_BROWSER_NOTIFICATIONS

const string ILIAS\Chatroom\UserSettings\AllowOnScreenChatConversations::KEY_ENABLE_BROWSER_NOTIFICATIONS = 'chat_osc_browser_notifications'
private

Definition at line 33 of file AllowOnScreenChatConversations.php.


The documentation for this class was generated from the following file: