ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 declare(strict_types=1);
6 
7 require_once 'Modules/IndividualAssessment/classes/class.ilIndividualAssessmentMembersTableGUI.php';
8 require_once 'Modules/IndividualAssessment/classes/LearningProgress/class.ilIndividualAssessmentLPInterface.php';
9 
10 use \ILIAS\UI;
11 use \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(
100  ilCtrl $ctrl,
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  $this->tpl->setPermanentLink("iass", $this->ref_id);
141 
142  switch ($next_class) {
143  case "ilrepositorysearchgui":
144  require_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
145  $rep_search = new ilRepositorySearchGUI();
146  $rep_search->setCallback($this, "addUsersFromSearch");
147  $rep_search->addUserAccessFilterCallable(
148  function ($a_user_ids) {
149  return $a_user_ids;
150  }
151  );
152  $this->ctrl->forwardCommand($rep_search);
153  break;
154  case "ilindividualassessmentmembergui":
155  $this->tabs->clearTargets();
156  $this->tabs->setBackTarget(
157  $this->lng->txt('back'),
158  $this->ctrl->getLinkTargetByClass(self::class, 'view')
159  );
160  $this->ctrl->forwardCommand($this->member_gui);
161  break;
162  default:
163  if (!$cmd) {
164  $cmd = 'view';
165  }
166  $this->$cmd();
167  break;
168  }
169  }
170 
171  protected function addedUsers()
172  {
173  if (!$_GET['failure']) {
174  ilUtil::sendSuccess($this->txt('iass_add_user_success'));
175  } else {
176  ilUtil::sendFailure($this->txt('iass_add_user_failure'));
177  }
178  $this->view();
179  }
180 
181  protected function view()
182  {
183  if ($this->iass_access->mayEditMembers()) {
184  require_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
185 
186  $search_params = ['crs', 'grp'];
187  $container_id = $this->object->getParentContainerIdByType($this->ref_id, $search_params);
188  if ($container_id !== 0) {
190  $this,
191  $this->toolbar,
192  array(
193  'auto_complete_name' => $this->txt('user'),
194  'submit_name' => $this->txt('add'),
195  'add_search' => true,
196  'add_from_container' => $container_id
197  )
198  );
199  } else {
201  $this,
202  $this->toolbar,
203  array(
204  'auto_complete_name' => $this->txt('user'),
205  'submit_name' => $this->txt('add'),
206  'add_search' => true
207  )
208  );
209  }
210  }
212  $this,
213  $this->lng,
214  $this->ctrl,
215  $this->iass_access,
216  $this->factory,
217  $this->renderer,
218  (int) $this->user->getId()
219  );
220 
221  $get = $_GET;
222 
223  $filter = $this->getFilterValue($get);
224  $sort = $this->getSortValue($get);
225 
226  $entries = $this->object->loadMembersAsSingleObjects($filter, $sort);
227  $table->setData($entries);
228  $view_constrols = $this->getViewControls($get);
229 
230  $output = $table->render($view_constrols);
231 
232  if (count($entries) == 0) {
233  $output .= $this->txt("iass_no_entries");
234  }
235  $this->tpl->setContent($output);
236  }
237 
241  public function addUsersFromSearch(array $user_ids)
242  {
243  if ($user_ids && is_array($user_ids) && !empty($user_ids)) {
244  $this->addUsers($user_ids);
245  }
246 
247  ilUtil::sendInfo($this->txt("search_no_selection"), true);
248  $this->ctrl->redirect($this, 'view');
249  }
250 
256  public function addUsers(array $user_ids)
257  {
258  if (!$this->iass_access->mayEditMembers()) {
259  $this->handleAccessViolation();
260  }
261  $iass = $this->object;
262  $members = $iass->loadMembers();
263  $failure = null;
264  if (count($user_ids) === 0) {
265  $failure = 1;
266  }
267  foreach ($user_ids as $user_id) {
268  $user = new ilObjUser($user_id);
269  if (!$members->userAllreadyMember($user)) {
270  $members = $members->withAdditionalUser($user);
271  } else {
272  $failure = 1;
273  }
274  }
275  $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
277  $this->ctrl->setParameter($this, 'failure', $failure);
278  $this->ctrl->redirect($this, 'addedUsers');
279  }
280 
284  protected function removeUserConfirmation()
285  {
286  if (!$this->iass_access->mayEditMembers()) {
287  $this->handleAccessViolation();
288  }
289  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
290  $confirm = new ilConfirmationGUI();
291  $confirm->addItem('usr_id', $_GET['usr_id'], ilObjUser::_lookupFullname($_GET['usr_id']));
292  $confirm->setHeaderText($this->txt('iass_remove_user_qst'));
293  $confirm->setFormAction($this->ctrl->getFormAction($this));
294  $confirm->setConfirm($this->txt('remove'), 'removeUser');
295  $confirm->setCancel($this->txt('cancel'), 'view');
296  $this->tpl->setContent($confirm->getHTML());
297  }
298 
302  public function removeUser()
303  {
304  if (!$this->iass_access->mayEditMembers()) {
305  $this->handleAccessViolation();
306  }
307  $usr_id = $_POST['usr_id'];
308  $iass = $this->object;
309  $iass->loadMembers()
310  ->withoutPresentUser(new ilObjUser($usr_id))
311  ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
312  ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
313  ilUtil::sendSuccess($this->txt("iass_user_removed"), true);
314  $this->ctrl->redirect($this, 'view');
315  }
316 
320  protected function getViewControls(array $get) : array
321  {
322  $ret = array();
323 
324  $vc_factory = $this->factory->viewControl();
325 
326  $sort = $this->getSortationControl($vc_factory);
327  $ret[] = $this->getModeControl($get, $vc_factory);
328  $ret[] = $sort;
329 
330  return $ret;
331  }
332 
336  protected function getModeControl(array $get, ViewControl\Factory $vc_factory) : ViewControl\Mode
337  {
338  $active = $this->getActiveLabelForModeByFilter($get[self::F_STATUS]);
339 
340  return $vc_factory->mode(
341  $this->getModeOptions(),
342  ""
343  )
344  ->withActive($active);
345  }
346 
347  protected function getSortationControl(ViewControl\Factory $vc_factory) : ViewControl\Sortation
348  {
349  $target = $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
350  return $vc_factory->sortation(
351  $this->getSortOptions()
352  )
353  ->withTargetURL($target, self::F_SORT)
354  ->withLabel($this->txt("iass_sort"));
355  }
356 
360  protected function getModeOptions() : array
361  {
362  $ret = [];
363 
364  $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
365 
366  if ($this->maybeViewLearningProgress()) {
368  $ret[$this->txt("iass_filter_not_finalized")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_IN_PROGRESS);
369  $ret[$this->txt("iass_filter_finalized")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_COMPLETED);
370  $ret[$this->txt("iass_filter_failed")] = $this->getLinkForStatusFilter(ilIndividualAssessmentMembers::LP_FAILED);
371  }
372  return $ret;
373  }
374 
378  protected function getActiveLabelForModeByFilter($filter) : string
379  {
380  switch ($filter) {
382  return $this->txt("iass_filter_not_started");
383  break;
385  return $this->txt("iass_filter_not_finalized");
386  break;
388  return $this->txt("iass_filter_finalized");
389  break;
391  return $this->txt("iass_filter_failed");
392  break;
393  default:
394  return $this->txt("iass_filter_all");
395  }
396  }
397 
401  protected function getLinkForStatusFilter($value) : string
402  {
403  $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
404  $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
405  $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
406 
407  return $link;
408  }
409 
414  protected function getFilterValue(array $get)
415  {
416  if (isset($get[self::F_STATUS])
417  && $get[self::F_STATUS] != ""
418  && in_array(
419  $get[self::F_STATUS],
420  [
425  ]
426  )
427  ) {
428  return $get[self::F_STATUS];
429  }
430 
431  return null;
432  }
433 
434  protected function getSortOptions() : array
435  {
436  return array(
437  self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
438  self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
439  self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
440  self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
441  self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
442  self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
443  );
444  }
445 
450  protected function getSortValue(array $get)
451  {
452  if (isset($get[self::F_SORT])
453  && $get[self::F_SORT] != ""
454  && in_array(
455  $get[self::F_SORT],
456  [
457  self::S_NAME_ASC,
458  self::S_NAME_DESC,
459  self::S_EXAMINER_ASC,
460  self::S_EXAMINER_DESC,
461  self::S_CHANGETIME_ASC,
462  self::S_CHANGETIME_DESC
463  ]
464  )
465  ) {
466  return $get[self::F_SORT];
467  }
468 
469  return null;
470  }
471 
472  public function handleAccessViolation()
473  {
474  $this->error_object->raiseError($this->txt("msg_no_perm_read"), $this->error_object->WARNING);
475  }
476 
477  protected function maybeViewLearningProgress()
478  {
479  return $this->iass_access->mayViewUser();
480  }
481 
482  protected function txt(string $code) : string
483  {
484  return $this->lng->txt($code);
485  }
486 }
An entity that renders components to a string output.
Definition: Renderer.php:14
$failure
This class provides processing control methods.
addUsers(array $user_ids)
Add users to corresponding iass-object.
Class Factory.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
Tabs GUI.
$_GET["client_id"]
static _lookupFullname($a_user_id)
Lookup Full Name.
withTargetURL($url, $paramter_name)
Get a Sortation with this target-url.
removeUser()
Remove users from corresponding iass-object.
user()
Definition: user.php:4
Mechanic regarding the access controll and roles of an objcet goes here.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilGlobalPageTemplate.
getModeControl(array $get, ViewControl\Factory $vc_factory)
This is how the factory for UI elements looks.
Definition: Factory.php:13
__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)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This describes a Sortation Control.
Definition: Sortation.php:12
This describes a Mode Control.
Definition: Mode.php:12
$ret
Definition: parser.php:6
getRefId()
get reference id public
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
removeUserConfirmation()
Display confirmation form for user might be removed.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
$_POST["username"]
Confirmation screen class.