ILIAS  release_8 Revision v8.24
class.ilIndividualAssessmentMembersGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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;
61
62 public function __construct(
75 ILIAS\Refinery\Factory $refinery,
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 $sort = $this->getSortValue();
193
194 $entries = $this->object->loadMembersAsSingleObjects($filter, $sort);
195 $table->setData($entries);
196 $view_controls = $this->getViewControls();
197
198 $output = $table->render($view_controls);
199
200 if (count($entries) == 0) {
201 $output .= $this->txt("iass_no_entries");
202 }
203 $this->tpl->setContent($output);
204 }
205
209 public function addUsersFromSearch(array $user_ids): void
210 {
211 if (!empty($user_ids)) {
212 $this->addUsers($user_ids);
213 }
214
215 $this->tpl->setOnScreenMessage("info", $this->txt("search_no_selection"), true);
216 $this->ctrl->redirect($this, 'view');
217 }
218
224 public function addUsers(array $user_ids): void
225 {
226 if (!$this->iass_access->mayEditMembers()) {
227 $this->handleAccessViolation();
228 }
229 $iass = $this->object;
230 $members = $iass->loadMembers();
231 $failure = null;
232 if (count($user_ids) === 0) {
233 $failure = 1;
234 }
235 foreach ($user_ids as $user_id) {
236 $user = new ilObjUser($user_id);
237 if (!$members->userAllreadyMember($user)) {
238 $members = $members->withAdditionalUser($user);
239 } else {
240 $failure = 1;
241 }
242 }
243 $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
245 $this->ctrl->setParameter($this, 'failure', $failure);
246 $this->ctrl->redirect($this, 'addedUsers');
247 }
248
252 protected function removeUserConfirmation(): void
253 {
254 if (!$this->iass_access->mayEditMembers()) {
255 $this->handleAccessViolation();
256 }
257 $usr_id = $this->request_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
258 $confirm = new ilConfirmationGUI();
259 $confirm->addItem('usr_id', (string) $usr_id, ilObjUser::_lookupFullname($usr_id));
260 $confirm->setHeaderText($this->txt('iass_remove_user_qst'));
261 $confirm->setFormAction($this->ctrl->getFormAction($this));
262 $confirm->setConfirm($this->txt('remove'), 'removeUser');
263 $confirm->setCancel($this->txt('cancel'), 'view');
264 $this->tpl->setContent($confirm->getHTML());
265 }
266
270 public function removeUser(): void
271 {
272 if (!$this->iass_access->mayEditMembers()) {
273 $this->handleAccessViolation();
274 }
275 $usr_id = $this->post_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
276 $iass = $this->object;
277 $iass->loadMembers()
278 ->withoutPresentUser(new ilObjUser($usr_id))
279 ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
280 ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
281 $this->tpl->setOnScreenMessage("success", $this->txt("iass_user_removed"), true);
282 $this->ctrl->redirect($this, 'view');
283 }
284
288 protected function getViewControls(): array
289 {
290 $ret = array();
291
292 $vc_factory = $this->factory->viewControl();
293
294 $sort = $this->getSortationControl($vc_factory);
295 $ret[] = $this->getModeControl($vc_factory);
296 $ret[] = $sort;
297
298 return $ret;
299 }
300
301 protected function getModeControl(ViewControl\Factory $vc_factory): ViewControl\Mode
302 {
303 $vc = $vc_factory->mode(
304 $this->getModeOptions(),
305 ""
306 );
307
308 if ($this->request_wrapper->has(self::F_STATUS)) {
309 $vc = $vc->withActive(
310 $this->request_wrapper->retrieve(
311 self::F_STATUS,
312 $this->refinery->kindlyTo()->string()
313 )
314 );
315 }
316
317 return $vc;
318 }
319
320 protected function getSortationControl(ViewControl\Factory $vc_factory): ViewControl\Sortation
321 {
322 $target = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
323 return $vc_factory->sortation(
324 $this->getSortOptions()
325 )
326 ->withTargetURL($target, self::F_SORT)
327 ->withLabel($this->getSortOptions()[$this->getSortValue() ?? self::S_NAME_ASC]);
328 }
329
333 protected function getModeOptions(): array
334 {
335 $ret = [];
336
337 $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
338
339 if ($this->iass_access->mayViewAnyUser()) {
340 $ret[$this->txt("iass_filter_not_started")] =
342 $ret[$this->txt("iass_filter_not_finalized")] =
344 $ret[$this->txt("iass_filter_finalized")] =
346 $ret[$this->txt("iass_filter_failed")] =
348 }
349 return $ret;
350 }
351
355 protected function getActiveLabelForModeByFilter($filter): string
356 {
357 switch ($filter) {
359 return $this->txt("iass_filter_not_started");
361 return $this->txt("iass_filter_not_finalized");
363 return $this->txt("iass_filter_finalized");
365 return $this->txt("iass_filter_failed");
366 default:
367 return $this->txt("iass_filter_all");
368 }
369 }
370
374 protected function getLinkForStatusFilter($value): string
375 {
376 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, $this->getSortValue());
377 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
378 $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
379 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
380
381 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, null);
382
383 return $link;
384 }
385
386 protected function getFilterValue(): ?string
387 {
388 if (
389 $this->request_wrapper->has(self::F_STATUS) &&
390 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()) != "" &&
391 in_array(
392 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()),
393 [
398 ]
399 )
400 ) {
401 return $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string());
402 }
403
404 return null;
405 }
406
407 protected function getSortOptions(): array
408 {
409 return [
410 self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
411 self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
412 self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
413 self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
414 self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
415 self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
416 ];
417 }
418
419 protected function getSortValue(): ?string
420 {
421 if (
422 $this->request_wrapper->has(self::F_SORT) &&
423 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()) != "" &&
424 in_array(
425 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()),
426 [
427 self::S_NAME_ASC,
428 self::S_NAME_DESC,
429 self::S_EXAMINER_ASC,
430 self::S_EXAMINER_DESC,
431 self::S_CHANGETIME_ASC,
432 self::S_CHANGETIME_DESC
433 ]
434 )
435 ) {
436 return $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string());
437 }
438
439 return null;
440 }
441
442 public function handleAccessViolation(): void
443 {
444 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
445 }
446
447 protected function txt(string $code): string
448 {
449 return $this->lng->txt($code);
450 }
451}
Builds data types.
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
Error Handling & global info handling uses PEAR error class.
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadMembers()
Get the members object associated with this.
User class.
static _lookupFullname(int $a_user_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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface RequestWrapper.
This is how the factory for UI elements looks.
Definition: Factory.php:31
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
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
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...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.