ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilIndividualAssessmentMembersGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\UI;
23
33{
34 public const F_STATUS = "status";
35 public const F_SORT = "sortation";
36
37 public const S_NAME_ASC = "user_login:asc";
38 public const S_NAME_DESC = "user_login:desc";
39 public const S_EXAMINER_ASC = "examiner_login:asc";
40 public const S_EXAMINER_DESC = "examiner_login:desc";
41 public const S_CHANGETIME_ASC = "change_time:asc";
42 public const S_CHANGETIME_DESC = "change_time:desc";
43
44 protected ilCtrl $ctrl;
46 protected int $ref_id;
48 protected ilLanguage $lng;
50 protected ilObjUser $user;
51 protected ilTabsGUI $tabs;
53 protected UI\Factory $factory;
54 protected UI\Renderer $renderer;
61
62 public function __construct(
76 ILIAS\HTTP\Wrapper\WrapperFactory $wrapper,
78 ) {
79 $this->object = $object;
80 $this->ctrl = $ctrl;
81 $this->tpl = $tpl;
82 $this->lng = $lng;
83 $this->toolbar = $toolbar;
84 $this->user = $user;
85 $this->tabs = $tabs;
86 $this->iass_access = $iass_access;
87 $this->factory = $factory;
88 $this->renderer = $renderer;
89 $this->error_object = $error_object;
90 $this->member_gui = $member_gui;
91 $this->refinery = $refinery;
92 $this->request_wrapper = $wrapper->query();
93 $this->post_wrapper = $wrapper->post();
94 $this->date_formatter = $date_formatter;
95
96 $this->ref_id = $object->getRefId();
97 }
98
99 public function executeCommand(): void
100 {
101 if (!$this->iass_access->mayEditMembers()
102 && !$this->iass_access->mayGradeAnyUser()
103 && !$this->iass_access->mayViewAnyUser()
104 && !$this->iass_access->mayAmendAllUsers()
105 ) {
106 $this->handleAccessViolation();
107 }
108 $cmd = $this->ctrl->getCmd();
109 $next_class = $this->ctrl->getNextClass();
110 $this->ctrl->saveParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS);
111 $this->tpl->setPermanentLink("iass", $this->ref_id);
112
113 switch ($next_class) {
114 case "ilrepositorysearchgui":
115 $rep_search = new ilRepositorySearchGUI();
116 $rep_search->setCallback($this, "addUsersFromSearch");
117 $rep_search->addUserAccessFilterCallable(
118 function ($a_user_ids) {
119 return $a_user_ids;
120 }
121 );
122 $this->ctrl->forwardCommand($rep_search);
123 break;
124 case "ilindividualassessmentmembergui":
125 $this->tabs->clearTargets();
126 $this->tabs->setBackTarget(
127 $this->lng->txt('back'),
128 $this->ctrl->getLinkTargetByClass(self::class, 'view')
129 );
130 $this->ctrl->forwardCommand($this->member_gui);
131 break;
132 default:
133 if (!$cmd) {
134 $cmd = 'view';
135 }
136 $this->$cmd();
137 break;
138 }
139 }
140
141 protected function addedUsers(): void
142 {
143 $r = $this->refinery;
144 if ($this->request_wrapper->retrieve('failure', $r->byTrying([$r->kindlyTo()->bool(), $r->always(false)]))) {
145 $this->tpl->setOnScreenMessage("failure", $this->txt('iass_add_user_failure'));
146 } else {
147 $this->tpl->setOnScreenMessage("success", $this->txt('iass_add_user_success'));
148 }
149 $this->view();
150 }
151
152 protected function view(): void
153 {
154 if ($this->iass_access->mayEditMembers()) {
155 $search_params = ['crs', 'grp'];
156 $container_id = $this->object->getParentContainerIdByType($this->ref_id, $search_params);
157 if ($container_id !== 0) {
159 $this,
160 $this->toolbar,
161 array(
162 'auto_complete_name' => $this->txt('user'),
163 'submit_name' => $this->txt('add'),
164 'add_search' => true,
165 'add_from_container' => $container_id
166 )
167 );
168 } else {
170 $this,
171 $this->toolbar,
172 array(
173 'auto_complete_name' => $this->txt('user'),
174 'submit_name' => $this->txt('add'),
175 'add_search' => true
176 )
177 );
178 }
179 }
181 $this,
182 $this->lng,
183 $this->ctrl,
184 $this->iass_access,
185 $this->factory,
186 $this->renderer,
187 $this->user,
188 $this->date_formatter
189 );
190
191 $filter = $this->getFilterValue();
192
193 $sort = $this->getSortValue();
194 if ($sort === null) {
195 $sort = self::S_NAME_ASC;
196 }
197
198 $entries = $this->object->loadMembersAsSingleObjects($filter, $sort);
199 $table->setData($entries);
200 $view_controls = $this->getViewControls();
201
202 $output = $table->render($view_controls);
203
204 $this->tpl->setContent($output);
205 }
206
210 public function addUsersFromSearch(array $user_ids): void
211 {
212 if (!empty($user_ids)) {
213 $this->addUsers($user_ids);
214 }
215
216 $this->tpl->setOnScreenMessage("info", $this->txt("search_no_selection"), true);
217 $this->ctrl->redirect($this, 'view');
218 }
219
225 public function addUsers(array $user_ids): void
226 {
227 if (!$this->iass_access->mayEditMembers()) {
228 $this->handleAccessViolation();
229 }
230 $iass = $this->object;
231 $members = $iass->loadMembers();
232 $failure = null;
233 if (count($user_ids) === 0) {
234 $failure = 1;
235 }
236 foreach ($user_ids as $user_id) {
237 $user = new ilObjUser($user_id);
238 if (!$members->userAllreadyMember($user)) {
239 $members = $members->withAdditionalUser($user);
240 } else {
241 $failure = 1;
242 }
243 }
244 $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
246 $this->ctrl->setParameter($this, 'failure', $failure);
247 $this->ctrl->redirect($this, 'addedUsers');
248 }
249
253 protected function removeUserConfirmation(): void
254 {
255 if (!$this->iass_access->mayEditMembers()) {
256 $this->handleAccessViolation();
257 }
258 $usr_id = $this->request_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
259 $message = $this->lng->txt('iass_remove_user_qst');
260
261 $this->ctrl->setParameterByClass(self::class, 'usr_id', $usr_id);
262 $remove = $this->ctrl->getFormAction($this, 'removeUser');
263 $cancel = $this->ctrl->getFormAction($this, 'view');
264 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
265
266 $buttons = [
267 $this->factory->button()->standard($this->lng->txt('remove'), $remove),
268 $this->factory->button()->standard($this->lng->txt('cancel'), $cancel)
269 ];
270 $message_box = $this->factory->messageBox()->confirmation($message)->withButtons($buttons);
271 $this->tpl->setContent($this->renderer->render($message_box));
272 }
273
277 public function removeUser(): void
278 {
279 if (!$this->iass_access->mayEditMembers()) {
280 $this->handleAccessViolation();
281 }
282 $usr_id = $this->request_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
283 $iass = $this->object;
284 $iass->loadMembers()
285 ->withoutPresentUser(new ilObjUser($usr_id))
286 ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
287 ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
288 $this->tpl->setOnScreenMessage("success", $this->txt("iass_user_removed"), true);
289 $this->ctrl->redirect($this, 'view');
290 }
291
295 protected function getViewControls(): array
296 {
297 $ret = array();
298
299 $vc_factory = $this->factory->viewControl();
300
301 $sort = $this->getSortationControl($vc_factory);
302 $ret[] = $this->getModeControl($vc_factory);
303 $ret[] = $sort;
304
305 return $ret;
306 }
307
308 protected function getModeControl(ViewControl\Factory $vc_factory): ViewControl\Mode
309 {
310 $vc = $vc_factory->mode(
311 $this->getModeOptions(),
312 ""
313 );
314
315 if ($this->request_wrapper->has(self::F_STATUS)) {
316 $vc = $vc->withActive(
317 $this->request_wrapper->retrieve(
318 self::F_STATUS,
319 $this->refinery->kindlyTo()->string()
320 )
321 );
322 }
323
324 return $vc;
325 }
326
327 protected function getSortationControl(ViewControl\Factory $vc_factory): ViewControl\Sortation
328 {
329 $target = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
330 return $vc_factory->sortation(
331 $this->getSortOptions(),
332 $this->getSortValue() ?? self::S_NAME_ASC
333 )
334 ->withTargetURL($target, self::F_SORT);
335 }
336
340 protected function getModeOptions(): array
341 {
342 $ret = [];
343
344 $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
345
346 if ($this->iass_access->mayViewAnyUser()) {
347 $ret[$this->txt("iass_filter_not_started")] =
349 $ret[$this->txt("iass_filter_not_finalized")] =
351 $ret[$this->txt("iass_filter_finalized")] =
353 $ret[$this->txt("iass_filter_failed")] =
355 }
356 return $ret;
357 }
358
362 protected function getActiveLabelForModeByFilter($filter): string
363 {
364 switch ($filter) {
366 return $this->txt("iass_filter_not_started");
368 return $this->txt("iass_filter_not_finalized");
370 return $this->txt("iass_filter_finalized");
372 return $this->txt("iass_filter_failed");
373 default:
374 return $this->txt("iass_filter_all");
375 }
376 }
377
381 protected function getLinkForStatusFilter($value): string
382 {
383 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, $this->getSortValue());
384 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
385 $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
386 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
387
388 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, null);
389
390 return $link;
391 }
392
393 protected function getFilterValue(): ?string
394 {
395 if (
396 $this->request_wrapper->has(self::F_STATUS) &&
397 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()) != "" &&
398 in_array(
399 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()),
400 [
405 ]
406 )
407 ) {
408 return $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string());
409 }
410
411 return null;
412 }
413
414 protected function getSortOptions(): array
415 {
416 return [
417 self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
418 self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
419 self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
420 self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
421 self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
422 self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
423 ];
424 }
425
426 protected function getSortValue(): ?string
427 {
428 if (
429 $this->request_wrapper->has(self::F_SORT) &&
430 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()) != "" &&
431 in_array(
432 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()),
433 [
434 self::S_NAME_ASC,
435 self::S_NAME_DESC,
436 self::S_EXAMINER_ASC,
437 self::S_EXAMINER_DESC,
438 self::S_CHANGETIME_ASC,
439 self::S_CHANGETIME_DESC
440 ]
441 )
442 ) {
443 return $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string());
444 }
445
446 return null;
447 }
448
449 public function handleAccessViolation(): void
450 {
451 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
452 }
453
454 protected function txt(string $code): string
455 {
456 return $this->lng->txt($code);
457 }
458}
renderer()
factory()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Definition: UI.php:24
Class ilCtrl provides processing control methods.
Error Handling & global info handling.
static updateLPStatusByIds(int $iass_id, array $usr_ids)
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
__construct(ilObjIndividualAssessment $object, ilCtrl $ctrl, ilGlobalPageTemplate $tpl, ilLanguage $lng, ilToolbarGUI $toolbar, ilObjUser $user, ilTabsGUI $tabs, IndividualAssessmentAccessHandler $iass_access, UI\Factory $factory, UI\Renderer $renderer, ilErrorHandling $error_object, ilIndividualAssessmentMemberGUI $member_gui, ILIAS\Refinery\Factory $refinery, ILIAS\HTTP\Wrapper\WrapperFactory $wrapper, ilIndividualAssessmentDateFormatter $date_formatter)
ilIndividualAssessmentDateFormatter $date_formatter
removeUser()
Remove users from corresponding iass-object.
addUsers(array $user_ids)
Add users to corresponding iass-object.
removeUserConfirmation()
Display confirmation form for user might be removed.
ILIAS HTTP Wrapper ArrayBasedRequestWrapper $post_wrapper
language handling
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
loadMembers()
Get the members object associated with this.
User class.
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...
Interface RequestWrapper.
This describes a Mode Control.
Definition: Mode.php:29
withActive(string $label)
set the currently active/engaged Button by label.
This describes a Sortation Control.
Definition: Sortation.php:32
An entity that renders components to a string output.
Definition: Renderer.php:31
Mechanic regarding the access control and roles of an objet goes here.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.