ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumModeratorsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 private const string CMD_SHOW_MODERATORS = 'showModerators';
29 private const string CMD_ADD_MODERATOR = 'addModerator';
30 private const string CMD_HANDLE_TABLE_ACTIONS = 'handleModeratorActions';
31 private const string DEFAULT_CMD = self::CMD_SHOW_MODERATORS;
32
33 private readonly ilCtrlInterface $ctrl;
35 private readonly ilLanguage $lng;
36 private readonly ilTabsGUI $tabs;
37 private readonly ilErrorHandling $error;
38 private readonly ilObjUser $user;
39 private readonly ilToolbarGUI $toolbar;
41 private readonly ilAccessHandler $access;
42 private readonly \ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper;
43 private readonly \ILIAS\Refinery\Factory $refinery;
44 private readonly \ILIAS\HTTP\Services $http;
45 private readonly \ILIAS\UI\Factory $ui_factory;
46 private readonly \ILIAS\UI\Renderer $ui_renderer;
47
48 public function __construct(private readonly ilObjForum $forum)
49 {
51 global $DIC;
52
53 $this->ctrl = $DIC->ctrl();
54 $this->tpl = $DIC->ui()->mainTemplate();
55 $this->lng = $DIC->language();
56 $this->access = $DIC->access();
57 $this->tabs = $DIC->tabs();
58 $this->error = $DIC['ilErr'];
59 $this->user = $DIC->user();
60 $this->toolbar = $DIC->toolbar();
61
62 $this->lng->loadLanguageModule('search');
63 $this->http_wrapper = $DIC->http()->wrapper();
64 $this->http = $DIC->http();
65 $this->refinery = $DIC->refinery();
66 $this->ui_renderer = $DIC->ui()->renderer();
67 $this->ui_factory = $DIC->ui()->factory();
68
69 $this->frm_moderators = new ilForumModerators($this->forum->getRefId());
70 }
71
72 public function executeCommand(): void
73 {
74 if (!$this->access->checkAccess('write', '', $this->forum->getRefId())) {
75 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
76 }
77
78 $this->tabs->activateTab('frm_moderators');
79
80 $next_class = $this->ctrl->getNextClass($this) ?? '';
81 $cmd = $this->ctrl->getCmd();
82
83 switch (strtolower($next_class)) {
84 case strtolower(ilRepositorySearchGUI::class):
85 $rep_search = new ilRepositorySearchGUI();
86 $rep_search->setCallback($this, self::CMD_ADD_MODERATOR . 'Command');
87 $this->ctrl->setReturn($this, self::CMD_SHOW_MODERATORS);
88 $this->ctrl->forwardCommand($rep_search);
89 break;
90
91 default:
92 if ($cmd === null || $cmd === '' || !method_exists($this, $cmd . 'Command')) {
93 $cmd = self::DEFAULT_CMD;
94 }
95 $verified_command = $cmd . 'Command';
96
97 $this->$verified_command();
98 break;
99 }
100 }
101
105 public function addModeratorCommand(array $users = []): void
106 {
107 if ($users === []) {
108 $this->tpl->setOnScreenMessage(
109 $this->tpl::MESSAGE_TYPE_FAILURE,
110 $this->lng->txt('frm_moderators_select_one')
111 );
112 return;
113 }
114
115 $frm_properties = ilForumProperties::getInstance(ilObject::_lookupObjId($this->forum->getRefId()));
116 $notificaton_type = $frm_properties->getNotificationType();
117 $is_membersip_enabled_parent = $this->forum->isParentMembershipEnabledContainer();
118 $tmp_frm_noti = new ilForumNotification($this->forum->getRefId());
119
120 foreach ($users as $usr_id) {
121 $this->frm_moderators->addModeratorRole($usr_id);
122 if ($is_membersip_enabled_parent && $notificaton_type !== NotificationType::DEFAULT) {
123 $tmp_frm_noti->setUserId($usr_id);
124 $tmp_frm_noti->setUserIdNoti($this->user->getId());
125 $tmp_frm_noti->setUserToggle($frm_properties->getUserToggleNoti());
126 $tmp_frm_noti->setAdminForce($frm_properties->getAdminForceNoti());
127 $tmp_frm_noti->insertAdminForce();
128 }
129 }
130
131 $this->tpl->setOnScreenMessage(
132 $this->tpl::MESSAGE_TYPE_SUCCESS,
133 $this->lng->txt('frm_moderator_role_added_successfully'),
134 true
135 );
136 $this->ctrl->redirect($this, self::CMD_SHOW_MODERATORS);
137 }
138
139 private function detachModeratorRole(): void
140 {
141 $usr_ids = $this->http_wrapper->query()->retrieve(
142 'frm_moderators_table_usr_ids',
143 $this->refinery->byTrying([
144 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
145 $this->refinery->always([])
146 ])
147 );
148
149 if ($usr_ids === []) {
150 $this->tpl->setOnScreenMessage(
151 $this->tpl::MESSAGE_TYPE_FAILURE,
152 $this->lng->txt('frm_moderators_select_at_least_one')
153 );
154 $this->ctrl->redirect($this, self::CMD_SHOW_MODERATORS);
155 }
156
157 $entries = $this->frm_moderators->getCurrentModerators();
158 if (count($usr_ids) === count($entries)) {
159 $this->tpl->setOnScreenMessage(
160 $this->tpl::MESSAGE_TYPE_FAILURE,
161 $this->lng->txt('frm_at_least_one_moderator'),
162 true
163 );
164 $this->ctrl->redirect($this, self::CMD_SHOW_MODERATORS);
165 }
166
167 $frm_properties = ilForumProperties::getInstance(ilObject::_lookupObjId($this->forum->getRefId()));
168 $obj_id = $frm_properties->getObjId();
169 $notificaton_type = $frm_properties->getNotificationType();
170 $is_membersip_enabled_parent = $this->forum->isParentMembershipEnabledContainer();
171 $need_participants = $is_membersip_enabled_parent && $notificaton_type !== NotificationType::DEFAULT;
172 $tmp_frm_noti = new ilForumNotification($this->forum->getRefId());
173
174 $participants_result = $need_participants
175 ? new \ILIAS\Data\Result\Ok($this->forum->parentParticipants())
176 : new \ILIAS\Data\Result\Error("Participants not required for ref_id {$this->forum->getRefId()}");
177
178 foreach ($usr_ids as $usr_id) {
179 $this->frm_moderators->detachModeratorRole($usr_id);
180 $participants_result->map(function (ilParticipants $participants) use ($tmp_frm_noti, $usr_id, $obj_id) {
181 if (!$participants->isAssigned($usr_id)) {
182 $tmp_frm_noti->setUserId($usr_id);
183 $tmp_frm_noti->setForumId($obj_id);
184 $tmp_frm_noti->deleteAdminForce();
185 }
186 });
187 }
188
189 $this->tpl->setOnScreenMessage(
190 $this->tpl::MESSAGE_TYPE_SUCCESS,
191 $this->lng->txt('frm_moderators_detached_role_successfully'),
192 true
193 );
194 $this->ctrl->redirect($this, self::CMD_SHOW_MODERATORS);
195 }
196
197 private function showModeratorsCommand(): void
198 {
200 $this,
201 $this->toolbar,
202 [
203 'auto_complete_name' => $this->lng->txt('user'),
204 'submit_name' => $this->lng->txt('add'),
205 'add_search' => true,
206 'add_from_container' => $this->frm_moderators->getRefId()
207 ]
208 );
209
210 $tbl = new \ILIAS\Forum\Moderation\ForumModeratorsTable(
211 $this->frm_moderators,
212 $this->lng,
213 $this->http,
214 $this->ui_factory,
215 ilUtil::_getHttpPath() . '/' . $this->ctrl->getLinkTarget(
216 $this,
217 self::CMD_HANDLE_TABLE_ACTIONS
218 )
219 );
220
221 $this->tpl->setContent($this->ui_renderer->render($tbl->getComponent()));
222 }
223
224 private function handleModeratorActionsCommand(): void
225 {
226 $action = $this->http_wrapper->query()->retrieve(
227 'frm_moderators_table_action',
228 $this->refinery->byTrying([
229 $this->refinery->kindlyTo()->string(),
230 $this->refinery->always('')
231 ])
232 );
233 match ($action) {
234 'detachModeratorRole' => $this->detachModeratorRole(),
235 default => $this->ctrl->redirect($this, self::CMD_SHOW_MODERATORS),
236 };
237 }
238
239 public function getUnsafeGetCommands(): array
240 {
241 return [
243 ];
244 }
245
246 public function getSafePostCommands(): array
247 {
248 return [];
249 }
250}
error(string $a_errmsg)
Error Handling & global info handling.
@ilCtrl_Calls ilForumModeratorsGUI: ilRepositorySearchGUI
readonly ilToolbarGUI $toolbar
readonly ilGlobalTemplateInterface $tpl
readonly ILIAS UI Renderer $ui_renderer
readonly ilCtrlInterface $ctrl
readonly ILIAS HTTP Wrapper WrapperFactory $http_wrapper
readonly ilAccessHandler $access
readonly ilForumModerators $frm_moderators
getUnsafeGetCommands()
This method must return a list of unsafe GET commands.
readonly ILIAS Refinery Factory $refinery
readonly ILIAS HTTP Services $http
readonly ilErrorHandling $error
readonly ILIAS UI Factory $ui_factory
getSafePostCommands()
This method must return a list of safe POST commands.
Class ilForumModerators.
Class ilForumNotification.
static getInstance(int $a_obj_id=0)
language handling
Class ilObjForum.
User class.
static _lookupObjId(int $ref_id)
Base class for course and group participants.
isAssigned(int $a_usr_id)
check if user is assigned
static fillAutoCompleteToolbar(object $parent_object, ?ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
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 _getHttpPath()
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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26