ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Renderer as UiRenderer;
23use ILIAS\Data\Factory as DataFactory;
27
32{
33 private readonly ilCtrlInterface $ctrl;
35 private readonly ilLanguage $lng;
36 private readonly ilSetting $settings;
37 private readonly ilTabsGUI $tabs;
38 private readonly ilAccessHandler $access;
39 private readonly \ILIAS\HTTP\GlobalHttpState $http;
42 private readonly ilObjectService $obj_service;
43 private readonly \ILIAS\DI\Container $dic;
44 private readonly ilErrorHandling $error;
45 private readonly \ILIAS\UI\Factory $ui_factory;
46 private readonly UiRenderer $ui_renderer;
47 private readonly ilUIService $ui_service;
48
49 public function __construct(private readonly ilObjForumGUI $parent_obj, private readonly ilObjForum $forum)
50 {
51 global $DIC;
52
53 $this->dic = $DIC;
54
55 $this->ctrl = $DIC->ctrl();
56 $this->tpl = $DIC->ui()->mainTemplate();
57 $this->lng = $DIC->language();
58 $this->settings = $DIC->settings();
59 $this->tabs = $DIC->tabs();
60 $this->access = $DIC->access();
61 $this->obj_service = $this->dic->object();
62 $this->http = $DIC->http();
63 $this->ui_factory = $DIC->ui()->factory();
64 $this->ui_renderer = $DIC->ui()->renderer();
65 $this->ui_service = $DIC->uiService();
66 $this->error = $DIC['ilErr'];
67
68 $this->lng->loadLanguageModule('style');
69 $this->lng->loadLanguageModule('cont');
70 }
71
72 public function getRefId(): int
73 {
74 return $this->forum->getRefId();
75 }
76
77 private function initForcedForumNotification(): void
78 {
79 $this->forumNotificationObj = new ilForumNotification($this->forum->getRefId());
80 $this->forumNotificationObj->readAllForcedEvents();
81 }
82
83 public function executeCommand(): void
84 {
85 $cmd = $this->ctrl->getCmd() ?? '';
86 switch (true) {
87 case method_exists($this, $cmd . 'Command'):
88 $this->settingsTabs();
89 $this->{$cmd . 'Command'}();
90 break;
91
92 default:
93 $this->ctrl->redirect($this->parent_obj);
94 }
95 }
96
97 private function addAvailabilitySection(ilPropertyFormGUI $form): void
98 {
99 $section = new ilFormSectionHeaderGUI();
100 $section->setTitle($this->lng->txt('rep_activation_availability'));
101 $form->addItem($section);
102
103 $online = new ilCheckboxInputGUI($this->lng->txt('rep_activation_online'), 'activation_online');
104 $online->setInfo($this->lng->txt('frm_activation_online_info'));
105 $form->addItem($online);
106 }
107
108 public function getCustomForm(ilPropertyFormGUI $a_form): void
109 {
110 $this->settingsTabs();
111 $this->tabs->activateSubTab(self::UI_SUB_TAB_ID_BASIC_SETTINGS);
112 $a_form->setTitle($this->lng->txt('frm_settings_form_header'));
113
114 $this->addAvailabilitySection($a_form);
115
116 $presentationHeader = new ilFormSectionHeaderGUI();
117 $presentationHeader->setTitle($this->lng->txt('settings_presentation_header'));
118 $a_form->addItem($presentationHeader);
119
120 $this->obj_service->commonSettings()->legacyForm($a_form, $this->parent_obj->getObject())->addTileImage();
121
122 $rg_pro = new ilRadioGroupInputGUI($this->lng->txt('frm_default_view'), 'default_view');
123 $option_view_by_posts = new ilRadioOption($this->lng->txt('sort_by_posts'), (string) ilForumProperties::VIEW_TREE);
124 $option_view_by_posts->setInfo($this->lng->txt('sort_by_posts_desc'));
125 $rg_pro->addOption($option_view_by_posts);
126 $option_view_by_date = new ilRadioOption($this->lng->txt('sort_by_date'), (string) ilForumProperties::VIEW_DATE);
127 $option_view_by_date->setInfo($this->lng->txt('sort_by_date_desc'));
128 $sub_group = new ilRadioGroupInputGUI('', 'default_view_by_date');
129 $sub_group->addOption(new ilRadioOption($this->lng->txt('ascending_order'), (string) ilForumProperties::VIEW_DATE_ASC));
130 $sub_group->addOption(new ilRadioOption($this->lng->txt('descending_order'), (string) ilForumProperties::VIEW_DATE_DESC));
131
132 $option_view_by_date->addSubItem($sub_group);
133 $rg_pro->addOption($option_view_by_date);
134 $a_form->addItem($rg_pro);
135
136 $userFunctionsHeader = new ilFormSectionHeaderGUI();
137 $userFunctionsHeader->setTitle($this->lng->txt('frm_settings_user_functions_header'));
138 $a_form->addItem($userFunctionsHeader);
139
140 $frm_subject = new ilRadioGroupInputGUI($this->lng->txt('frm_subject_setting'), 'subject_setting');
141 $frm_subject->addOption(new ilRadioOption($this->lng->txt('preset_subject'), 'preset_subject'));
142 $frm_subject->addOption(new ilRadioOption($this->lng->txt('add_re_to_subject'), 'add_re_to_subject'));
143 $frm_subject->addOption(new ilRadioOption($this->lng->txt('empty_subject'), 'empty_subject'));
144 $a_form->addItem($frm_subject);
145
146 $cb_prop = new ilCheckboxInputGUI($this->lng->txt('enable_thread_ratings'), 'thread_rating');
147 $cb_prop->setValue('1');
148 $cb_prop->setInfo($this->lng->txt('enable_thread_ratings_info'));
149 $a_form->addItem($cb_prop);
150
152 $frm_upload = new ilCheckboxInputGUI($this->lng->txt('file_upload_allowed'), 'file_upload_allowed');
153 $frm_upload->setValue('1');
154 $frm_upload->setInfo($this->lng->txt('allow_file_upload_desc'));
155 $a_form->addItem($frm_upload);
156 }
157
158 $moderatorFunctionsHeader = new ilFormSectionHeaderGUI();
159 $moderatorFunctionsHeader->setTitle($this->lng->txt('frm_settings_mod_functions_header'));
160 $a_form->addItem($moderatorFunctionsHeader);
161
162 $cb_prop = new ilCheckboxInputGUI($this->lng->txt('activate_new_posts'), 'post_activation');
163 $cb_prop->setValue('1');
164 $cb_prop->setInfo($this->lng->txt('post_activation_desc'));
165 $a_form->addItem($cb_prop);
166
167 $cb_prop = new ilCheckboxInputGUI($this->lng->txt('mark_moderator_posts'), 'mark_mod_posts');
168 $cb_prop->setValue('1');
169 $cb_prop->setInfo($this->lng->txt('mark_moderator_posts_desc'));
170 $a_form->addItem($cb_prop);
171
172 if ($this->settings->get('enable_anonymous_fora') || $this->settings->get('enable_fora_statistics')) {
173 $privacyHeader = new ilFormSectionHeaderGUI();
174 $privacyHeader->setTitle($this->lng->txt('frm_settings_privacy_header'));
175 $a_form->addItem($privacyHeader);
176 }
177
178 if ($this->settings->get('enable_fora_statistics')) {
179 $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_statistics_enabled'), 'statistics_enabled');
180 $cb_prop->setValue('1');
181 $cb_prop->setInfo($this->lng->txt('frm_statistics_enabled_desc'));
182 $a_form->addItem($cb_prop);
183 }
184
185 if ($this->settings->get('enable_anonymous_fora') || $this->parent_obj->objProperties->isAnonymized()) {
186 $cb_prop = new ilCheckboxInputGUI($this->lng->txt('frm_anonymous_posting'), 'anonymized');
187 $cb_prop->setValue('1');
188 $cb_prop->setInfo($this->lng->txt('frm_anonymous_posting_desc'));
189 $a_form->addItem($cb_prop);
190 }
191 }
192
193 public function settingsTabs(): bool
194 {
195 $this->tabs->addSubTabTarget(
196 self::UI_SUB_TAB_ID_BASIC_SETTINGS,
197 $this->ctrl->getLinkTarget($this->parent_obj, 'edit'),
198 '',
199 [strtolower(ilObjForumGUI::class)]
200 );
201
202 if ($this->settings->get('forum_notification') > 0 &&
203 $this->forum->isParentMembershipEnabledContainer() &&
204 $this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
205
206 $this->tabs->addSubTabTarget(
207 self::UI_SUB_TAB_ID_NOTIFICATIONS,
208 $this->ctrl->getLinkTarget($this, 'showMembers'),
209 '',
210 [strtolower(self::class)]
211 );
212 }
213
214 $this->tabs->addSubTabTarget(
215 self::UI_SUB_TAB_ID_NEWS,
216 $this->ctrl->getLinkTargetByClass(ilContainerNewsSettingsGUI::class),
217 '',
218 [strtolower(ilContainerNewsSettingsGUI::class)]
219 );
220
221 $this->tabs->addSubTabTarget(
222 self::UI_SUB_TAB_ID_STYLE,
223 $this->ctrl->getLinkTargetByClass(strtolower(ilObjectContentStyleSettingsGUI::class), ""),
224 '',
225 [strtolower(ilObjectContentStyleSettingsGUI::class)]
226 );
227
228 $this->tabs->activateTab(self::UI_TAB_ID_SETTINGS);
229
230 return true;
231 }
232
233 public function getCustomValues(array &$a_values): void
234 {
235 $a_values['anonymized'] = $this->parent_obj->objProperties->isAnonymized();
236 $a_values['statistics_enabled'] = $this->parent_obj->objProperties->isStatisticEnabled();
237 $a_values['post_activation'] = $this->parent_obj->objProperties->isPostActivationEnabled();
238 $a_values['subject_setting'] = $this->parent_obj->objProperties->getSubjectSetting();
239 $a_values['mark_mod_posts'] = $this->parent_obj->objProperties->getMarkModeratorPosts();
240 $a_values['thread_rating'] = $this->parent_obj->objProperties->isIsThreadRatingEnabled();
241
242 $default_view_value = $this->parent_obj->objProperties->getDefaultView();
243 if (in_array($default_view_value, [
248 ], true)) {
249 if (in_array($default_view_value, [
252 ], true)) {
253 $default_view_by_date = $default_view_value;
254 $default_view = ilForumProperties::VIEW_DATE;
255 } else {
256 $default_view = $default_view_value;
257 }
258 } else {
259 $default_view = ilForumProperties::VIEW_TREE;
260 }
261
262 $a_values['default_view'] = $default_view;
263 if (isset($default_view_by_date)) {
264 $a_values['default_view_by_date'] = $default_view_by_date;
265 }
266 $a_values['file_upload_allowed'] = $this->parent_obj->objProperties->getFileUploadAllowed();
267
268 $object = $this->parent_obj->getObject();
269 $a_values['activation_online'] = !$object->getOfflineStatus();
270 }
271
272 public function updateCustomValues(ilPropertyFormGUI $a_form): void
273 {
274 $default_view_input_value = (int) $a_form->getInput('default_view');
275 if (in_array($default_view_input_value, [
280 ], true)) {
281 if ($default_view_input_value === ilForumProperties::VIEW_DATE) {
282 $default_view_order_by_date_value = (int) $a_form->getInput('default_view_by_date');
283 if (in_array($default_view_order_by_date_value, [
286 ], true)) {
287 $default_view_input_value = $default_view_order_by_date_value;
288 }
289 }
290 $default_view = $default_view_input_value;
291 } else {
292 $default_view = ilForumProperties::VIEW_TREE;
293 }
294 $this->parent_obj->objProperties->setDefaultView($default_view);
295
296 // BUGFIX FOR 11271
297
298 $view_mode = 'viewmode_' . $this->forum->getId();
299 if (ilSession::get($view_mode)) {
300 ilSession::set($view_mode, $default_view);
301 }
302
303 if ($this->settings->get('enable_anonymous_fora') || $this->parent_obj->objProperties->isAnonymized()) {
304 $this->parent_obj->objProperties->setAnonymisation((bool) $a_form->getInput('anonymized'));
305 }
306 if ($this->settings->get('enable_fora_statistics')) {
307 $this->parent_obj->objProperties->setStatisticsStatus((bool) $a_form->getInput('statistics_enabled'));
308 }
309 $this->parent_obj->objProperties->setPostActivation((bool) $a_form->getInput('post_activation'));
310 $this->parent_obj->objProperties->setSubjectSetting($a_form->getInput('subject_setting'));
311 $this->parent_obj->objProperties->setMarkModeratorPosts((bool) $a_form->getInput('mark_mod_posts'));
312 $this->parent_obj->objProperties->setIsThreadRatingEnabled((bool) $a_form->getInput('thread_rating'));
314 $this->parent_obj->objProperties->setFileUploadAllowed((bool) $a_form->getInput('file_upload_allowed'));
315 }
316 $this->parent_obj->objProperties->update();
317 $this->obj_service->commonSettings()->legacyForm($a_form, $this->parent_obj->getObject())->saveTileImage();
318
319 $object = $this->parent_obj->getObject();
320 $object->setOfflineStatus(!$a_form->getInput('activation_online'));
321 $object->update();
322 }
323
324 private function showMembersCommand(): void
325 {
326 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
327 $this->error->raiseError(
328 $this->lng->txt('msg_no_perm_read'),
329 $this->error->MESSAGE
330 );
331 }
332
333 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.forums_members_list.html', 'components/ILIAS/Forum');
334
335 // instantiate the property form
336 if (!$this->initNotificationSettingsForm()) {
337 // if the form was just created set the values fetched from database
338 $interested_events = $this->parent_obj->objProperties->getInterestedEvents();
339
340 $form_events = [];
341 if (($interested_events & ilForumNotificationEvents::UPDATED) !== 0) {
342 $form_events[] = ilForumNotificationEvents::UPDATED;
343 }
344
345 if (($interested_events & ilForumNotificationEvents::CENSORED) !== 0) {
347 }
348
349 if (($interested_events & ilForumNotificationEvents::UNCENSORED) !== 0) {
351 }
352
353 if (($interested_events & ilForumNotificationEvents::POST_DELETED) !== 0) {
355 }
356
357 if (($interested_events & ilForumNotificationEvents::THREAD_DELETED) !== 0) {
359 }
360
361 $this->notificationSettingsForm->setValuesByArray([
362 'notification_type' => $this->parent_obj->objProperties->getNotificationType()->value,
363 'adm_force' => $this->parent_obj->objProperties->isAdminForceNoti(),
364 'usr_toggle' => $this->parent_obj->objProperties->isUserToggleNoti(),
365 'notification_events' => $form_events
366 ]);
367 }
368
369 $this->tpl->setVariable('NOTIFICATIONS_SETTINGS_FORM', $this->notificationSettingsForm->getHTML());
370
371 if ($this->parent_obj->objProperties->getNotificationType() === NotificationType::DEFAULT) {
372 $forum_noti = new ilForumNotification($this->forum->getRefId());
373 $forum_noti->setAdminForce($this->parent_obj->objProperties->isAdminForceNoti());
374 $forum_noti->setUserToggle($this->parent_obj->objProperties->isUserToggleNoti());
375 $forum_noti->setForumId($this->parent_obj->objProperties->getObjId());
376 $forum_noti->setInterestedEvents($this->parent_obj->objProperties->getInterestedEvents());
377 $forum_noti->update();
378 } elseif ($this->parent_obj->objProperties->getNotificationType() === NotificationType::PER_USER) {
379 $this->tpl->setVariable('TABLE', $this->ui_renderer->render($this->getForumNotificationTable()->getComponents()));
380 }
381 }
382
384 {
386 return new ForumNotificationTable(
387 $this->http->request(),
388 $this->lng,
389 $this->ui_factory,
390 new DataFactory(),
391 $this->parent_obj->getObject()->getRefId(),
392 $this->forum->parentParticipants(),
393 $this->forumNotificationObj,
394 $this->ui_service,
395 $this->ctrl->getLinkTarget($this, 'handleNotificationActions')
396 );
397 }
398
399 private function notificationSettings(): never
400 {
401 $send_bad_request = function () {
402 $this->http->saveResponse(
403 $this->http->response()
404 ->withStatus(400)
405 );
406 $this->http->sendResponse();
407 $this->http->close();
408 };
409
410 if (!$this->http->wrapper()->query()->has('frm_notifications_table_usr_ids')) {
411 $send_bad_request();
412 }
413
414 $user_ids = $this->http->wrapper()->query()->retrieve(
415 'frm_notifications_table_usr_ids',
416 $this->dic->refinery()->kindlyTo()->listOf($this->dic->refinery()->kindlyTo()->int())
417 );
418 if (count($user_ids) !== 1) {
419 $send_bad_request();
420 }
421
422 $user_id = current($user_ids);
424 $forced_events = $this->forumNotificationObj->getForcedEventsObjectByUserId($user_id);
425 $interested_events = $forced_events->getInterestedEvents();
426 $form_gui = new ilForumNotificationEventsFormGUI(
427 $this->ctrl->getFormAction($this->parent_obj, 'saveEventsForUser'),
428 [
429 'hidden_value' => json_encode([
430 'usr_id' => $user_id
431 ], JSON_THROW_ON_ERROR),
432 'notify_modified' => (bool) ($interested_events & ilForumNotificationEvents::UPDATED),
433 'notify_censored' => (bool) ($interested_events & ilForumNotificationEvents::CENSORED),
434 'notify_uncensored' => (bool) ($interested_events & ilForumNotificationEvents::UNCENSORED),
435 'notify_post_deleted' => (bool) ($interested_events & ilForumNotificationEvents::POST_DELETED),
436 'notify_thread_deleted' => (bool) ($interested_events & ilForumNotificationEvents::THREAD_DELETED),
437 ],
438 $this->ui_factory,
439 $this->lng
440 );
441
442 $modal = $this->ui_factory->modal()->roundtrip(
443 $this->lng->txt('notification_settings'),
444 [],
445 $form_gui->getInputs(),
446 $this->ctrl->getFormAction($this, 'saveEventsForUser')
447 );
448
449 $this->http->saveResponse($this->http->response()->withBody(
450 Streams::ofString($this->ui_renderer->renderAsync($modal))
451 )->withHeader(ResponseHeader::CONTENT_TYPE, 'text/html'));
452 $this->http->sendResponse();
453 $this->http->close();
454 }
455
456 public function saveEventsForUserCommand(): void
457 {
458 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
459 $this->error->raiseError(
460 $this->lng->txt('msg_no_perm_read'),
461 $this->error->MESSAGE
462 );
463 }
464
465 $events_form_builder = new ilForumNotificationEventsFormGUI(
466 $this->ctrl->getFormAction($this, 'saveEventsForUser'),
467 null,
468 $this->ui_factory,
469 $this->lng
470 );
471
472 if ($this->http->request()->getMethod() === 'POST') {
473 $form = $events_form_builder->build()->withRequest($this->http->request());
474 $formData = $form->getData();
475
476 $interested_events = ilForumNotificationEvents::DEACTIVATED;
477
478 foreach ($events_form_builder->getValidEvents() as $event) {
479 $interested_events += isset($formData[$event]) && $formData[$event] ? $events_form_builder->getValueForEvent(
480 $event
481 ) : 0;
482 }
483
484 if (isset($formData['hidden_value']) && $formData['hidden_value']) {
485 $hidden_value = json_decode($formData['hidden_value'], false, 512, JSON_THROW_ON_ERROR);
486 $valid_usr_ids = $this->forum->getAllForumParticipants();
487
488 if (in_array($hidden_value->usr_id, $valid_usr_ids)) {
489 $frm_noti = new ilForumNotification($this->parent_obj->getRefId());
490 $frm_noti->setUserId($hidden_value->usr_id);
491 $frm_noti->setForumId($this->forum->getId());
492 $frm_noti->setInterestedEvents($interested_events);
493 $frm_noti->updateInterestedEvents();
494 }
495 }
496 }
497
498 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
499 $this->ctrl->redirect($this, 'showMembers');
500 }
501
502 public function enableAdminForceNotiCommand(): void
503 {
504 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
505 $this->error->raiseError(
506 $this->lng->txt('msg_no_perm_read'),
507 $this->error->MESSAGE
508 );
509 }
510
511 $user_ids = [];
512 if ($this->dic->http()->wrapper()->post()->has('user_id')) {
513 $user_ids = $this->dic->http()->wrapper()->post()->retrieve(
514 'user_id',
515 $this->dic->refinery()->kindlyTo()->listOf($this->dic->refinery()->kindlyTo()->int())
516 );
517 }
518
519 if (count($user_ids) === 0) {
520 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('time_limit_no_users_selected'), true);
521 } else {
522 $frm_noti = new ilForumNotification($this->forum->getRefId());
523
524 foreach ($user_ids as $user_id) {
525 $frm_noti->setUserId((int) $user_id);
526 $frm_noti->setUserToggle(false);
527 $is_enabled = $frm_noti->isAdminForceNotification();
528
529 if (!$is_enabled) {
530 $frm_noti->setAdminForce(true);
531 $frm_noti->insertAdminForce();
532 }
533 }
534
535 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
536 }
537
538 $this->ctrl->redirect($this, 'showMembers');
539 }
540
541 public function disableAdminForceNotiCommand(): void
542 {
543 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
544 $this->error->raiseError(
545 $this->lng->txt('msg_no_perm_read'),
546 $this->error->MESSAGE
547 );
548 }
549
550 $user_ids = [];
551 if ($this->dic->http()->wrapper()->post()->has('user_id')) {
552 $user_ids = $this->dic->http()->wrapper()->post()->retrieve(
553 'user_id',
554 $this->dic->refinery()->kindlyTo()->listOf($this->dic->refinery()->kindlyTo()->int())
555 );
556 }
557
558 if (count($user_ids) === 0) {
559 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('time_limit_no_users_selected'), true);
560 } else {
561 $frm_noti = new ilForumNotification($this->forum->getRefId());
562
563 foreach ($user_ids as $user_id) {
564 $frm_noti->setUserId((int) $user_id);
565 $is_enabled = $frm_noti->isAdminForceNotification();
566
567 if ($is_enabled) {
568 $frm_noti->deleteAdminForce();
569 }
570 }
571
572 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
573 }
574
575 $this->ctrl->redirect($this, 'showMembers');
576 }
577
578 private function enableHideUserToggleNoti(): void
579 {
580 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
581 $this->error->raiseError(
582 $this->lng->txt('msg_no_perm_read'),
583 $this->error->MESSAGE
584 );
585 }
586
587 $user_ids = [];
588 if ($this->dic->http()->wrapper()->query()->has('frm_notifications_table_usr_ids')) {
589 $user_ids = $this->dic->http()->wrapper()->query()->retrieve(
590 'frm_notifications_table_usr_ids',
591 $this->dic->refinery()->kindlyTo()->listOf($this->dic->refinery()->kindlyTo()->string())
592 );
593 if ($user_ids === ['ALL_OBJECTS']) {
594 $table = $this->getForumNotificationTable();
595 $user_ids = $table->getFilteredUserIds($this->ui_service->filter()->getData($table->getFilterComponent()));
596 }
597 }
598
599 if (count($user_ids) === 0) {
600 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('time_limit_no_users_selected'), true);
601 } else {
602 $frm_noti = new ilForumNotification($this->forum->getRefId());
603
604 foreach ($user_ids as $user_id) {
605 $frm_noti->setUserId((int) $user_id);
606 $frm_noti->setUserToggle(true);
607 $is_enabled = $frm_noti->isAdminForceNotification();
608
609 if ($is_enabled) {
610 $frm_noti->updateUserToggle();
611 } else {
612 $frm_noti->setAdminForce(true);
613 $frm_noti->insertAdminForce();
614 }
615 }
616
617 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
618 }
619
620 $this->ctrl->redirect($this, 'showMembers');
621 }
622
623 private function disableHideUserToggleNoti(): void
624 {
625 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
626 $this->error->raiseError(
627 $this->lng->txt('msg_no_perm_read'),
628 $this->error->MESSAGE
629 );
630 }
631
632 $user_ids = [];
633 if ($this->dic->http()->wrapper()->query()->has('frm_notifications_table_usr_ids')) {
634 $user_ids = $this->dic->http()->wrapper()->query()->retrieve(
635 'frm_notifications_table_usr_ids',
636 $this->dic->refinery()->kindlyTo()->listOf($this->dic->refinery()->kindlyTo()->string())
637 );
638 if ($user_ids === ['ALL_OBJECTS']) {
639 $table = $this->getForumNotificationTable();
640 $user_ids = $table->getFilteredUserIds($this->ui_service->filter()->getData($table->getFilterComponent()));
641 }
642 }
643
644 if (count($user_ids) === 0) {
645 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('time_limit_no_users_selected'), true);
646 } else {
647 $frm_noti = new ilForumNotification($this->forum->getRefId());
648
649 foreach ($user_ids as $user_id) {
650 $frm_noti->setUserId((int) $user_id);
651 $frm_noti->setUserToggle(false);
652 $is_enabled = $frm_noti->isAdminForceNotification();
653 if ($is_enabled) {
654 $frm_noti->updateUserToggle();
655 } else {
656 $frm_noti->setAdminForce(true);
657 $frm_noti->insertAdminForce();
658 }
659 }
660
661 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
662 }
663
664 $this->ctrl->redirect($this, 'showMembers');
665 }
666
667 private function initNotificationSettingsForm(): bool
668 {
669 if ($this->notificationSettingsForm === null) {
670 $form = new ilPropertyFormGUI();
671 $form->setFormAction($this->ctrl->getFormAction($this, 'updateNotificationSettings'));
672 $form->setTitle($this->lng->txt('forums_notification_settings'));
673
674 $radio_grp = new ilRadioGroupInputGUI('', 'notification_type');
675 $radio_grp->setValue('default');
676
677 $opt_default = new ilRadioOption(
678 $this->lng->txt('user_decides_notification'),
680 );
681 $opt_0 = new ilRadioOption($this->lng->txt('settings_for_all_members'), NotificationType::ALL_USERS->value);
682 $opt_1 = new ilRadioOption($this->lng->txt('settings_per_users'), NotificationType::PER_USER->value);
683
684 $radio_grp->addOption($opt_default);
685 $radio_grp->addOption($opt_0);
686 $radio_grp->addOption($opt_1);
687
688 $chb_2 = new ilCheckboxInputGUI($this->lng->txt('user_toggle_noti'), 'usr_toggle');
689 $chb_2->setValue('1');
690
691 $opt_0->addSubItem($chb_2);
692
693 $cb_grp = new ilCheckboxGroupInputGUI($this->lng->txt('notification_settings'), 'notification_events');
694
695 $notify_modified = new ilCheckboxOption($this->lng->txt('notify_modified'), (string) ilForumNotificationEvents::UPDATED);
696 $cb_grp->addOption($notify_modified);
697
698 $notify_censored = new ilCheckboxOption($this->lng->txt('notify_censored'), (string) ilForumNotificationEvents::CENSORED);
699 $cb_grp->addOption($notify_censored);
700
701 $notify_uncensored = new ilCheckboxOption($this->lng->txt('notify_uncensored'), (string) ilForumNotificationEvents::UNCENSORED);
702 $cb_grp->addOption($notify_uncensored);
703
704 $notify_post_deleted = new ilCheckboxOption($this->lng->txt('notify_post_deleted'), (string) ilForumNotificationEvents::POST_DELETED);
705 $cb_grp->addOption($notify_post_deleted);
706
707 $notify_thread_deleted = new ilCheckboxOption($this->lng->txt('notify_thread_deleted'), (string) ilForumNotificationEvents::THREAD_DELETED);
708 $cb_grp->addOption($notify_thread_deleted);
709 $opt_0->addSubItem($cb_grp);
710
711 $form->addItem($radio_grp);
712
713 $form->addCommandButton('updateNotificationSettings', $this->lng->txt('save'));
714
715 $this->notificationSettingsForm = $form;
716
717 return false;
718 }
719
720 return true;
721 }
722
723 private function updateNotificationSettingsCommand(): void
724 {
725 if (!$this->access->checkAccess('write', '', $this->parent_obj->getRefId())) {
726 $this->error->raiseError(
727 $this->lng->txt('msg_no_perm_read'),
728 $this->error->MESSAGE
729 );
730 }
731
733
734 $frm_noti = new ilForumNotification($this->forum->getRefId());
735 if ($this->notificationSettingsForm->checkInput()) {
736 $notification_type = NotificationType::tryFrom($this->dic->http()->wrapper()->post()->retrieve(
737 'notification_type',
738 $this->dic->refinery()->byTrying([
739 $this->dic->refinery()->kindlyTo()->string(),
740 $this->dic->refinery()->always(NotificationType::DEFAULT->value)
741 ])
743
744 if ($notification_type === NotificationType::ALL_USERS) {
745 $notification_events = $this->notificationSettingsForm->getInput('notification_events');
746 $interested_events = 0;
747
748 if (is_array($notification_events)) {
749 foreach ($notification_events as $activated_event) {
750 $interested_events += (int) $activated_event;
751 }
752 }
753
754 $this->parent_obj->objProperties->setAdminForceNoti(true);
755 $this->parent_obj->objProperties->setUserToggleNoti(
756 (bool) $this->notificationSettingsForm->getInput('usr_toggle')
757 );
758 $this->parent_obj->objProperties->setNotificationType(NotificationType::ALL_USERS);
759 $this->parent_obj->objProperties->setInterestedEvents($interested_events);
760 } elseif ($notification_type === NotificationType::PER_USER) {
761 $this->parent_obj->objProperties->setNotificationType(NotificationType::PER_USER);
762 $this->parent_obj->objProperties->setAdminForceNoti(true);
763 $this->parent_obj->objProperties->setUserToggleNoti(false);
764 } else {
765 $this->parent_obj->objProperties->setNotificationType(NotificationType::DEFAULT);
766 $this->parent_obj->objProperties->setAdminForceNoti(false);
767 $this->parent_obj->objProperties->setUserToggleNoti(false);
768 $frm_noti->deleteNotificationAllUsers();
769 }
770 $properties = ilForumProperties::getInstance($this->forum->getId());
771 $frm_noti->updateUserNotifications($this->forum->getAllForumParticipants(), $properties);
772
773 $this->parent_obj->objProperties->update();
774
775 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->lng->txt('saved_successfully'), true);
776 }
777 $this->notificationSettingsForm->setValuesByPost();
778
779 $this->ctrl->redirect($this, 'showMembers');
780 }
781
782 public function getUnsafeGetCommands(): array
783 {
784 return [
785 'handleNotificationActions',
786 ];
787 }
788
789 public function getSafePostCommands(): array
790 {
791 return [];
792 }
793
794 private function handleNotificationActionsCommand(): void
795 {
796 $action = $this->http->wrapper()->query()->retrieve(
797 'frm_notifications_table_action',
798 $this->dic->refinery()->byTrying([
799 $this->dic->refinery()->kindlyTo()->string(),
800 $this->dic->refinery()->always(null)
801 ])
802 );
803
804 match ($action) {
805 'enableHideUserToggleNoti' => $this->enableHideUserToggleNoti(),
806 'disableHideUserToggleNoti' => $this->disableHideUserToggleNoti(),
807 'notificationSettings' => $this->notificationSettings(),
808 default => $this->showMembersCommand()
809 };
810 }
811}
Builds data types.
Definition: Factory.php:36
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
error(string $a_errmsg)
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
Error Handling & global info handling.
This class represents a section header in a property form.
Class ilForumNotification.
static getInstance(int $a_obj_id=0)
@ilCtrl_Calls ilForumSettingsGUI: ilObjectContentStyleSettingsGUI
__construct(private readonly ilObjForumGUI $parent_obj, private readonly ilObjForum $forum)
getSafePostCommands()
This method must return a list of safe POST commands.
readonly ILIAS HTTP GlobalHttpState $http
readonly ilAccessHandler $access
readonly UiRenderer $ui_renderer
readonly ILIAS UI Factory $ui_factory
getCustomForm(ilPropertyFormGUI $a_form)
readonly ilSetting $settings
readonly ilGlobalTemplateInterface $tpl
readonly ilUIService $ui_service
readonly ilObjectService $obj_service
addAvailabilitySection(ilPropertyFormGUI $form)
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
readonly ilErrorHandling $error
readonly ilLanguage $lng
updateCustomValues(ilPropertyFormGUI $a_form)
readonly ILIAS DI Container $dic
getCustomValues(array &$a_values)
ilForumNotification $forumNotificationObj
ilPropertyFormGUI $notificationSettingsForm
readonly ilCtrlInterface $ctrl
language handling
@ilCtrl_Calls ilObjForumGUI: ilPermissionGUI, ilForumExportGUI, ilInfoScreenGUI @ilCtrl_Calls ilObjFo...
Class ilObjForum.
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
This class represents a property in a property form.
This class represents an option in a radio group.
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Filter service.
Interface ResponseHeader.
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26