ILIAS  release_8 Revision v8.24
class.ilForumModeratorsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
37 private int $ref_id = 0;
39 private \ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper;
40 private \ILIAS\Refinery\Factory $refinery;
41
42 public function __construct()
43 {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $this->tpl = $DIC->ui()->mainTemplate();
49 $this->lng = $DIC->language();
50 $this->access = $DIC->access();
51 $this->tabs = $DIC->tabs();
52 $this->error = $DIC['ilErr'];
53 $this->user = $DIC->user();
54 $this->toolbar = $DIC->toolbar();
55
56 $this->tabs->activateTab('frm_moderators');
57 $this->lng->loadLanguageModule('search');
58 $this->http_wrapper = $DIC->http()->wrapper();
59 $this->refinery = $DIC->refinery();
60
61 if ($this->http_wrapper->query()->has('ref_id')) {
62 $this->ref_id = $this->http_wrapper->query()->retrieve(
63 'ref_id',
64 $this->refinery->kindlyTo()->int()
65 );
66 }
67
68 if (!$this->access->checkAccess('write', '', (int) $this->ref_id)) {
69 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
70 }
71
72 $this->oForumModerators = new ilForumModerators((int) $this->ref_id);
73 }
74
75 public function executeCommand(): void
76 {
77 $next_class = $this->ctrl->getNextClass($this);
78 $cmd = $this->ctrl->getCmd();
79
80 switch (strtolower($next_class)) {
81 case strtolower(ilRepositorySearchGUI::class):
82 $rep_search = new ilRepositorySearchGUI();
83 $rep_search->setCallback($this, 'addModerator');
84 $this->ctrl->setReturn($this, 'showModerators');
85 $this->ctrl->forwardCommand($rep_search);
86 break;
87
88 default:
89 if (!$cmd) {
90 $cmd = 'showModerators';
91 }
92 $this->$cmd();
93 break;
94 }
95 }
96
97 public function addModerator($users = []): void
98 {
99 if (!$users) {
100 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('frm_moderators_select_one'));
101 return;
102 }
103
104 $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
105 $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
106 $frm_noti_type = $objFrmProps->getNotificationType();
107
108 foreach ($users as $user_id) {
109 $this->oForumModerators->addModeratorRole((int) $user_id);
110 if ($isCrsGrp && $frm_noti_type !== 'default') {
111 $tmp_frm_noti = new ilForumNotification($this->ref_id);
112 $tmp_frm_noti->setUserId((int) $user_id);
113 $tmp_frm_noti->setUserIdNoti($this->user->getId());
114 $tmp_frm_noti->setUserToggle($objFrmProps->getUserToggleNoti());
115 $tmp_frm_noti->setAdminForce($objFrmProps->getAdminForceNoti());
116
117 $tmp_frm_noti->insertAdminForce();
118 }
119 }
120
121 $this->tpl->setOnScreenMessage('success', $this->lng->txt('frm_moderator_role_added_successfully'), true);
122 $this->ctrl->redirect($this, 'showModerators');
123 }
124
125 public function detachModeratorRole(): void
126 {
127 $usr_ids = [];
128 if ($this->http_wrapper->post()->has('usr_id')) {
129 $usr_ids = $this->http_wrapper->post()->retrieve(
130 'usr_id',
131 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())
132 );
133 }
134
135 if (!isset($usr_ids) || !is_array($usr_ids)) {
136 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('frm_moderators_select_at_least_one'));
137 $this->ctrl->redirect($this, 'showModerators');
138 }
139
140 $entries = $this->oForumModerators->getCurrentModerators();
141 if (count($usr_ids) === count($entries)) {
142 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('frm_at_least_one_moderator'));
143 $this->ctrl->redirect($this, 'showModerators');
144 }
145
146 $isCrsGrp = ilForumNotification::_isParentNodeGrpCrs($this->ref_id);
147
148 $objFrmProps = ilForumProperties::getInstance(ilObject::_lookupObjId($this->ref_id));
149 $frm_noti_type = $objFrmProps->getNotificationType();
150
151 foreach ($usr_ids as $usr_id) {
152 $this->oForumModerators->detachModeratorRole((int) $usr_id);
153
154 if ($isCrsGrp && $frm_noti_type !== 'default' && !ilParticipants::_isParticipant($this->ref_id, $usr_id)) {
155 $tmp_frm_noti = new ilForumNotification($this->ref_id);
156 $tmp_frm_noti->setUserId((int) $usr_id);
157 $tmp_frm_noti->setForumId(ilObject::_lookupObjId($this->ref_id));
158
159 $tmp_frm_noti->deleteAdminForce();
160 }
161 }
162
163 $this->tpl->setOnScreenMessage('success', $this->lng->txt('frm_moderators_detached_role_successfully'), true);
164 $this->ctrl->redirect($this, 'showModerators');
165 }
166
167 public function showModerators(): void
168 {
170 $this,
171 $this->toolbar,
172 [
173 'auto_complete_name' => $this->lng->txt('user'),
174 'submit_name' => $this->lng->txt('add'),
175 'add_search' => true,
176 'add_from_container' => $this->oForumModerators->getRefId()
177 ]
178 );
179 if ($this->http_wrapper->query()->has('ref_id')) {
180 $this->ref_id = $this->http_wrapper->query()->retrieve(
181 'ref_id',
182 $this->refinery->kindlyTo()->int()
183 );
184 }
185 $tbl = new ilForumModeratorsTableGUI($this, 'showModerators', $this->ref_id);
186
187 $entries = $this->oForumModerators->getCurrentModerators();
188 $num = count($entries);
189 $result = [];
190 $i = 0;
191 foreach ($entries as $usr_id) {
194 if (!($user instanceof ilObjUser)) {
195 $this->oForumModerators->detachModeratorRole($usr_id);
196 continue;
197 }
198
199 if ($num > 1) {
200 $result[$i]['check'] = ilLegacyFormElementsUtil::formCheckbox(false, 'usr_id[]', (string) $user->getId());
201 } else {
202 $result[$i]['check'] = '';
203 }
204 $result[$i]['login'] = $user->getLogin();
205 $result[$i]['firstname'] = $user->getFirstname();
206 $result[$i]['lastname'] = $user->getLastname();
207 ++$i;
208 }
209
210 $tbl->setData($result);
211 $this->tpl->setContent($tbl->getHTML());
212 }
213}
error(string $a_errmsg)
Error Handling & global info handling uses PEAR error class.
Class ilForumModeratorsGUI.
ILIAS Refinery Factory $refinery
ILIAS HTTP Wrapper WrapperFactory $http_wrapper
ilGlobalTemplateInterface $tpl
Class ilForumModeratorsTableGUI.
Class ilForumModerators.
static _isParentNodeGrpCrs(int $a_ref_id)
static getInstance(int $a_obj_id=0)
language handling
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId(int $ref_id)
static _isParticipant(int $a_ref_id, int $a_usr_id)
Static function to check if a user is a participant of the container object.
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...
global $DIC
Definition: feed.php:28
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc