ILIAS  release_8 Revision v8.24
class.ilOrgUnitUserAssignmentGUI.php
Go to the documentation of this file.
1<?php
2
22
31{
32 public const CMD_ASSIGNMENTS_RECURSIVE = 'assignmentsRecursive';
33 public const SUBTAB_ASSIGNMENTS = 'user_assignments';
34 public const SUBTAB_ASSIGNMENTS_RECURSIVE = 'user_assignments_recursive';
35 private \ilGlobalTemplateInterface $main_tpl;
36 private Services $http;
37 private ilCtrl $ctrl;
41
42 public function __construct()
43 {
44 global $DIC;
45
47
48 $this->main_tpl = $DIC->ui()->mainTemplate();
49 $this->http = $DIC->http();
50 $this->ctrl = $DIC->ctrl();
51 $this->toolbar = $DIC->toolbar();
52 $this->access = $DIC->access();
53 $this->language = $DIC->language();
54 }
55
56 public function executeCommand(): void
57 {
58 if (!ilObjOrgUnitAccess::_checkAccessPositions((int) filter_input(
59 INPUT_GET,
60 "ref_id",
61 FILTER_SANITIZE_NUMBER_INT
62 ))) {
63 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("permission_denied"), true);
64 $this->ctrl->redirectByClass(ilObjOrgUnitGUI::class);
65 }
66
67 $r = $this->http->request();
68 switch ($this->ctrl->getNextClass()) {
69 case strtolower(ilRepositorySearchGUI::class):
70 switch ($this->ctrl->getCmd()) {
71 case 'addUserFromAutoComplete':
72 if ($r->getQueryParams()['addusertype'] == "staff") {
73 $this->addStaff();
74 }
75 break;
76 default:
77 $repo = new ilRepositorySearchGUI();
78 $repo->setCallback($this, 'addStaffFromSearch');
79 $this->ctrl->forwardCommand($repo);
80 break;
81 }
82 break;
83
84 default:
85 parent::executeCommand();
86 break;
87 }
88 }
89
90 protected function index(): void
91 {
92 $this->addSubTabs();
93 $this->activeSubTab(self::SUBTAB_ASSIGNMENTS);
94
95 // Header
96 $types = ilOrgUnitPosition::getArray('id', 'title');
97 //$types = array();
98 $this->ctrl->setParameterByClass(ilRepositorySearchGUI::class, 'addusertype', 'staff');
100 'auto_complete_name' => $this->language->txt('user'),
101 'user_type' => $types,
102 'submit_name' => $this->language->txt('add'),
103 ));
104
105 // Tables
106 $html = '';
107 foreach (ilOrgUnitPosition::getActiveForPosition($this->getParentRefId()) as $ilOrgUnitPosition) {
108 $ilOrgUnitUserAssignmentTableGUI = new ilOrgUnitUserAssignmentTableGUI(
109 $this,
110 self::CMD_INDEX,
111 $ilOrgUnitPosition
112 );
113 $html .= $ilOrgUnitUserAssignmentTableGUI->getHTML();
114 }
115 $this->setContent($html);
116 }
117
118 protected function assignmentsRecursive(): void
119 {
120 $this->addSubTabs();
121 $this->activeSubTab(self::SUBTAB_ASSIGNMENTS_RECURSIVE);
122 // Tables
123 $html = '';
124 foreach (ilOrgUnitPosition::getActiveForPosition($this->getParentRefId()) as $ilOrgUnitPosition) {
125 $ilOrgUnitRecursiveUserAssignmentTableGUI =
127 $this,
128 self::CMD_ASSIGNMENTS_RECURSIVE,
129 $ilOrgUnitPosition
130 );
131 $html .= $ilOrgUnitRecursiveUserAssignmentTableGUI->getHTML();
132 }
133 $this->setContent($html);
134 }
135
136 protected function confirm(): void
137 {
138 $confirmation = $this->getConfirmationGUI();
139 $confirmation->setConfirm($this->language->txt('remove_user'), self::CMD_DELETE);
140
141 $this->setContent($confirmation->getHTML());
142 }
143
144 protected function confirmRecursive(): void
145 {
146 $confirmation = $this->getConfirmationGUI();
147 $confirmation->setConfirm($this->language->txt('remove_user'), self::CMD_DELETE_RECURSIVE);
148
149 $this->setContent($confirmation->getHTML());
150 }
151
153 {
154 $this->ctrl->saveParameter($this, 'position_id');
155 $confirmation = new ilConfirmationGUI();
156 $confirmation->setFormAction($this->ctrl->getFormAction($this));
157 $confirmation->setCancel($this->language->txt(self::CMD_CANCEL), self::CMD_CANCEL);
158
159 $params = $this->http->request()->getQueryParams();
160 $usr_id = $params['usr_id'];
161 $position_id = $params['position_id'];
162
163 $types = ilOrgUnitPosition::getArray('id', 'title');
164 $position_title = $types[$position_id];
165
166 $confirmation->setHeaderText(sprintf($this->language->txt('msg_confirm_remove_user'), $position_title));
167 $confirmation->addItem('usr_id', $usr_id, ilObjUser::_lookupLogin($usr_id));
168
169 return $confirmation;
170 }
171
172 protected function delete(): void
173 {
174 $params = $this->http->request()->getQueryParams();
175 $usr_id = $_POST['usr_id'];
176 $position_id = $params['position_id'];
177
178 $ua = ilOrgUnitUserAssignmentQueries::getInstance()->getAssignmentOrFail(
179 $usr_id,
180 $position_id,
181 $this->getParentRefId()
182 );
183 $ua->delete();
184 $this->main_tpl->setOnScreenMessage('success', $this->language->txt('remove_successful'), true);
185 $this->cancel();
186 }
187
188 protected function deleteRecursive()
189 {
190 $r = $this->http->request();
192 ->getAssignmentsOfUserIdAndPosition((int) $_POST['usr_id'], (int) $r->getQueryParams()['position_id'])
193 ;
194
195 foreach ($assignments as $assignment) {
196 $assignment->delete();
197 }
198 $this->main_tpl->setOnScreenMessage('success', $this->language->txt('remove_successful'), true);
199 $this->cancel();
200 }
201
202 protected function cancel(): void
203 {
204 $this->ctrl->redirect($this, self::CMD_INDEX);
205 }
206
207 public function addStaff(): void
208 {
209 if (!$this->access->checkAccess("write", "", $this->getParentRefId())) {
210 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("permission_denied"), true);
211 $this->ctrl->redirect($this, self::CMD_INDEX);
212 }
213
214 $users = explode(',', $_POST['user_login']);
215 $user_ids = array();
216 foreach ($users as $user) {
217 $user_id = ilObjUser::_lookupId($user);
218 if ($user_id) {
219 $user_ids[] = $user_id;
220 }
221 }
222
223 if (!count($user_ids)) {
224 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("user_not_found"), true);
225 $this->ctrl->redirect($this, self::CMD_INDEX);
226 }
227
228 $position_id = (int) ($_POST['user_type'] ?? ilOrgUnitPosition::CORE_POSITION_EMPLOYEE);
229
230 if (!$position_id && !$position = ilOrgUnitPosition::find($position_id)) {
231 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("user_not_found"), true);
232 $this->ctrl->redirect($this, self::CMD_INDEX);
233 }
234 foreach ($user_ids as $user_id) {
235 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getParentRefId());
236 }
237
238 $this->main_tpl->setOnScreenMessage('success', $this->language->txt("users_successfuly_added"), true);
239 $this->ctrl->redirect($this, self::CMD_INDEX);
240 }
241
245 public function addStaffFromSearch(array $user_ids, ?string $user_type = null): void
246 {
247 if (!$this->access->checkAccess("write", "", $this->getParentRefId())) {
248 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("permission_denied"), true);
249 $this->ctrl->redirect($this, self::CMD_INDEX);
250 }
251
252 if (!count($user_ids)) {
253 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("user_not_found"), true);
254 $this->ctrl->redirect($this, self::CMD_INDEX);
255 }
256
257 $position_id = (int) ($user_type ?? ilOrgUnitPosition::CORE_POSITION_EMPLOYEE);
258
259 if (!$position_id && !$position = ilOrgUnitPosition::find($position_id)) {
260 $this->main_tpl->setOnScreenMessage('failure', $this->language->txt("user_not_found"), true);
261 $this->ctrl->redirect($this, self::CMD_INDEX);
262 }
263 foreach ($user_ids as $user_id) {
264 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getParentRefId());
265 }
266
267 $this->main_tpl->setOnScreenMessage('success', $this->language->txt("users_successfuly_added"), true);
268 $this->ctrl->redirect($this, self::CMD_INDEX);
269 }
270
271 public function addSubTabs(): void
272 {
273 $this->pushSubTab(self::SUBTAB_ASSIGNMENTS, $this->ctrl
274 ->getLinkTarget($this, self::CMD_INDEX));
275 $this->pushSubTab(self::SUBTAB_ASSIGNMENTS_RECURSIVE, $this->ctrl
276 ->getLinkTarget(
277 $this,
278 self::CMD_ASSIGNMENTS_RECURSIVE
279 ));
280 }
281}
static getArray(?string $key=null, $values=null)
Class Services.
Definition: Services.php:38
pushSubTab(string $subtab_id, string $url)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
static _checkAccessPositions(int $ref_id)
static _lookupId($a_user_str)
static _lookupLogin(int $a_user_id)
static getActiveForPosition(int $orgu_ref_id)
Class ilOrgUnitUserAssignmentGUI.
addStaffFromSearch(array $user_ids, ?string $user_type=null)
Class ilOrgUnitUserAssignmentTableGUI.
static findOrCreateAssignment(int $user_id, int $position_id, int $orgu_id)
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...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc