ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomFormFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const PROP_TITLE_AND_DESC = 'title_and_desc';
24 public const PROP_ONLINE_STATUS = 'online_status';
25 public const PROP_TILE_IMAGE = 'tile_image';
26 public const PROP_DISPLAY_PAST_MSG = 'display_past_msgs';
27 public const PROP_ENABLE_HISTORY = 'enable_history';
28 public const PROP_ALLOW_ANONYMOUS = 'allow_anonymous';
29 public const PROP_ALLOW_CUSTOM_NAMES = 'allow_custom_usernames';
30 public const PROP_AUTOGEN_USERNAMES = 'autogen_usernames';
31
32 protected ilLanguage $lng;
33 protected ilObjUser $user;
34 protected \ILIAS\HTTP\Services $http;
35 protected \ILIAS\UI\Factory $ui_factory;
36 protected \ILIAS\Refinery\Factory $refinery;
37
38 public function __construct()
39 {
40 global $DIC;
41
42 $this->lng = $DIC->language();
43 $this->user = $DIC->user();
44 $this->http = $DIC->http();
45 $this->ui_factory = $DIC->ui()->factory();
46 $this->refinery = $DIC->refinery();
47 }
48
52 public static function applyValues(ilPropertyFormGUI $form, array $values): void
53 {
54 $form->setValuesByArray(
55 array_map(
56 static fn($value) => is_int($value) ? (string) $value : $value,
57 $values
58 )
59 );
60 }
61
62 private function mergeValuesTrafo(): \ILIAS\Refinery\Transformation
63 {
64 return $this->refinery->custom()->transformation(static fn(array $values): array => array_merge(...$values));
65 }
66
67 private function saniziteArrayElementsTrafo(): \ILIAS\Refinery\Transformation
68 {
69 $sanitize = static function (array $data) use (&$sanitize): array {
70 foreach ($data as $key => $value) {
71 if (is_array($value)) {
72 $data[$key] = $sanitize($value);
73 } elseif (is_string($value)) {
74 $data[$key] = ilUtil::stripSlashes($value);
75 }
76 }
77
78 return $data;
79 };
80
81 return $this->refinery->custom()->transformation($sanitize);
82 }
83
84 public function getSettingsForm(
86 ilCtrlInterface $ctrl,
87 ?array $values = null,
88 bool $may_write = false
89 ): \ILIAS\UI\Component\Input\Container\Form\Form {
90 $this->lng->loadLanguageModule('obj');
91 $this->lng->loadLanguageModule('rep');
92
93 $field_factory = $this->ui_factory->input()->field();
94
95 $title_and_description = $gui->getObject()->getObjectProperties()->getPropertyTitleAndDescription();
96 $general_settings_fields = [
97 self::PROP_TITLE_AND_DESC => $title_and_description->toForm(
98 $this->lng,
99 $field_factory,
100 $this->refinery
101 )
102 ];
103
104 $online_status = $gui->getObject()->getObjectProperties()->getPropertyIsOnline();
105 $availability_fields = [
106 self::PROP_ONLINE_STATUS => $online_status->toForm(
107 $this->lng,
108 $field_factory,
109 $this->refinery
110 )->withByline($this->lng->txt('chtr_activation_online_info')),
111 ];
112
113 $tile_image = $gui->getObject()->getObjectProperties()->getPropertyTileImage();
114 $presentation_fields = [
115 self::PROP_TILE_IMAGE => $tile_image->toForm(
116 $this->lng,
117 $field_factory,
118 $this->refinery
119 ),
120 self::PROP_DISPLAY_PAST_MSG => $field_factory->numeric(
121 $this->lng->txt('display_past_msgs'),
122 $this->lng->txt('hint_display_past_msgs')
123 )->withRequired(
124 true
125 )->withAdditionalTransformation(
126 $this->refinery->logical()->parallel([
127 $this->refinery->int()->isGreaterThanOrEqual(0),
128 $this->refinery->int()->isLessThanOrEqual(100)
129 ])
130 )->withValue(
131 $values['display_past_msgs'] ?? 0
132 ),
133 self::PROP_ENABLE_HISTORY => $field_factory->checkbox(
134 $this->lng->txt('chat_enable_history'),
135 $this->lng->txt('chat_enable_history_info')
136 )->withValue((bool) ($values['enable_history'] ?? false)),
137 ];
138
139 $function_fields = [
140 self::PROP_ALLOW_ANONYMOUS => $field_factory->checkbox(
141 $this->lng->txt('allow_anonymous'),
142 $this->lng->txt('anonymous_hint')
143 )->withValue((bool) ($values['allow_anonymous'] ?? false)),
144 self::PROP_ALLOW_CUSTOM_NAMES => $field_factory->optionalGroup(
145 [
146 self::PROP_AUTOGEN_USERNAMES => $field_factory->text(
147 $this->lng->txt('autogen_usernames'),
148 $this->lng->txt('autogen_usernames_info')
149 )->withRequired(true),
150 ],
151 $this->lng->txt('allow_custom_usernames')
152 )->withValue(
153 ($values['allow_custom_usernames'] ?? false) ? [self::PROP_AUTOGEN_USERNAMES => $values['autogen_usernames'] ?? ''] : null
154 ),
155 ];
156
157 $sections = [
158 $field_factory->section(
159 $general_settings_fields,
160 $this->lng->txt('settings_title'),
161 ''
162 ),
163 $field_factory->section(
164 $availability_fields,
165 $this->lng->txt('rep_activation_availability'),
166 ''
167 ),
168 $field_factory->section(
169 $presentation_fields,
170 $this->lng->txt('settings_presentation_header'),
171 ''
172 ),
173 $field_factory->section(
174 $function_fields,
175 $this->lng->txt('chat_settings_functions_header'),
176 ''
177 ),
178 ];
179
180 $action = $ctrl->getFormAction($gui, 'settings-saveGeneral');
181 if (!$may_write) {
182 $action = $ctrl->getFormAction($gui, 'settings-general');
183 }
184
185 if (!$may_write) {
186 $sections = array_map(static fn($x) => $x->withDisabled(true), $sections);
187 }
188
189 $form = $this->ui_factory
190 ->input()
191 ->container()
192 ->form()
193 ->standard(
194 $action,
195 $sections
196 )
197 ->withAdditionalTransformation($this->mergeValuesTrafo())
198 ->withAdditionalTransformation($this->saniziteArrayElementsTrafo());
199
200 if (!$may_write) {
201 $form = $form->withSubmitLabel($this->lng->txt('refresh'));
202 }
203
204 return $form;
205 }
206
208 {
209 $form = new ilPropertyFormGUI();
210 $form->setPreventDoubleSubmission(false);
211
212 $duration = new ilDateDurationInputGUI($this->lng->txt('period'), 'timeperiod');
213
214 $duration->setStartText($this->lng->txt('duration_from'));
215 $duration->setEndText($this->lng->txt('duration_to'));
216 $duration->setShowTime(true);
217 $duration->setRequired(true);
218 $form->addItem($duration);
219
220 return $form;
221 }
222
227 public function getUserChatNameSelectionForm(array $name_options): ilPropertyFormGUI
228 {
229 $form = new ilPropertyFormGUI();
230
231 $radio = new ilRadioGroupInputGUI($this->lng->txt('select_custom_username'), 'custom_username_radio');
232
233 foreach ($name_options as $key => $option) {
234 $opt = new ilRadioOption($option, $key);
235 $radio->addOption($opt);
236 }
237
238 $custom_opt = new ilRadioOption($this->lng->txt('custom_username'), 'custom_username');
239 $radio->addOption($custom_opt);
240
241 $txt = new ilTextInputGUI($this->lng->txt('preferred_chatname'), 'custom_username_text');
242 $custom_opt->addSubItem($txt);
243 $form->addItem($radio);
244
245 if ($this->user->isAnonymous()) {
246 $radio->setValue('anonymousName');
247 } else {
248 $radio->setValue('fullname');
249 }
250
251 return $form;
252 }
253
255 {
256 $form = new ilPropertyFormGUI();
257
258 $enable_chat = new ilCheckboxInputGUI($this->lng->txt('chat_enabled'), 'chat_enabled');
259 $form->addItem($enable_chat);
260
261 $enable_osc = new ilCheckboxInputGUI($this->lng->txt('chatroom_enable_osc'), 'enable_osc');
262 $enable_osc->setInfo($this->lng->txt('chatroom_enable_osc_info'));
263 $enable_chat->addSubItem($enable_osc);
264
265 $oscBrowserNotificationStatus = new ilCheckboxInputGUI(
266 $this->lng->txt('osc_adm_browser_noti_label'),
267 'enable_browser_notifications'
268 );
269 $oscBrowserNotificationStatus->setInfo($this->lng->txt('osc_adm_browser_noti_info'));
270 $oscBrowserNotificationStatus->setValue('1');
271 $enable_osc->addSubItem($oscBrowserNotificationStatus);
272
273 $oscBrowserNotificationIdleTime = new ilNumberInputGUI(
274 $this->lng->txt('osc_adm_conv_idle_state_threshold_label'),
275 'conversation_idle_state_in_minutes'
276 );
277 $oscBrowserNotificationIdleTime->allowDecimals(false);
278 $oscBrowserNotificationIdleTime->setSuffix($this->lng->txt('minutes'));
279 $oscBrowserNotificationIdleTime->setMinValue(1);
280 $oscBrowserNotificationIdleTime->setSize(5);
281 $oscBrowserNotificationIdleTime->setInfo($this->lng->txt('osc_adm_conv_idle_state_threshold_info'));
282 $enable_osc->addSubItem($oscBrowserNotificationIdleTime);
283
284 $oscAllowConversations = new ilSelectInputGUI(
285 $this->lng->txt('chat_osc_accept_msg'),
286 'chat_osc_accept_msg'
287 );
288 $oscAllowConversations->setOptions(
289 [
290 'n' => $this->lng->txt('buddy_allow_to_contact_me_no'),
291 'y' => $this->lng->txt('buddy_allow_to_contact_me_yes')
292 ]
293 );
294 $oscAllowConversations->setInfo($this->lng->txt('chat_osc_accept_msg_default_info'));
295 $enable_osc->addSubItem($oscAllowConversations);
296
297 $oscBroadcastTyping = new ilSelectInputGUI(
298 $this->lng->txt('chat_broadcast_typing'),
299 'chat_broadcast_typing'
300 );
301 $oscBroadcastTyping->setOptions(
302 [
303 'n' => $this->lng->txt('chat_no_use_typing_broadcast'),
304 'y' => $this->lng->txt('chat_use_typing_broadcast')
305 ]
306 );
307 $oscBroadcastTyping->setInfo($this->lng->txt('chat_broadcast_typing_default_info'));
308 $enable_osc->addSubItem($oscBroadcastTyping);
309
310 $name = new ilTextInputGUI($this->lng->txt('chatroom_client_name'), 'client_name');
311 $name->setInfo($this->lng->txt('chatroom_client_name_info'));
312 $name->setRequired(true);
313 $name->setMaxLength(100);
314 $enable_chat->addSubItem($name);
315
316 $auth = new ilChatroomAuthInputGUI(
317 $this->lng->txt('chatroom_auth'),
318 'auth',
319 $this->http
320 );
321 $auth->setInfo($this->lng->txt('chat_auth_token_info'));
322 $auth->setCtrlPath(
323 [
324 ilAdministrationGUI::class,
325 ilObjChatroomGUI::class,
326 ilPropertyFormGUI::class,
327 ilFormPropertyDispatchGUI::class,
328 ilChatroomAuthInputGUI::class,
329 ]
330 );
331 $auth->setRequired(true);
332 $enable_chat->addSubItem($auth);
333
334 return $form;
335 }
336}
$duration
Class ilChatroomAuthInputGUI.
static applyValues(ilPropertyFormGUI $form, array $values)
Applies given values to field in given form.
getSettingsForm(ilChatroomObjectGUI $gui, ilCtrlInterface $ctrl, ?array $values=null, bool $may_write=false)
getUserChatNameSelectionForm(array $name_options)
Returns chatname selection form.
ILIAS Refinery Factory $refinery
This class represents a checkbox property in a property form.
input GUI for a time span (start and end date)
language handling
This class represents a number property in a property form.
User class.
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$txt
Definition: error.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFormAction(object $a_gui_obj, ?string $a_fallback_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
Returns a form action link for the given information.
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26