ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilIndividualAssessmentMembersGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Denis Klöpfer <denis.kloepfer@concepts-and-training.de> Extended GPL, see ./LICENSE */
3/* Copyright (c) 2018 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see ./LICENSE */
4
5declare(strict_types=1);
6
7require_once 'Modules/IndividualAssessment/classes/class.ilIndividualAssessmentMembersTableGUI.php';
8require_once 'Modules/IndividualAssessment/classes/LearningProgress/class.ilIndividualAssessmentLPInterface.php';
9
10use \ILIAS\UI;
11use \ILIAS\UI\Component\ViewControl;
12
22{
26 protected $ctrl;
27
31 protected $object;
32
36 protected $ref_id;
37
41 protected $tpl;
42
46 protected $lng;
47
51 protected $toolbar;
52
56 protected $user;
57
61 protected $tabs;
62
66 protected $iass_access;
67
71 protected $factory;
72
76 protected $renderer;
77
81 protected $error_object;
82
86 protected $member_gui;
87
88 const F_STATUS = "status";
89 const F_SORT = "sortation";
90
91 const S_NAME_ASC = "user_lastname:asc";
92 const S_NAME_DESC = "user_lastname:desc";
93 const S_EXAMINER_ASC = "examiner_login:asc";
94 const S_EXAMINER_DESC = "examiner_login:desc";
95 const S_CHANGETIME_ASC = "change_time:asc";
96 const S_CHANGETIME_DESC = "change_time:desc";
97
98 public function __construct(
111 ) {
112 $this->object = $object;
113 $this->ctrl = $ctrl;
114 $this->tpl = $tpl;
115 $this->lng = $lng;
116 $this->toolbar = $toolbar;
117 $this->user = $user;
118 $this->tabs = $tabs;
119 $this->iass_access = $iass_access;
120 $this->factory = $factory;
121 $this->renderer = $renderer;
122 $this->error_object = $error_object;
123 $this->member_gui = $member_gui;
124
125 $this->ref_id = (int) $object->getRefId();
126 }
127
128 public function executeCommand()
129 {
130 if (!$this->iass_access->mayEditMembers()
131 && !$this->iass_access->mayGradeUser()
132 && !$this->iass_access->mayViewUser()
133 && !$this->iass_access->mayAmendGradeUser()
134 ) {
135 $this->handleAccessViolation();
136 }
137 $cmd = $this->ctrl->getCmd();
138 $next_class = $this->ctrl->getNextClass();
139 $this->ctrl->saveParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS);
140 switch ($next_class) {
141 case "ilrepositorysearchgui":
142 require_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
143 $rep_search = new ilRepositorySearchGUI();
144 $rep_search->setCallback($this, "addUsersFromSearch");
145 $rep_search->addUserAccessFilterCallable(
146 function ($a_user_ids) {
147 return $a_user_ids;
148 }
149 );
150 $this->ctrl->forwardCommand($rep_search);
151 break;
152 case "ilindividualassessmentmembergui":
153 $this->tabs->clearTargets();
154 $this->tabs->setBackTarget(
155 $this->lng->txt('back'),
156 $this->ctrl->getLinkTargetByClass(self::class, 'view')
157 );
158 $this->ctrl->forwardCommand($this->member_gui);
159 break;
160 default:
161 if (!$cmd) {
162 $cmd = 'view';
163 }
164 $this->$cmd();
165 break;
166 }
167 }
168
169 protected function addedUsers()
170 {
171 if (!$_GET['failure']) {
172 ilUtil::sendSuccess($this->txt('iass_add_user_success'));
173 } else {
174 ilUtil::sendFailure($this->txt('iass_add_user_failure'));
175 }
176 $this->view();
177 }
178
179 protected function view()
180 {
181 if ($this->iass_access->mayEditMembers()) {
182 require_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
183
184 $search_params = ['crs', 'grp'];
185 $container_id = $this->object->getParentContainerIdByType($this->ref_id, $search_params);
186 if ($container_id !== 0) {
188 $this,
189 $this->toolbar,
190 array(
191 'auto_complete_name' => $this->txt('user'),
192 'submit_name' => $this->txt('add'),
193 'add_search' => true,
194 'add_from_container' => $container_id
195 )
196 );
197 } else {
199 $this,
200 $this->toolbar,
201 array(
202 'auto_complete_name' => $this->txt('user'),
203 'submit_name' => $this->txt('add'),
204 'add_search' => true
205 )
206 );
207 }
208 }
210 $this,
211 $this->lng,
212 $this->ctrl,
213 $this->iass_access,
214 $this->factory,
215 $this->renderer,
216 (int) $this->user->getId()
217 );
218
219 $get = $_GET;
220
221 $filter = $this->getFilterValue($get);
222 $sort = $this->getSortValue($get);
223
224 $entries = $this->object->loadMembersAsSingleObjects($filter, $sort);
225 $table->setData($entries);
226 $view_constrols = $this->getViewControls($get);
227
228 $output = $table->render($view_constrols);
229
230 if (count($entries) == 0) {
231 $output .= $this->txt("iass_no_entries");
232 }
233 $this->tpl->setContent($output);
234 }
235
239 public function addUsersFromSearch(array $user_ids)
240 {
241 if ($user_ids && is_array($user_ids) && !empty($user_ids)) {
242 $this->addUsers($user_ids);
243 }
244
245 ilUtil::sendInfo($this->txt("search_no_selection"), true);
246 $this->ctrl->redirect($this, 'view');
247 }
248
254 public function addUsers(array $user_ids)
255 {
256 if (!$this->iass_access->mayEditMembers()) {
257 $this->handleAccessViolation();
258 }
259 $iass = $this->object;
260 $members = $iass->loadMembers();
261 $failure = null;
262 if (count($user_ids) === 0) {
263 $failure = 1;
264 }
265 foreach ($user_ids as $user_id) {
266 $user = new ilObjUser($user_id);
267 if (!$members->userAllreadyMember($user)) {
268 $members = $members->withAdditionalUser($user);
269 } else {
270 $failure = 1;
271 }
272 }
273 $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
275 $this->ctrl->setParameter($this, 'failure', $failure);
276 $this->ctrl->redirect($this, 'addedUsers');
277 }
278
282 protected function removeUserConfirmation()
283 {
284 if (!$this->iass_access->mayEditMembers()) {
285 $this->handleAccessViolation();
286 }
287 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
288 $confirm = new ilConfirmationGUI();
289 $confirm->addItem('usr_id', $_GET['usr_id'], ilObjUser::_lookupFullname($_GET['usr_id']));
290 $confirm->setHeaderText($this->txt('iass_remove_user_qst'));
291 $confirm->setFormAction($this->ctrl->getFormAction($this));
292 $confirm->setConfirm($this->txt('remove'), 'removeUser');
293 $confirm->setCancel($this->txt('cancel'), 'view');
294 $this->tpl->setContent($confirm->getHTML());
295 }
296
300 public function removeUser()
301 {
302 if (!$this->iass_access->mayEditMembers()) {
303 $this->handleAccessViolation();
304 }
305 $usr_id = $_POST['usr_id'];
306 $iass = $this->object;
307 $iass->loadMembers()
308 ->withoutPresentUser(new ilObjUser($usr_id))
309 ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
310 ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
311 ilUtil::sendSuccess($this->txt("iass_user_removed"), true);
312 $this->ctrl->redirect($this, 'view');
313 }
314
318 protected function getViewControls(array $get) : array
319 {
320 $ret = array();
321
322 $vc_factory = $this->factory->viewControl();
323
324 $sort = $this->getSortationControl($vc_factory);
325 $ret[] = $this->getModeControl($get, $vc_factory);
326 $ret[] = $sort;
327
328 return $ret;
329 }
330
334 protected function getModeControl(array $get, ViewControl\Factory $vc_factory) : ViewControl\Mode
335 {
336 $active = $this->getActiveLabelForModeByFilter($get[self::F_STATUS]);
337
338 return $vc_factory->mode(
339 $this->getModeOptions(),
340 ""
341 )
342 ->withActive($active);
343 }
344
345 protected function getSortationControl(ViewControl\Factory $vc_factory) : ViewControl\Sortation
346 {
347 $target = $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
348 return $vc_factory->sortation(
349 $this->getSortOptions()
350 )
351 ->withTargetURL($target, self::F_SORT)
352 ->withLabel($this->txt("iass_sort"));
353 }
354
358 protected function getModeOptions() : array
359 {
360 $ret = [];
361
362 $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
363
364 if ($this->maybeViewLearningProgress()) {
366 $ret[$this->txt("iass_filter_not_finalized")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_IN_PROGRESS);
367 $ret[$this->txt("iass_filter_finalized")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_COMPLETED);
368 $ret[$this->txt("iass_filter_failed")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_FAILED);
369 }
370 return $ret;
371 }
372
376 protected function getActiveLabelForModeByFilter($filter) : string
377 {
378 switch ($filter) {
380 return $this->txt("iass_filter_not_started");
381 break;
383 return $this->txt("iass_filter_not_finalized");
384 break;
386 return $this->txt("iass_filter_finalized");
387 break;
389 return $this->txt("iass_filter_failed");
390 break;
391 default:
392 return $this->txt("iass_filter_all");
393 }
394 }
395
399 protected function getLinkForStatusFilter($value) : string
400 {
401 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
402 $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
403 $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
404
405 return $link;
406 }
407
412 protected function getFilterValue(array $get)
413 {
414 if (isset($get[self::F_STATUS])
415 && $get[self::F_STATUS] != ""
416 && in_array(
417 $get[self::F_STATUS],
418 [
423 ]
424 )
425 ) {
426 return $get[self::F_STATUS];
427 }
428
429 return null;
430 }
431
432 protected function getSortOptions() : array
433 {
434 return array(
435 self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
436 self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
437 self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
438 self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
439 self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
440 self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
441 );
442 }
443
448 protected function getSortValue(array $get)
449 {
450 if (isset($get[self::F_SORT])
451 && $get[self::F_SORT] != ""
452 && in_array(
453 $get[self::F_SORT],
454 [
455 self::S_NAME_ASC,
456 self::S_NAME_DESC,
457 self::S_EXAMINER_ASC,
458 self::S_EXAMINER_DESC,
459 self::S_CHANGETIME_ASC,
460 self::S_CHANGETIME_DESC
461 ]
462 )
463 ) {
464 return $get[self::F_SORT];
465 }
466
467 return null;
468 }
469
470 public function handleAccessViolation()
471 {
472 $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
473 }
474
475 protected function maybeViewLearningProgress()
476 {
477 return $this->iass_access->mayViewUser();
478 }
479
480 protected function txt(string $code) : string
481 {
482 return $this->lng->txt($code);
483 }
484}
user()
Definition: user.php:4
$failure
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
This class provides processing control methods.
Class ilGlobalPageTemplate.
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)
removeUser()
Remove users from corresponding iass-object.
getModeControl(array $get, ViewControl\Factory $vc_factory)
addUsers(array $user_ids)
Add users to corresponding iass-object.
removeUserConfirmation()
Display confirmation form for user might be removed.
language handling
For the purpose of streamlining the grading and learning-process status definition outside of tests,...
static _lookupFullname($a_user_id)
Lookup Full Name.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
Tabs GUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This is how the factory for UI elements looks.
Definition: Factory.php:14
This describes a Mode Control.
Definition: Mode.php:13
This describes a Sortation Control.
Definition: Sortation.php:13
withTargetURL($url, $paramter_name)
Get a Sortation with this target-url.
An entity that renders components to a string output.
Definition: Renderer.php:15
Mechanic regarding the access controll and roles of an objcet goes here.
Class Factory.
$ret
Definition: parser.php:6