ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjStudyProgrammeMembersGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
34 {
37 
38  private const DEFAULT_CMD = "view";
39 
40  public const ACTION_MARK_ACCREDITED = "mark_accredited";
41  public const ACTION_UNMARK_ACCREDITED = "unmark_accredited";
42  public const ACTION_SHOW_INDIVIDUAL_PLAN = "show_individual_plan";
43  public const ACTION_REMOVE_USER = "remove_user";
44  public const ACTION_CHANGE_DEADLINE = "change_deadline";
45  public const ACTION_MARK_RELEVANT = "mark_relevant";
46  public const ACTION_UNMARK_RELEVANT = "unmark_relevant";
47  public const ACTION_UPDATE_FROM_CURRENT_PLAN = "update_from_current_plan";
48  public const ACTION_CHANGE_EXPIRE_DATE = "change_expire_date";
49  public const ACTION_UPDATE_CERTIFICATE = "update_certificate";
50  public const ACTION_ACKNOWLEDGE_COURSES = "acknowledge_completed_courses";
51  public const ACTION_REMOVE_CERTIFICATE = "remove_certificate";
52 
53  public const F_COMMAND_OPTION_ALL = 'select_cmd_all';
54  public const F_ALL_PROGRESS_IDS = 'all_progress_ids';
55  public const F_SELECTED_PROGRESS_IDS = 'prgs_ids';
56  public const F_SELECTED_USER_IDS = 'usrids';
57 
61  protected int $ref_id;
62 
63  public function __construct(
64  protected ilGlobalTemplateInterface $tpl,
65  protected ilCtrl $ctrl,
66  protected ilToolbarGUI $toolbar,
67  protected ilLanguage $lng,
68  protected ilObjUser $user,
69  protected ilTabsGUI $tabs,
70  protected ilPRGAssignmentDBRepository $assignment_db,
71  protected ilStudyProgrammeRepositorySearchGUI $repository_search_gui,
72  protected ilObjStudyProgrammeIndividualPlanGUI $individual_plan_gui,
74  protected Factory $data_factory,
75  protected ilConfirmationGUI $confirmation_gui,
76  protected ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper,
77  protected ILIAS\Refinery\Factory $refinery,
78  protected ILIAS\UI\Factory $ui_factory,
79  protected ILIAS\UI\Renderer $ui_renderer,
80  protected GuzzleHttp\Psr7\ServerRequest $request,
81  ) {
82  $this->object = null;
83  $this->permissions = null;
84 
85  $lng->loadLanguageModule("prg");
86  $this->toolbar->setPreventDoubleSubmission(true);
87  }
88 
89  public function setParentGUI(ilObjectGUI $a_parent_gui): void
90  {
91  $this->parent_gui = $a_parent_gui;
92  }
93 
94  public function setRefId(int $ref_id): void
95  {
96  $this->ref_id = $ref_id;
97  $this->object = ilObjStudyProgramme::getInstanceByRefId($ref_id);
98  $this->permissions = ilStudyProgrammeDIC::specificDicFor($this->object)['permissionhelper'];
99  }
100 
101  public function executeCommand(): void
102  {
103  $cmd = $this->ctrl->getCmd();
104  $next_class = $this->ctrl->getNextClass($this);
105 
106  if ($cmd === "" || $cmd === null) {
107  $cmd = $this->getDefaultCommand();
108  }
109 
110  switch ($next_class) {
111  case "ilstudyprogrammerepositorysearchgui":
112  $this->repository_search_gui->setCallback($this, "addUsers");
113  $this->ctrl->setReturn($this, "view");
114  $this->ctrl->forwardCommand($this->repository_search_gui);
115  break;
116  case "ilobjstudyprogrammeindividualplangui":
117  $this->individual_plan_gui->setParentGUI($this);
118  $this->individual_plan_gui->setRefId($this->ref_id);
119  $this->ctrl->forwardCommand($this->individual_plan_gui);
120  break;
121  case "ilstudyprogrammemailmembersearchgui":
122  $this->tabs->clearTargets();
123  $this->tabs->setBackTarget(
124  $this->lng->txt('btn_back'),
125  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
126  );
127  $dic = ilStudyProgrammeDIC::specificDicFor($this->object);
128  $mail_search = $dic['ilStudyProgrammeMailMemberSearchGUI'];
129  $mail_search->setAssignments($this->getAssignmentsById());
130  $mail_search->setBackTarget(
131  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
132  );
133  $this->ctrl->forwardCommand($mail_search);
134  break;
135  case "ilstudyprogrammechangeexpiredategui":
136  $this->tabs->clearTargets();
137  $this->tabs->setBackTarget(
138  $this->lng->txt('btn_back'),
139  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
140  );
142  $gui = $dic['ilStudyProgrammeChangeExpireDateGUI'];
143  $gui->setRefId($this->ref_id);
144  $gui->setProgressIds($this->getGetPrgsIds());
145  $this->ctrl->forwardCommand($gui);
146  break;
147  case "ilstudyprogrammechangedeadlinegui":
148  $this->tabs->clearTargets();
149  $this->tabs->setBackTarget(
150  $this->lng->txt('btn_back'),
151  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
152  );
154  $gui = $dic['ilStudyProgrammeChangeDeadlineGUI'];
155  $gui->setRefId($this->ref_id);
156  $gui->setProgressIds($this->getGetPrgsIds());
157  $this->ctrl->forwardCommand($gui);
158  break;
159  case false:
160  switch ($cmd) {
161  case "view":
162  case "markAccredited":
163  case "markAccreditedMulti":
164  case "unmarkAccredited":
165  case "unmarkAccreditedMulti":
166  case "removeUser":
167  case "removeUserMulti":
168  case "markNotRelevantMulti":
169  case "markRelevant":
170  case "markRelevantMulti":
171  case "updateFromCurrentPlan":
172  case "updateFromCurrentPlanMulti":
173  case "acknowledgeCourses":
174  case "acknowledgeCoursesMulti":
175  case "applyFilter":
176  case "resetFilter":
177  case "changeDeadline":
178  case "changeDeadlineMulti":
179  case "changeExpireDate":
180  case "changeExpireDateMulti":
181  case "updateCertificate":
182  case "updateCertificateMulti":
183  case "removeCertificate":
184  case "removeCertificateMulti":
185  $cont = $this->$cmd();
186  $this->tpl->setContent($cont);
187  break;
188  case "confirmedRemoveUsers":
189  $this->confirmedRemoveUsers();
190  break;
191  case "confirmedUpdateFromCurrentPlan":
193  break;
194  case "confirmedAcknowledgeCourses":
196  break;
197  case "confirmedAcknowledgeAllCourses":
199  break;
200  case "mailUserMulti":
201  $this->mailToSelectedUsers();
202  break;
203  case "markNotRelevant":
204  $this->markNotRelevant();
205  break;
206  case "confirmedUpdateCertificate":
208  break;
209  case "confirmedRemovalOfCertificate":
211  break;
212  case "deliverCertificate":
213  if (!$this->permissions->may(ilOrgUnitOperation::OP_MANAGE_MEMBERS)) {
214  $this->tpl->setOnScreenMessage("failure", $this->lng->txt("permission_denied"), true);
215  $this->ctrl->redirect($this, "view");
216  }
217  $usr_id = $this->http_wrapper->query()->retrieve(
218  'cert_usr_id',
219  $this->refinery->kindlyTo()->int()
220  );
221  $this->deliverCertificate($this->object->getId(), $usr_id);
222  break;
223 
224  default:
225  throw new ilException("ilObjStudyProgrammeMembersGUI: Command not supported: $cmd");
226  }
227  break;
228  default:
229  throw new ilException(
230  "ilObjStudyProgrammeMembersGUI: Can't forward to next class $next_class"
231  );
232  }
233  }
234 
235  protected function getDefaultCommand(): string
236  {
237  return self::DEFAULT_CMD;
238  }
239 
240  protected function getAssignmentsById(): array
241  {
242  return $this->assignment_db->getAllForNodeIsContained($this->object->getId());
243  }
244 
246  {
247  $prg_id = ilObject::_lookupObjId($this->ref_id);
248  $dic = ilStudyProgrammeDIC::specificDicFor($this->object);
249  $table = new ilStudyProgrammeMembersTableGUI(
250  $prg_id,
251  $this->ref_id,
252  $this,
253  $this->permissions,
254  $this->data_factory,
255  $dic['ui.factory'],
256  $dic['ui.renderer'],
257  $dic['ilStudyProgrammeUserTable'],
258  $dic['filter.assignment'],
259  $this->user,
260  "view",
261  ""
262  );
263  return $table;
264  }
265 
269  protected function getPostPrgsIds(): array
270  {
271  if ($this->http_wrapper->post()->has(self::F_COMMAND_OPTION_ALL)) {
272  $pgs_ids = $this->http_wrapper->post()->retrieve(
273  self::F_ALL_PROGRESS_IDS,
274  $this->refinery->custom()->transformation(
275  fn($ids) => explode(',', $ids)
276  )
277  );
278  } else {
279  $pgs_ids = $this->http_wrapper->post()->retrieve(
280  self::F_SELECTED_PROGRESS_IDS,
281  $this->refinery->custom()->transformation(fn($ids) => $ids)
282  );
283  }
284  if ($pgs_ids === null) {
285  $this->showInfoMessage("no_user_selected");
286  $this->ctrl->redirect($this, "view");
287  }
288  if (is_string($pgs_ids)) {
289  $pgs_ids = [$pgs_ids];
290  }
291 
292  $r = [];
293  foreach ($pgs_ids as $pgs_id) {
294  $r[] = PRGProgressId::createFromString($pgs_id);
295  }
296  return $r;
297  }
298 
299  protected function getGetPrgsIds(): array
300  {
301  $prgrs_ids = $_GET['prgrs_ids'];
302  $ids = [];
303  if (!is_null($prgrs_ids)) {
304  foreach (explode(',', $prgrs_ids) as $id) {
305  $ids[] = PRGProgressId::createFromString($id);
306  };
307  }
308  return $ids;
309  }
310 
311  protected function getPrgrsId(): PRGProgressId
312  {
313  if (!$_GET["prgrs_id"]) {
314  throw new ilException("Expected 'prgrs_id'");
315  }
316  return PRGProgressId::createFromString($_GET["prgrs_id"]);
317  }
318 
322  protected function view(): string
323  {
324  if ($this->getStudyProgramme()->isActive() && $this->permissions->may(ilOrgUnitOperation::OP_MANAGE_MEMBERS)) {
325  $this->initSearchGUI();
326  $this->initMailToMemberButton($this->toolbar, true);
327  }
328 
329  if (!$this->getStudyProgramme()->isActive()) {
330  $this->tpl->setOnScreenMessage("info", $this->lng->txt("prg_no_members_not_active"));
331  }
332  $table = $this->getMembersTableGUI();
333  return $table->getHTML();
334  }
335 
336  public function applyFilter(): void
337  {
338  $table = $this->getMembersTableGUI();
339  $table->resetOffset();
340  $table->writeFilterToSession();
341  $this->ctrl->redirect($this, "view");
342  }
343 
344  public function resetFilter(): void
345  {
346  $table = $this->getMembersTableGUI();
347  $table->resetOffset();
348  $table->resetFilter();
349  $this->ctrl->redirect($this, "view");
350  }
351 
357  public function addUsers(array $user_ids)
358  {
359  $user_ids = $this->getAddableUsers($user_ids);
360  $prg = $this->getStudyProgramme();
361  $assignments = [];
362  $with_courses = [];
363 
364  foreach ($user_ids as $user_id) {
365  $ass = $prg->assignUser((int) $user_id);
366  $assignments[] = $ass;
367  if ($prg->getCompletedCourses((int) $user_id)) {
368  $with_courses[] = $ass;
369  }
370  }
371 
372  if (count($assignments) === 1) {
373  $this->tpl->setOnScreenMessage("success", $this->lng->txt("prg_added_member"), true);
374  }
375  if (count($assignments) > 1) {
376  $this->tpl->setOnScreenMessage("success", $this->lng->txt("prg_added_members"), true);
377  }
378 
379  if ($with_courses) {
380  $this->tpl->setContent(
381  $this->ui_renderer->render(
382  $this->viewCompletedCourses($assignments)
383  )
384  );
385  return true;
386 
387  } else {
388  $this->ctrl->redirect($this, "view");
389  }
390  }
391 
395  public function viewCompletedCourses(array $assignments): Form
396  {
397  $prg = $this->getStudyProgramme();
398  $completed_courses = [];
399  $ass_ids = [];
400  foreach ($assignments as $ass) {
401  $ass_ids[] = $ass->getId();
402  $completed_crss = $prg->getCompletedCourses($ass->getUserId());
403 
404  $label = sprintf(
405  "%s (%s)",
406  $ass->getUserInformation()->getFullname(),
407  $ass->getId()
408  );
409  $options = [];
410  foreach ($completed_crss as $opt) {
411  $options[implode(';', [$ass->getId(), $opt['prg_obj_id'],$opt['crs_id']])] = $opt['title'];
412  }
413 
414  $completed_courses[] = $this->ui_factory->input()->field()->multiselect($label, $options);
415  }
416 
417  $form_action = $this->ctrl->getFormAction($this, 'confirmedAcknowledgeCourses')
418  . '&ass_ids=' . implode(',', $ass_ids);
419 
420  $form = $this->ui_factory->input()->container()->form()->standard(
421  $form_action,
422  [
423  $this->ui_factory->input()->field()->section(
424  $completed_courses,
425  $this->lng->txt("prg_acknowledge_completed_courses")
426  )
427  ]
428  )->withAdditionalTransformation(
429  $this->refinery->custom()->transformation(
430  function ($values) {
431  $values = array_merge(...array_filter(array_shift($values)));
432  return array_map(
433  fn($entry) => explode(';', $entry),
434  $values
435  );
436  }
437  )
438  )->withSubmitLabel(
439  $this->lng->txt("btn_next")
440  );
441 
442  $this->toolbar->addComponent(
443  $this->ui_factory->link()->standard(
444  $this->lng->txt('prg_cancel_acknowledge_completed_courses'),
445  $this->ctrl->getLinkTarget($this, self::DEFAULT_CMD)
446  )
447  );
448  $this->toolbar->addComponent(
449  $this->ui_factory->link()->standard(
450  $this->lng->txt('prg_acknowledge_all_completed_courses'),
451  $this->ctrl->getLinkTarget($this, 'confirmedAcknowledgeAllCourses')
452  . '&ass_ids=' . implode(',', $ass_ids)
453  )
454  );
455 
456  return $form;
457  }
458 
462  protected function getAddableUsers(array $users): array
463  {
464  $to_add = $this->permissions->filterUserIds(
465  $users,
467  );
468 
469  $cnt_not_added = count($users) - count($to_add);
470  if ($cnt_not_added > 0) {
471  $this->tpl->setOnScreenMessage(
472  "info",
473  sprintf(
474  $this->lng->txt('could_not_add_users_no_permissons'),
475  $cnt_not_added
476  ),
477  true
478  );
479  }
480  return $to_add;
481  }
482 
483  protected function markAccredited(): void
484  {
485  $prgrs_id = $this->getPrgrsId();
486  $msgs = $this->getMessageCollection('msg_mark_accredited');
487  $this->markAccreditedByProgressId($prgrs_id, $msgs);
488  $this->showMessages($msgs);
489  $this->ctrl->redirect($this, "view");
490  }
491 
492  protected function markAccreditedMulti(): void
493  {
494  $prgrs_ids = $this->getPostPrgsIds();
495  $msgs = $this->getMessageCollection('msg_mark_accredited');
496  foreach ($prgrs_ids as $key => $prgrs_id) {
497  $this->markAccreditedByProgressId($prgrs_id, $msgs);
498  }
499  $this->showMessages($msgs);
500  $this->ctrl->redirect($this, "view");
501  }
502 
503  protected function markAccreditedByProgressId(PRGProgressId $prgrs_id, ilPRGMessageCollection $msgs): void
504  {
505  $usr_id = $prgrs_id->getUsrId();
506  if (!$this->mayCurrentUserEditProgressForUser($usr_id)) {
507  $msgs->add(false, 'No permission to edit progress of user', (string) $prgrs_id);
508  } else {
509  $programme = $this->getStudyProgramme();
510  $programme->markAccredited($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
511  }
512  }
513 
514  protected function unmarkAccredited(): void
515  {
516  $prgrs_id = $this->getPrgrsId();
517  $msgs = $this->getMessageCollection('msg_unmark_accredited');
518  $this->unmarkAccreditedByProgressId($prgrs_id, $msgs);
519  $this->showMessages($msgs);
520  $this->ctrl->redirect($this, "view");
521  }
522 
523  public function unmarkAccreditedMulti(): void
524  {
525  $prgrs_ids = $this->getPostPrgsIds();
526  $msgs = $this->getMessageCollection('msg_unmark_accredited');
527  foreach ($prgrs_ids as $key => $prgrs_id) {
528  $this->unmarkAccreditedByProgressId($prgrs_id, $msgs);
529  }
530  $this->showMessages($msgs);
531  $this->ctrl->redirect($this, "view");
532  }
533 
534  protected function unmarkAccreditedByProgressId(PRGProgressId $prgrs_id, ilPRGMessageCollection $msgs): void
535  {
536  $usr_id = $prgrs_id->getUsrId();
537  if (!$this->mayCurrentUserEditProgressForUser($usr_id)) {
538  $msgs->add(false, 'No permission to edit progress of user', (string) $prgrs_id);
539  } else {
540  $programme = $this->getStudyProgramme();
541  $programme->unmarkAccredited($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
542  }
543  }
544 
545  public function markRelevant(): void
546  {
547  $prgrs_id = $this->getPrgrsId();
548  $msgs = $this->getMessageCollection('msg_mark_relevant');
549  $programme = $this->getStudyProgramme();
550  if (!$this->mayCurrentUserEditProgressForUser($prgrs_id->getUsrId())) {
551  $msgs->add(false, "No permission to edit progress of user", (string) $prgrs_id);
552  } else {
553  $programme->markRelevant($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
554  }
555  $this->showMessages($msgs);
556  $this->ctrl->redirect($this, "view");
557  }
558 
559  public function markRelevantMulti(): void
560  {
561  $prgrs_ids = $this->getPostPrgsIds();
562  $msgs = $this->getMessageCollection('msg_mark_relevant');
563  $programme = $this->getStudyProgramme();
564  foreach ($prgrs_ids as $key => $prgrs_id) {
565  if (!$this->mayCurrentUserEditProgressForUser($prgrs_id->getUsrId())) {
566  $msgs->add(false, 'No permission to edit progress of user', (string) $prgrs_id);
567  } else {
568  $programme->markRelevant($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
569  }
570  }
571  $this->showMessages($msgs);
572  $this->ctrl->redirect($this, "view");
573  }
574 
575  public function markNotRelevant(): void
576  {
577  $prgrs_id = $this->getPrgrsId();
578  $msgs = $this->getMessageCollection('msg_mark_not_relevant');
579  $programme = $this->getStudyProgramme();
580  if (!$this->mayCurrentUserEditProgressForUser($prgrs_id->getUsrId())) {
581  $msgs->add(false, 'No permission to edit progress of user', (string) $prgrs_id);
582  } else {
583  $programme->markNotRelevant($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
584  }
585  $this->showMessages($msgs);
586  $this->ctrl->redirect($this, "view");
587  }
588 
589  public function markNotRelevantMulti(): void
590  {
591  $prgrs_ids = $this->getPostPrgsIds();
592  $msgs = $this->getMessageCollection('msg_mark_not_relevant');
593  $programme = $this->getStudyProgramme();
594  foreach ($prgrs_ids as $key => $prgrs_id) {
595  if (!$this->mayCurrentUserEditProgressForUser($prgrs_id->getUsrId())) {
596  $msgs->add(false, 'No permission to edit progress of user', (string) $prgrs_id);
597  } else {
598  $programme->markNotRelevant($prgrs_id->getAssignmentId(), $this->user->getId(), $msgs);
599  }
600  }
601  $this->showMessages($msgs);
602  $this->ctrl->redirect($this, "view");
603  }
604 
605  public function updateFromCurrentPlan(): string
606  {
607  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateFromCurrentPlan'));
608  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_current_plan'));
609  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateFromCurrentPlan');
610  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
611 
612  $prgs_id = $this->getPrgrsId();
613  $user_name = ilObjUser::_lookupFullname($prgs_id->getUsrId());
614  $this->confirmation_gui->addItem(
615  self::F_SELECTED_PROGRESS_IDS,
616  (string) $prgs_id,
617  $user_name
618  );
619  return $this->confirmation_gui->getHTML();
620  }
621 
622  public function updateFromCurrentPlanMulti(): string
623  {
624  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateFromCurrentPlan'));
625  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_current_plan'));
626  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateFromCurrentPlan');
627  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
628 
629  foreach ($this->getPostPrgsIds() as $progress_id) {
630  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
631  $this->confirmation_gui->addItem(
632  self::F_SELECTED_PROGRESS_IDS . '[]',
633  (string) $progress_id,
634  $user_name
635  );
636  }
637  return $this->confirmation_gui->getHTML();
638  }
639 
641  {
642  $pgs_ids = $this->getPostPrgsIds();
643  $msgs = $this->getMessageCollection('msg_update_from_settings');
644  foreach ($pgs_ids as $idx => $pgs_id) {
645  if (!$this->mayCurrentUserEditProgressForUser($pgs_id->getUsrId())) {
646  $msgs->add(false, 'no_permission_to_update_plan_of_user', (string) $pgs_id);
647  continue;
648  } else {
649  $msgs->add(true, '', (string) $pgs_id);
650  }
651 
652  $this->object->updatePlanFromRepository(
653  $pgs_id->getAssignmentId(),
654  $this->user->getId(),
655  $msgs
656  );
657  }
658  $this->showMessages($msgs);
659  $this->ctrl->redirect($this, "view");
660  }
661 
662  public function acknowledgeCourses(): string
663  {
664  $progress_id = $this->getPrgrsId();
665  $assignments = [
666  $this->assignment_db->get($progress_id->getAssignmentId())
667  ];
668  return $this->ui_renderer->render(
669  $this->viewCompletedCourses($assignments)
670  );
671  }
672 
673  public function acknowledgeCoursesMulti(): string
674  {
675  $assignments = [];
676  foreach ($this->getPostPrgsIds() as $progress_id) {
677  $assignments[] = $this->assignment_db->get($progress_id->getAssignmentId());
678  }
679  return $this->ui_renderer->render(
680  $this->viewCompletedCourses($assignments)
681  );
682  }
683 
687  protected function getAssignmentsFromQuery(): array
688  {
689  $ass_ids = $this->http_wrapper->query()->retrieve(
690  'ass_ids',
691  $this->refinery->custom()->transformation(fn($ids) => explode(',', $ids))
692  );
693  $prg = $this->getStudyProgramme();
694  $assignments = array_map(
695  fn($ass_id) => $this->assignment_db->get((int) $ass_id),
696  $ass_ids
697  );
698 
699  $assignments = array_filter(
700  $assignments,
701  fn($ass) => $ass->getRootId() === $prg->getId()
702  );
703  return $assignments;
704  }
705 
707  {
708  $prg = $this->getStudyProgramme();
709  $assignments = $this->getAssignmentsFromQuery();
710  $msgs = $this->getMessageCollection('msg_acknowledge_courses');
711 
712  foreach ($assignments as $ass) {
713  $ass_ids[] = $ass->getId();
714  $completed_crss = $prg->getCompletedCourses($ass->getUserId());
715  $nodes = [];
716  foreach ($completed_crss as $opt) {
717  $nodes[] = [$opt['prg_obj_id'], $opt['crs_id']];
718  }
719  $prg->acknowledgeCourses(
720  $ass->getId(),
721  $nodes,
722  $msgs
723  );
724  }
725  $this->showMessages($msgs);
726  $this->ctrl->redirect($this, "view");
727  }
728 
729  public function confirmedAcknowledgeCourses()
730  {
731  $assignments = $this->getAssignmentsFromQuery();
732 
733  $form = $this->viewCompletedCourses($assignments)->withRequest($this->request);
734  $data = $form->getData();
735 
736  $msgs = $this->getMessageCollection('msg_acknowledge_courses');
737 
738  if ($data) {
739  $acknowledge = [];
740  foreach ($data as $ack) {
741  [$assignment_id, $node_obj_id, $course_obj_id] = $ack;
742  if (! array_key_exists($assignment_id, $acknowledge)) {
743  $acknowledge[$assignment_id] = [];
744  }
745  $acknowledge[$assignment_id][] = [(int) $node_obj_id, (int) $course_obj_id];
746  }
747  foreach ($acknowledge as $ass_id => $nodes) {
748  $this->object->acknowledgeCourses(
749  (int) $ass_id,
750  $nodes,
751  $msgs
752  );
753  }
754  $this->showMessages($msgs);
755  }
756  $this->ctrl->redirect($this, "view");
757  }
758 
759  public function changeDeadline(): void
760  {
761  $this->ctrl->setParameterByClass(
762  'ilStudyProgrammeChangeDeadlineGUI',
763  'prgrs_ids',
764  $this->getPrgrsId()
765  );
766 
767  $link = $this->ctrl->getLinkTargetByClass(
768  'ilStudyProgrammeChangeDeadlineGUI',
769  'showDeadlineConfig'
770  );
771 
772  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeDeadlineGUI', 'prgrs_ids');
773  $this->ctrl->redirectToURL($link);
774  }
775 
776  public function changeDeadlineMulti(): void
777  {
778  $this->ctrl->setParameterByClass(
779  'ilStudyProgrammeChangeDeadlineGUI',
780  'prgrs_ids',
781  implode(',', $this->getPostPrgsIds())
782  );
783 
784  $link = $this->ctrl->getLinkTargetByClass(
785  'ilStudyProgrammeChangeDeadlineGUI',
786  'showDeadlineConfig'
787  );
788 
789  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeDeadlineGUI', 'prgrs_ids');
790  $this->ctrl->redirectToURL($link);
791  }
792 
793  public function changeExpireDate(): void
794  {
795  $this->ctrl->setParameterByClass(
796  'ilStudyProgrammeChangeExpireDateGUI',
797  'prgrs_ids',
798  $this->getPrgrsId()
799  );
800 
801  $link = $this->ctrl->getLinkTargetByClass(
802  'ilStudyProgrammeChangeExpireDateGUI',
803  'showExpireDateConfig'
804  );
805 
806  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeExpireDateGUI', 'prgrs_ids');
807  $this->ctrl->redirectToURL($link);
808  }
809 
810  public function changeExpireDateMulti(): void
811  {
812  $this->ctrl->setParameterByClass(
813  'ilStudyProgrammeChangeExpireDateGUI',
814  'prgrs_ids',
815  implode(',', $this->getPostPrgsIds())
816  );
817 
818  $link = $this->ctrl->getLinkTargetByClass(
819  'ilStudyProgrammeChangeExpireDateGUI',
820  'showExpireDateConfig'
821  );
822 
823  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeExpireDateGUI', 'prgrs_ids');
824  $this->ctrl->redirectToURL($link);
825  }
826 
827  public function removeUser(): string
828  {
829  $prgrs_id = $this->getPrgrsId();
830  return $this->confirmRemoveUsers([$prgrs_id]);
831  }
832 
833  protected function removeUserMulti(): string
834  {
835  $pgs_ids = $this->getPostPrgsIds();
836  return $this->confirmRemoveUsers($pgs_ids);
837  }
838 
839  protected function confirmRemoveUsers(array $progress_ids): string
840  {
841  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
842  $this->confirmation_gui->setHeaderText($this->lng->txt('confirm_to_remove_selected_assignments'));
843  $this->confirmation_gui->setConfirm($this->lng->txt('prg_remove_user'), 'confirmedRemoveUsers');
844  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
845 
846  foreach ($progress_ids as $progress_id) {
847  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
848  $this->confirmation_gui->addItem(
849  self::F_SELECTED_PROGRESS_IDS . '[]',
850  (string) $progress_id,
851  $user_name
852  );
853  }
854  return $this->confirmation_gui->getHTML();
855  }
856 
857  protected function confirmedRemoveUsers(): void
858  {
859  $pgs_ids = $this->getPostPrgsIds();
860  $not_removed = array();
861  foreach ($pgs_ids as $idx => $pgs_id) {
862  try {
863  $this->removeAssignment($pgs_id);
864  } catch (ilException $e) {
865  $not_removed[] = $pgs_id;
866  }
867  }
868  if (count($not_removed) === count($pgs_ids)) {
869  $this->showInfoMessage("remove_users_not_possible");
870  } elseif (count($not_removed) > 0) {
871  $this->showSuccessMessage("remove_users_partial_success");
872  } else {
873  $this->showSuccessMessage("remove_users_success");
874  }
875  $this->ctrl->redirect($this, "view");
876  }
877 
881  protected function removeAssignment(PRGProgressId $pgs_id): void
882  {
883  if (!in_array(
884  $pgs_id->getUsrId(),
885  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_MANAGE_MEMBERS)
886  )) {
888  'No permission to manage membership of user'
889  );
890  }
891 
892  $ass = $this->assignment_db->get($pgs_id->getAssignmentId());
893  $prg_ref_id = ilObjStudyProgramme::getRefIdFor($ass->getRootId());
894  if ($prg_ref_id !== $this->ref_id) {
895  throw new ilException("Can only remove users from the node they where assigned to.");
896  }
897  $prg = ilObjStudyProgramme::getInstanceByRefId($prg_ref_id);
898  $prg->removeAssignment($ass);
899  }
900 
904  protected function showSuccessMessage(string $lng_var): void
905  {
906  $this->tpl->setOnScreenMessage("success", $this->lng->txt("prg_$lng_var"), true);
907  }
908 
912  protected function showInfoMessage(string $lng_var): void
913  {
914  $this->tpl->setOnScreenMessage("info", $this->lng->txt("prg_$lng_var"), true);
915  }
916 
917  protected function initSearchGUI(): void
918  {
920  $this,
921  $this->toolbar,
922  array(
923  "auto_complete_name" => $this->lng->txt("user"),
924  "submit_name" => $this->lng->txt("add"),
925  "add_search" => true
926  )
927  );
928  }
929 
930  protected function initMailToMemberButton(ilToolbarGUI $toolbar, bool $separator = false): void
931  {
932  if ($separator) {
933  $toolbar->addSeparator();
934  }
935 
936  $toolbar->addComponent(
937  $this->ui_factory->link()->standard(
938  $this->lng->txt('mail_assignments'),
939  $this->ctrl->getLinkTargetByClass(
940  'ilStudyProgrammeMailMemberSearchGUI',
941  'showSelectableUsers'
942  )
943  )
944  );
945  }
946 
951  public function getStudyProgramme(int $ref_id = null): ilObjStudyProgramme
952  {
953  if ($ref_id === null) {
954  $ref_id = $this->ref_id;
955  }
957  }
958 
962  public function getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id): string
963  {
964  switch ($action) {
965  case self::ACTION_MARK_ACCREDITED:
966  $target_name = "markAccredited";
967  break;
968  case self::ACTION_UNMARK_ACCREDITED:
969  $target_name = "unmarkAccredited";
970  break;
971  case self::ACTION_SHOW_INDIVIDUAL_PLAN:
972  return $this->individual_plan_gui->getLinkTargetView($ass_id);
973  case self::ACTION_REMOVE_USER:
974  $target_name = "removeUser";
975  break;
976  case self::ACTION_UNMARK_RELEVANT:
977  $target_name = "markNotRelevant";
978  break;
979  case self::ACTION_MARK_RELEVANT:
980  $target_name = "markRelevant";
981  break;
982  case self::ACTION_UPDATE_FROM_CURRENT_PLAN:
983  $target_name = "updateFromCurrentPlan";
984  break;
985  case self::ACTION_ACKNOWLEDGE_COURSES:
986  $target_name = "acknowledgeCourses";
987  break;
988  case self::ACTION_CHANGE_DEADLINE:
989  $target_name = "changeDeadline";
990  break;
991  case self::ACTION_CHANGE_EXPIRE_DATE:
992  $target_name = "changeExpireDate";
993  break;
994  case self::ACTION_UPDATE_CERTIFICATE:
995  $target_name = "updateCertificate";
996  break;
997  case self::ACTION_REMOVE_CERTIFICATE:
998  $target_name = "removeCertificate";
999  break;
1000  default:
1001  throw new ilException("Unknown action: $action");
1002  }
1003 
1004  $this->ctrl->setParameter($this, "prgrs_id", $prgrs_id);
1005  $link = $this->ctrl->getLinkTarget($this, $target_name);
1006  $this->ctrl->setParameter($this, "prgrs_id", null);
1007  return $link;
1008  }
1009 
1010  protected function mayCurrentUserEditProgressForUser(int $usr_id): bool
1011  {
1012  return in_array(
1013  $usr_id,
1014  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
1015  );
1016  }
1017 
1018  protected function getMessageCollection(string $topic): ilPRGMessageCollection
1019  {
1020  return $this->messages->getMessageCollection($topic);
1021  }
1022 
1023  protected function showMessages(ilPRGMessageCollection $msg): void
1024  {
1025  $this->messages->showMessages($msg);
1026  }
1027 
1028  protected function mailToSelectedUsers(): void
1029  {
1030  $dic = ilStudyProgrammeDIC::specificDicFor($this->object);
1031  $gui = $dic['ilStudyProgrammeMailMemberSearchGUI'];
1032  $selected = $this->getPostPrgsIds();
1033  $selected_ids = array_map(
1034  fn($id) => $id->getAssignmentId(),
1035  $selected
1036  );
1037 
1038  $assignments = array_filter(
1039  $this->getAssignmentsById(),
1040  fn($ass) => in_array($ass->getId(), $selected_ids)
1041  );
1042  $gui->setAssignments($assignments);
1043  $this->tabs->clearTargets();
1044  $this->tabs->setBackTarget(
1045  $this->lng->txt('btn_back'),
1046  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
1047  );
1048  $this->ctrl->forwardCommand($gui);
1049  }
1050 
1051  public function updateCertificate(): string
1052  {
1053  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateCertificate'));
1054  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_certificate'));
1055  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateCertificate');
1056  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1057 
1058  $prgs_id = $this->getPrgrsId();
1059  $user_name = ilObjUser::_lookupFullname($prgs_id->getUsrId());
1060  $this->confirmation_gui->addItem(
1061  self::F_SELECTED_PROGRESS_IDS,
1062  (string) $prgs_id,
1063  $user_name
1064  );
1065  return $this->confirmation_gui->getHTML();
1066  }
1067 
1068  public function updateCertificateMulti(): string
1069  {
1070  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateCertificate'));
1071  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_certificate'));
1072  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateCertificate');
1073  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1074 
1075  foreach ($this->getPostPrgsIds() as $progress_id) {
1076  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
1077  $this->confirmation_gui->addItem(
1078  self::F_SELECTED_PROGRESS_IDS . '[]',
1079  (string) $progress_id,
1080  $user_name
1081  );
1082  }
1083  return $this->confirmation_gui->getHTML();
1084  }
1085 
1086  public function confirmedUpdateCertificate(): void
1087  {
1088  $msgs = $this->getMessageCollection('msg_update_certificate');
1089  foreach ($this->getPostPrgsIds() as $idx => $prgs_id) {
1090  if (!$this->mayCurrentUserEditProgressForUser($prgs_id->getUsrId())) {
1091  $this->showInfoMessage("no_permission_to_update_certificate");
1092  } else {
1093 
1094  $assignment = $this->assignment_db->get($prgs_id->getAssignmentId());
1095  $progress = $assignment->getProgressForNode($prgs_id->getNodeId());
1096  if (!$progress->isSuccessful()) {
1097  $msgs->add(false, 'will_not_update_cert_for_unsuccessful_progress', (string) $prgs_id);
1098  continue;
1099  }
1100 
1101  if ($this->updateCertificateForPrg(
1102  $prgs_id->getNodeId(),
1103  $prgs_id->getUsrId()
1104  )) {
1105  $msgs->add(true, '', (string) $prgs_id);
1106  } else {
1107  $msgs->add(false, 'error_updating_certificate', (string) $prgs_id);
1108  }
1109  }
1110  }
1111  $this->showMessages($msgs);
1112  $this->ctrl->redirect($this, "view");
1113  }
1114 
1115  public function removeCertificate(): string
1116  {
1117  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmRemovalOfCertificate'));
1118  $this->confirmation_gui->setHeaderText($this->lng->txt('header_remove_certificate'));
1119  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedRemovalOfCertificate');
1120  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1121 
1122  $prgs_id = $this->getPrgrsId();
1123  $user_name = ilObjUser::_lookupFullname($prgs_id->getUsrId());
1124  $this->confirmation_gui->addItem(
1125  self::F_SELECTED_PROGRESS_IDS,
1126  (string) $prgs_id,
1127  $user_name
1128  );
1129  return $this->confirmation_gui->getHTML();
1130  }
1131 
1132  public function removeCertificateMulti(): string
1133  {
1134  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmRemovalOfCertificate'));
1135  $this->confirmation_gui->setHeaderText($this->lng->txt('header_remove_certificate'));
1136  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedRemovalOfCertificate');
1137  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1138 
1139  foreach ($this->getPostPrgsIds() as $progress_id) {
1140  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
1141  $this->confirmation_gui->addItem(
1142  self::F_SELECTED_PROGRESS_IDS . '[]',
1143  (string) $progress_id,
1144  $user_name
1145  );
1146  }
1147 
1148  return $this->confirmation_gui->getHTML();
1149  }
1150 
1151  public function confirmedRemovalOfCertificate(): void
1152  {
1153  $msgs = $this->getMessageCollection('msg_remove_certificate');
1154  $pgs_ids = $this->getPostPrgsIds();
1155  foreach ($pgs_ids as $idx => $prgs_id) {
1156  if (!$this->mayCurrentUserEditProgressForUser($prgs_id->getUsrId())) {
1157  $this->showInfoMessage("no_permission_to_remove_certificate");
1158  } else {
1159  $this->removeCertificateForUser(
1160  $prgs_id->getNodeId(),
1161  $prgs_id->getUsrId(),
1162  );
1163  }
1164  }
1165  $this->showSuccessMessage("successfully_removed_certificate");
1166  $this->ctrl->redirect($this, "view");
1167  }
1168 
1169  protected function deliverCertificate(int $obj_id, int $usr_id): void
1170  {
1171  $repository = new ilUserCertificateRepository();
1172  $pdf_action = new ilCertificatePdfAction(
1173  new ilPdfGenerator($repository),
1175  $this->lng->txt('error_creating_certificate_pdf')
1176  );
1177  $pdf_action->downloadPdf($usr_id, $obj_id);
1178  }
1179 }
getStudyProgramme(int $ref_id=null)
Get studyprogramm object for ref_id Use this ref_id if argument is null.
$_GET["client_id"]
Definition: webdav.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
removeAssignment(PRGProgressId $pgs_id)
Remove user.
removeCertificateForUser(int $node_id, int $usr_id,)
markAccreditedByProgressId(PRGProgressId $prgrs_id, ilPRGMessageCollection $msgs)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupFullname(int $a_user_id)
Class ChatMainBarProvider .
addComponent(\ILIAS\UI\Component\Component $a_comp)
__construct(protected ilGlobalTemplateInterface $tpl, protected ilCtrl $ctrl, protected ilToolbarGUI $toolbar, protected ilLanguage $lng, protected ilObjUser $user, protected ilTabsGUI $tabs, protected ilPRGAssignmentDBRepository $assignment_db, protected ilStudyProgrammeRepositorySearchGUI $repository_search_gui, protected ilObjStudyProgrammeIndividualPlanGUI $individual_plan_gui, protected ilPRGMessagePrinter $messages, protected Factory $data_factory, protected ilConfirmationGUI $confirmation_gui, protected ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper, protected ILIAS\Refinery\Factory $refinery, protected ILIAS\UI\Factory $ui_factory, protected ILIAS\UI\Renderer $ui_renderer, protected GuzzleHttp\Psr7\ServerRequest $request,)
updateCertificateForPrg(int $obj_id, int $usr_id)
loadLanguageModule(string $a_module)
Load language module.
static fillAutoCompleteToolbar( $parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
This is just the same as in the parent class, except for the hardcoded class name.
add(bool $success, string $message, string $record_identitifer)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
initMailToMemberButton(ilToolbarGUI $toolbar, bool $separator=false)
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22
getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id)
Get the link target for an action on user progress.
$lng
static createFromString(string $id)
showInfoMessage(string $lng_var)
Shows ilUtil failed message.
Class ilObjectGUI Basic methods of all Output classes.
trait ilPRGCertificateHelper
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
view()
Shows table with all members of the SP.
static specificDicFor(ilObjStudyProgramme $prg)
ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI ilObjStudyProgrammeMembersGUI: il...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Just a wrapper class to create Unit Test for other classes.
Custom repository search gui class for study programme to make it possible to get a handle on users s...
Assignments are relations of users to a PRG; They hold progress-information for (sub-)nodes of the PR...
showSuccessMessage(string $lng_var)
Shows ilUtil success message.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$dic
Definition: result.php:32
static getRefIdFor(int $obj_id)
addUsers(array $user_ids)
Assigns a users to SP.
unmarkAccreditedByProgressId(PRGProgressId $prgrs_id, ilPRGMessageCollection $msgs)
viewCompletedCourses(array $assignments)
Shows list of completed courses for each assignment.
Holds information about multi-actions, mainly in context of member-assignemnts and status changes...
$r
downloadPdf(int $userId, int $objectId)
Refinery Factory $refinery