ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $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 $this->tpl->setContent($output);
201 }
202
206 public function addUsersFromSearch(array $user_ids): void
207 {
208 if (!empty($user_ids)) {
209 $this->addUsers($user_ids);
210 }
211
212 $this->tpl->setOnScreenMessage("info", $this->txt("search_no_selection"), true);
213 $this->ctrl->redirect($this, 'view');
214 }
215
221 public function addUsers(array $user_ids): void
222 {
223 if (!$this->iass_access->mayEditMembers()) {
224 $this->handleAccessViolation();
225 }
226 $iass = $this->object;
227 $members = $iass->loadMembers();
228 $failure = null;
229 if (count($user_ids) === 0) {
230 $failure = 1;
231 }
232 foreach ($user_ids as $user_id) {
233 $user = new ilObjUser($user_id);
234 if (!$members->userAllreadyMember($user)) {
235 $members = $members->withAdditionalUser($user);
236 } else {
237 $failure = 1;
238 }
239 }
240 $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
242 $this->ctrl->setParameter($this, 'failure', $failure);
243 $this->ctrl->redirect($this, 'addedUsers');
244 }
245
249 protected function removeUserConfirmation(): void
250 {
251 if (!$this->iass_access->mayEditMembers()) {
252 $this->handleAccessViolation();
253 }
254 $usr_id = $this->request_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
255 $message = $this->lng->txt('iass_remove_user_qst');
256
257 $this->ctrl->setParameterByClass(self::class, 'usr_id', $usr_id);
258 $remove = $this->ctrl->getFormAction($this, 'removeUser');
259 $cancel = $this->ctrl->getFormAction($this, 'view');
260 $this->ctrl->clearParameterByClass(self::class, 'usr_id');
261
262 $buttons = [
263 $this->factory->button()->standard($this->lng->txt('remove'), $remove),
264 $this->factory->button()->standard($this->lng->txt('cancel'), $cancel)
265 ];
266 $message_box = $this->factory->messageBox()->confirmation($message)->withButtons($buttons);
267 $this->tpl->setContent($this->renderer->render($message_box));
268 }
269
273 public function removeUser(): void
274 {
275 if (!$this->iass_access->mayEditMembers()) {
276 $this->handleAccessViolation();
277 }
278 $usr_id = $this->request_wrapper->retrieve("usr_id", $this->refinery->kindlyTo()->int());
279 $iass = $this->object;
280 $iass->loadMembers()
281 ->withoutPresentUser(new ilObjUser($usr_id))
282 ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
283 ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
284 $this->tpl->setOnScreenMessage("success", $this->txt("iass_user_removed"), true);
285 $this->ctrl->redirect($this, 'view');
286 }
287
291 protected function getViewControls(): array
292 {
293 $ret = array();
294
295 $vc_factory = $this->factory->viewControl();
296
297 $sort = $this->getSortationControl($vc_factory);
298 $ret[] = $this->getModeControl($vc_factory);
299 $ret[] = $sort;
300
301 return $ret;
302 }
303
304 protected function getModeControl(ViewControl\Factory $vc_factory): ViewControl\Mode
305 {
306 $vc = $vc_factory->mode(
307 $this->getModeOptions(),
308 ""
309 );
310
311 if ($this->request_wrapper->has(self::F_STATUS)) {
312 $vc = $vc->withActive(
313 $this->request_wrapper->retrieve(
314 self::F_STATUS,
315 $this->refinery->kindlyTo()->string()
316 )
317 );
318 }
319
320 return $vc;
321 }
322
323 protected function getSortationControl(ViewControl\Factory $vc_factory): ViewControl\Sortation
324 {
325 $target = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
326 return $vc_factory->sortation(
327 $this->getSortOptions(),
328 $this->getSortValue() ?? self::S_NAME_ASC
329 )
330 ->withTargetURL($target, self::F_SORT);
331 }
332
336 protected function getModeOptions(): array
337 {
338 $ret = [];
339
340 $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
341
342 if ($this->iass_access->mayViewAnyUser()) {
343 $ret[$this->txt("iass_filter_not_started")] =
345 $ret[$this->txt("iass_filter_not_finalized")] =
347 $ret[$this->txt("iass_filter_finalized")] =
349 $ret[$this->txt("iass_filter_failed")] =
351 }
352 return $ret;
353 }
354
358 protected function getActiveLabelForModeByFilter($filter): string
359 {
360 switch ($filter) {
362 return $this->txt("iass_filter_not_started");
364 return $this->txt("iass_filter_not_finalized");
366 return $this->txt("iass_filter_finalized");
368 return $this->txt("iass_filter_failed");
369 default:
370 return $this->txt("iass_filter_all");
371 }
372 }
373
377 protected function getLinkForStatusFilter($value): string
378 {
379 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, $this->getSortValue());
380 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
381 $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
382 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
383
384 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_SORT, null);
385
386 return $link;
387 }
388
389 protected function getFilterValue(): ?string
390 {
391 if (
392 $this->request_wrapper->has(self::F_STATUS) &&
393 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()) != "" &&
394 in_array(
395 $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string()),
396 [
401 ]
402 )
403 ) {
404 return $this->request_wrapper->retrieve(self::F_STATUS, $this->refinery->kindlyTo()->string());
405 }
406
407 return null;
408 }
409
410 protected function getSortOptions(): array
411 {
412 return [
413 self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
414 self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
415 self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
416 self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
417 self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
418 self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
419 ];
420 }
421
422 protected function getSortValue(): ?string
423 {
424 if (
425 $this->request_wrapper->has(self::F_SORT) &&
426 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()) != "" &&
427 in_array(
428 $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string()),
429 [
430 self::S_NAME_ASC,
431 self::S_NAME_DESC,
432 self::S_EXAMINER_ASC,
433 self::S_EXAMINER_DESC,
434 self::S_CHANGETIME_ASC,
435 self::S_CHANGETIME_DESC
436 ]
437 )
438 ) {
439 return $this->request_wrapper->retrieve(self::F_SORT, $this->refinery->kindlyTo()->string());
440 }
441
442 return null;
443 }
444
445 public function handleAccessViolation(): void
446 {
447 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
448 }
449
450 protected function txt(string $code): string
451 {
452 return $this->lng->txt($code);
453 }
454}
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.
$message
Definition: xapiexit.php:31