ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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\Component\ViewControl;
11 
21 {
22  protected $ctrl;
23  protected $parent_gui;
24  protected $ref_id;
25  protected $tpl;
26  protected $lng;
27 
28  const F_STATUS = "status";
29  const F_SORT = "sortation";
30 
31  const S_NAME_ASC = "user_lastname:asc";
32  const S_NAME_DESC = "user_lastname:desc";
33  const S_EXAMINER_ASC = "examiner_login:asc";
34  const S_EXAMINER_DESC = "examiner_login:desc";
35  const S_CHANGETIME_ASC = "change_time:asc";
36  const S_CHANGETIME_DESC = "change_time:desc";
37 
41  protected $object;
42 
46  protected $iass_access;
47 
48  public function __construct(
49  ilObjIndividualAssessmentGUI $a_parent_gui,
50  int $a_ref_id
51  ) {
52  global $DIC;
53  $this->ctrl = $DIC['ilCtrl'];
54  $this->parent_gui = $a_parent_gui;
55  $this->object = $a_parent_gui->object;
56  $this->ref_id = $a_ref_id;
57  $this->tpl = $DIC['tpl'];
58  $this->lng = $DIC['lng'];
59  $this->toolbar = $DIC['ilToolbar'];
60  $this->user = $DIC["ilUser"];
61  $this->iass_access = $this->object->accessHandler();
62  $this->factory = $DIC->ui()->factory();
63  $this->renderer = $DIC->ui()->renderer();
64  }
65 
66  public function executeCommand()
67  {
68  if (
69  !$this->iass_access->mayEditMembers()
70  && !$this->iass_access->mayGradeUser()
71  && !$this->iass_access->mayViewUser()
72  && !$this->iass_access->mayAmendGradeUser()
73  ) {
74  $this->parent_gui->handleAccessViolation();
75  }
76 
77  $cmd = $this->ctrl->getCmd();
78  $next_class = $this->ctrl->getNextClass();
79  $this->ctrl->saveParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS);
80  switch ($next_class) {
81  case "ilrepositorysearchgui":
82  require_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
83  $rep_search = new ilRepositorySearchGUI();
84  $rep_search->setCallback($this, "addUsersFromSearch");
85  $rep_search->addUserAccessFilterCallable(
86  function ($a_user_ids) {
87  return $a_user_ids;
88  }
89  );
90  $this->ctrl->forwardCommand($rep_search);
91  break;
92  case "ilindividualassessmentmembergui":
93  require_once 'Modules/IndividualAssessment/classes/class.ilIndividualAssessmentMemberGUI.php';
94  $member = new ilIndividualAssessmentMemberGUI($this, $this->parent_gui, $this->ref_id);
95  $this->ctrl->forwardCommand($member);
96  break;
97  default:
98  if (!$cmd) {
99  $cmd = 'view';
100  }
101  $this->$cmd();
102  break;
103  }
104  }
105 
106  protected function addedUsers()
107  {
108  if (!$_GET['failure']) {
109  ilUtil::sendSuccess($this->txt('iass_add_user_success'));
110  } else {
111  ilUtil::sendFailure($this->txt('iass_add_user_failure'));
112  }
113  $this->view();
114  }
115 
116  protected function view()
117  {
118  if ($this->iass_access->mayEditMembers()) {
119  require_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
120 
121  $search_params = ['crs', 'grp'];
122  $container_id = $this->object->getParentContainerIdByType($this->ref_id, $search_params);
123  if ($container_id !== 0) {
125  $this,
126  $this->toolbar,
127  array(
128  'auto_complete_name' => $this->txt('user'),
129  'submit_name' => $this->txt('add'),
130  'add_search' => true,
131  'add_from_container' => $container_id
132  )
133  );
134  } else {
136  $this,
137  $this->toolbar,
138  array(
139  'auto_complete_name' => $this->txt('user'),
140  'submit_name' => $this->txt('add'),
141  'add_search' => true
142  )
143  );
144  }
145  }
146 
148  $this,
149  $this->lng,
150  $this->ctrl,
151  $this->object->accessHandler(),
153  $this->renderer,
154  (int) $this->user->getId()
155  );
156 
157  $get = $_GET;
158 
159  $filter = $this->getFilterValue($get);
160  $sort = $this->getSortValue($get);
161  $entries = $this->filterViewableOrGradeableEntries(
162  $this->object->loadMembersAsSingleObjects($filter, $sort)
163  );
164 
165  $table->setData($entries);
166  $view_constrols = $this->getViewControls($get);
167 
168  $output = $table->render($view_constrols);
169 
170  if (count($entries) == 0) {
171  $output .= $this->txt("iass_no_entries");
172  }
173  $this->tpl->setContent($output);
174  }
175 
176  protected function filterViewableOrGradeableEntries(array $entries) : array
177  {
178  $user_ids = array_map(function ($e) {
179  return $e->id();
180  }, $entries);
181  $viewable_or_gradeable_entries = $this->iass_access->filterViewableOrGradeableUsers($user_ids);
182 
183  return array_filter($entries, function ($e) use ($viewable_or_gradeable_entries) {
184  return in_array($e->id(), $viewable_or_gradeable_entries);
185  });
186  }
187 
191  public function addUsersFromSearch(array $user_ids)
192  {
193  if ($user_ids && is_array($user_ids) && !empty($user_ids)) {
194  $this->addUsers($user_ids);
195  }
196 
197  ilUtil::sendInfo($this->txt("search_no_selection"), true);
198  $this->ctrl->redirectByClass(array(get_class($this->parent_gui),get_class($this)), 'view');
199  }
200 
206  public function addUsers(array $user_ids)
207  {
208  if (!$this->iass_access->mayEditMembers()) {
209  $this->parent_gui->handleAccessViolation();
210  }
211  $iass = $this->object;
212  $members = $iass->loadMembers();
213  $failure = null;
214  if (count($user_ids) === 0) {
215  $failure = 1;
216  }
217  foreach ($user_ids as $user_id) {
218  $user = new ilObjUser($user_id);
219  if (!$members->userAllreadyMember($user)) {
220  $members = $members->withAdditionalUser($user);
221  } else {
222  $failure = 1;
223  }
224  }
225  $members->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
227  $this->ctrl->setParameter($this, 'failure', $failure);
228  $this->ctrl->redirectByClass(array(get_class($this->parent_gui),get_class($this)), 'addedUsers');
229  }
230 
234  protected function removeUserConfirmation()
235  {
236  if (!$this->iass_access->mayEditMembers()) {
237  $this->parent_gui->handleAccessViolation();
238  }
239  include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
240  $confirm = new ilConfirmationGUI();
241  $confirm->addItem('usr_id', $_GET['usr_id'], ilObjUser::_lookupFullname($_GET['usr_id']));
242  $confirm->setHeaderText($this->txt('iass_remove_user_qst'));
243  $confirm->setFormAction($this->ctrl->getFormAction($this));
244  $confirm->setConfirm($this->txt('remove'), 'removeUser');
245  $confirm->setCancel($this->txt('cancel'), 'view');
246  $this->tpl->setContent($confirm->getHTML());
247  }
248 
252  public function removeUser()
253  {
254  if (!$this->iass_access->mayEditMembers()) {
255  $this->parent_gui->handleAccessViolation();
256  }
257  $usr_id = $_POST['usr_id'];
258  $iass = $this->object;
259  $iass->loadMembers()
260  ->withoutPresentUser(new ilObjUser($usr_id))
261  ->updateStorageAndRBAC($iass->membersStorage(), $iass->accessHandler());
262  ilIndividualAssessmentLPInterface::updateLPStatusByIds($iass->getId(), array($usr_id));
263  ilUtil::sendSuccess($this->txt("iass_user_removed"), true);
264  $this->ctrl->redirectByClass(array(get_class($this->parent_gui),get_class($this)), 'view');
265  }
266 
270  protected function getViewControls(array $get) : array
271  {
272  $ret = array();
273 
274  $vc_factory = $this->factory->viewControl();
275 
276  $sort = $this->getSortationControl($vc_factory);
277  $ret[] = $this->getModeControl($get, $vc_factory);
278  $ret[] = $sort;
279 
280  return $ret;
281  }
282 
286  protected function getModeControl(array $get, ViewControl\Factory $vc_factory) : ViewControl\Mode
287  {
288  $active = $this->getActiveLabelForModeByFilter($get[self::F_STATUS]);
289 
290  return $vc_factory->mode(
291  $this->getModeOptions(),
292  ""
293  )
294  ->withActive($active);
295  }
296 
297  protected function getSortationControl(ViewControl\Factory $vc_factory) : ViewControl\Sortation
298  {
299  $target = $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
300  return $vc_factory->sortation(
301  $this->getSortOptions()
302  )
303  ->withTargetURL($target, self::F_SORT)
304  ->withLabel($this->txt("iass_sort"));
305  }
306 
310  protected function getModeOptions() : array
311  {
312  $ret = [];
313 
314  $ret[$this->txt("iass_filter_all")] = $this->getLinkForStatusFilter(null);
315  $ret[$this->txt("iass_filter_not_started")] = $this->getLinkForStatusFilter(
317  );
318  $ret[$this->txt("iass_filter_not_finalized")] = $this->getLinkForStatusFilter(
320  );
321  $ret[$this->txt("iass_filter_finalized")] = $this->getLinkForStatusFilter(
323  );
324  $ret[$this->txt("iass_filter_failed")] = $this->getLinkForStatusFilter(
326  );
327 
328  return $ret;
329  }
330 
334  protected function getActiveLabelForModeByFilter($filter) : string
335  {
336  switch ($filter) {
338  return $this->txt("iass_filter_not_started");
339  break;
341  return $this->txt("iass_filter_not_finalized");
342  break;
344  return $this->txt("iass_filter_finalized");
345  break;
347  return $this->txt("iass_filter_failed");
348  break;
349  default:
350  return $this->txt("iass_filter_all");
351  }
352  }
353 
357  protected function getLinkForStatusFilter($value) : string
358  {
359  $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, $value);
360  $link = $this->ctrl->getLinkTargetByClass("ilIndividualAssessmentMembersGUI", "view");
361  $this->ctrl->setParameterByClass("ilIndividualAssessmentMembersGUI", self::F_STATUS, null);
362 
363  return $link;
364  }
365 
370  protected function getFilterValue(array $get)
371  {
372  if (isset($get[self::F_STATUS])
373  && $get[self::F_STATUS] != ""
374  && in_array(
375  $get[self::F_STATUS],
376  [
381  ]
382  )
383  ) {
384  return $get[self::F_STATUS];
385  }
386 
387  return null;
388  }
389 
390  protected function getSortOptions() : array
391  {
392  return array(
393  self::S_NAME_ASC => $this->txt("iass_sort_name_asc"),
394  self::S_NAME_DESC => $this->txt("iass_sort_name_desc"),
395  self::S_EXAMINER_ASC => $this->txt("iass_sort_examiner_login_asc"),
396  self::S_EXAMINER_DESC => $this->txt("iass_sort_examiner_login_desc"),
397  self::S_CHANGETIME_ASC => $this->txt("iass_sort_changetime_asc"),
398  self::S_CHANGETIME_DESC => $this->txt("iass_sort_changetime_desc")
399  );
400  }
401 
406  protected function getSortValue(array $get)
407  {
408  if (isset($get[self::F_SORT])
409  && $get[self::F_SORT] != ""
410  && in_array(
411  $get[self::F_SORT],
412  [
413  self::S_NAME_ASC,
414  self::S_NAME_DESC,
415  self::S_EXAMINER_ASC,
416  self::S_EXAMINER_DESC,
417  self::S_CHANGETIME_ASC,
418  self::S_CHANGETIME_DESC
419  ]
420  )
421  ) {
422  return $get[self::F_SORT];
423  }
424 
425  return null;
426  }
427 
428  protected function txt(string $code) : string
429  {
430  return $this->lng->txt($code);
431  }
432 }
$failure
addUsers(array $user_ids)
Add users to corresponding iass-object.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static _lookupFullname($a_user_id)
Lookup Full Name.
__construct(ilObjIndividualAssessmentGUI $a_parent_gui, int $a_ref_id)
$code
Definition: example_050.php:99
$factory
Definition: metadata.php:43
For the purpose of streamlining the grading and learning-process status definition outside of tests...
removeUser()
Remove users from corresponding iass-object.
user()
Definition: user.php:4
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getModeControl(array $get, ViewControl\Factory $vc_factory)
This is how the factory for UI elements looks.
Definition: Factory.php:13
For the purpose of streamlining the grading and learning-process status definition outside of tests...
$user
Definition: migrateto20.php:57
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
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
if(empty($password)) $table
Definition: pwgen.php:24
removeUserConfirmation()
Display confirmation form for user might be removed.
For the purpose of streamlining the grading and learning-process status definition outside of tests...
$target
Definition: test.php:19
$_POST["username"]
Confirmation screen class.