ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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($ass)) {
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);
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  return $assignments;
699  }
700 
702  {
703  $prg = $this->getStudyProgramme();
704  $assignments = $this->getAssignmentsFromQuery();
705  $msgs = $this->getMessageCollection('msg_acknowledge_courses');
706 
707  foreach ($assignments as $ass) {
708  $ass_ids[] = $ass->getId();
709  $completed_crss = $prg->getCompletedCourses($ass);
710  $nodes = [];
711  foreach ($completed_crss as $opt) {
712  $nodes[] = [$opt['prg_obj_id'], $opt['crs_id']];
713  }
714  $prg->acknowledgeCourses(
715  $ass->getId(),
716  $nodes,
717  $msgs
718  );
719  }
720  $this->showMessages($msgs);
721  $this->ctrl->redirect($this, "view");
722  }
723 
724  public function confirmedAcknowledgeCourses()
725  {
726  $assignments = $this->getAssignmentsFromQuery();
727 
728  $form = $this->viewCompletedCourses($assignments)->withRequest($this->request);
729  $data = $form->getData();
730 
731  $msgs = $this->getMessageCollection('msg_acknowledge_courses');
732 
733  if ($data) {
734  $acknowledge = [];
735  foreach ($data as $ack) {
736  [$assignment_id, $node_obj_id, $course_obj_id] = $ack;
737  if (! array_key_exists($assignment_id, $acknowledge)) {
738  $acknowledge[$assignment_id] = [];
739  }
740  $acknowledge[$assignment_id][] = [(int) $node_obj_id, (int) $course_obj_id];
741  }
742  foreach ($acknowledge as $ass_id => $nodes) {
743  $this->object->acknowledgeCourses(
744  (int) $ass_id,
745  $nodes,
746  $msgs
747  );
748  }
749  $this->showMessages($msgs);
750  }
751  $this->ctrl->redirect($this, "view");
752  }
753 
754  public function changeDeadline(): void
755  {
756  $this->ctrl->setParameterByClass(
757  'ilStudyProgrammeChangeDeadlineGUI',
758  'prgrs_ids',
759  $this->getPrgrsId()
760  );
761 
762  $link = $this->ctrl->getLinkTargetByClass(
763  'ilStudyProgrammeChangeDeadlineGUI',
764  'showDeadlineConfig'
765  );
766 
767  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeDeadlineGUI', 'prgrs_ids');
768  $this->ctrl->redirectToURL($link);
769  }
770 
771  public function changeDeadlineMulti(): void
772  {
773  $this->ctrl->setParameterByClass(
774  'ilStudyProgrammeChangeDeadlineGUI',
775  'prgrs_ids',
776  implode(',', $this->getPostPrgsIds())
777  );
778 
779  $link = $this->ctrl->getLinkTargetByClass(
780  'ilStudyProgrammeChangeDeadlineGUI',
781  'showDeadlineConfig'
782  );
783 
784  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeDeadlineGUI', 'prgrs_ids');
785  $this->ctrl->redirectToURL($link);
786  }
787 
788  public function changeExpireDate(): void
789  {
790  $this->ctrl->setParameterByClass(
791  'ilStudyProgrammeChangeExpireDateGUI',
792  'prgrs_ids',
793  $this->getPrgrsId()
794  );
795 
796  $link = $this->ctrl->getLinkTargetByClass(
797  'ilStudyProgrammeChangeExpireDateGUI',
798  'showExpireDateConfig'
799  );
800 
801  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeExpireDateGUI', 'prgrs_ids');
802  $this->ctrl->redirectToURL($link);
803  }
804 
805  public function changeExpireDateMulti(): void
806  {
807  $this->ctrl->setParameterByClass(
808  'ilStudyProgrammeChangeExpireDateGUI',
809  'prgrs_ids',
810  implode(',', $this->getPostPrgsIds())
811  );
812 
813  $link = $this->ctrl->getLinkTargetByClass(
814  'ilStudyProgrammeChangeExpireDateGUI',
815  'showExpireDateConfig'
816  );
817 
818  $this->ctrl->clearParameterByClass('ilStudyProgrammeChangeExpireDateGUI', 'prgrs_ids');
819  $this->ctrl->redirectToURL($link);
820  }
821 
822  public function removeUser(): string
823  {
824  $prgrs_id = $this->getPrgrsId();
825  return $this->confirmRemoveUsers([$prgrs_id]);
826  }
827 
828  protected function removeUserMulti(): string
829  {
830  $pgs_ids = $this->getPostPrgsIds();
831  return $this->confirmRemoveUsers($pgs_ids);
832  }
833 
834  protected function confirmRemoveUsers(array $progress_ids): string
835  {
836  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this));
837  $this->confirmation_gui->setHeaderText($this->lng->txt('confirm_to_remove_selected_assignments'));
838  $this->confirmation_gui->setConfirm($this->lng->txt('prg_remove_user'), 'confirmedRemoveUsers');
839  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
840 
841  foreach ($progress_ids as $progress_id) {
842  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
843  $this->confirmation_gui->addItem(
844  self::F_SELECTED_PROGRESS_IDS . '[]',
845  (string) $progress_id,
846  $user_name
847  );
848  }
849  return $this->confirmation_gui->getHTML();
850  }
851 
852  protected function confirmedRemoveUsers(): void
853  {
854  $pgs_ids = $this->getPostPrgsIds();
855  $not_removed = array();
856  foreach ($pgs_ids as $idx => $pgs_id) {
857  try {
858  $this->removeAssignment($pgs_id);
859  } catch (ilException $e) {
860  $not_removed[] = $pgs_id;
861  }
862  }
863  if (count($not_removed) === count($pgs_ids)) {
864  $this->showInfoMessage("remove_users_not_possible");
865  } elseif (count($not_removed) > 0) {
866  $this->showSuccessMessage("remove_users_partial_success");
867  } else {
868  $this->showSuccessMessage("remove_users_success");
869  }
870  $this->ctrl->redirect($this, "view");
871  }
872 
876  protected function removeAssignment(PRGProgressId $pgs_id): void
877  {
878  if (!in_array(
879  $pgs_id->getUsrId(),
880  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_MANAGE_MEMBERS)
881  )) {
883  'No permission to manage membership of user'
884  );
885  }
886 
887  $ass = $this->assignment_db->get($pgs_id->getAssignmentId());
888  $prg_ref_id = ilObjStudyProgramme::getRefIdFor($ass->getRootId());
889  if ($prg_ref_id !== $this->ref_id) {
890  throw new ilException("Can only remove users from the node they where assigned to.");
891  }
892  $prg = ilObjStudyProgramme::getInstanceByRefId($prg_ref_id);
893  $prg->removeAssignment($ass);
894  }
895 
899  protected function showSuccessMessage(string $lng_var): void
900  {
901  $this->tpl->setOnScreenMessage("success", $this->lng->txt("prg_$lng_var"), true);
902  }
903 
907  protected function showInfoMessage(string $lng_var): void
908  {
909  $this->tpl->setOnScreenMessage("info", $this->lng->txt("prg_$lng_var"), true);
910  }
911 
912  protected function initSearchGUI(): void
913  {
915  $this,
916  $this->toolbar,
917  array(
918  "auto_complete_name" => $this->lng->txt("user"),
919  "submit_name" => $this->lng->txt("add"),
920  "add_search" => true
921  )
922  );
923  }
924 
925  protected function initMailToMemberButton(ilToolbarGUI $toolbar, bool $separator = false): void
926  {
927  if ($separator) {
928  $toolbar->addSeparator();
929  }
930 
931  $toolbar->addComponent(
932  $this->ui_factory->link()->standard(
933  $this->lng->txt('mail_assignments'),
934  $this->ctrl->getLinkTargetByClass(
935  'ilStudyProgrammeMailMemberSearchGUI',
936  'showSelectableUsers'
937  )
938  )
939  );
940  }
941 
946  public function getStudyProgramme(?int $ref_id = null): ilObjStudyProgramme
947  {
948  if ($ref_id === null) {
949  $ref_id = $this->ref_id;
950  }
952  }
953 
957  public function getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id): string
958  {
959  switch ($action) {
960  case self::ACTION_MARK_ACCREDITED:
961  $target_name = "markAccredited";
962  break;
963  case self::ACTION_UNMARK_ACCREDITED:
964  $target_name = "unmarkAccredited";
965  break;
966  case self::ACTION_SHOW_INDIVIDUAL_PLAN:
967  return $this->individual_plan_gui->getLinkTargetView($ass_id);
968  case self::ACTION_REMOVE_USER:
969  $target_name = "removeUser";
970  break;
971  case self::ACTION_UNMARK_RELEVANT:
972  $target_name = "markNotRelevant";
973  break;
974  case self::ACTION_MARK_RELEVANT:
975  $target_name = "markRelevant";
976  break;
977  case self::ACTION_UPDATE_FROM_CURRENT_PLAN:
978  $target_name = "updateFromCurrentPlan";
979  break;
980  case self::ACTION_ACKNOWLEDGE_COURSES:
981  $target_name = "acknowledgeCourses";
982  break;
983  case self::ACTION_CHANGE_DEADLINE:
984  $target_name = "changeDeadline";
985  break;
986  case self::ACTION_CHANGE_EXPIRE_DATE:
987  $target_name = "changeExpireDate";
988  break;
989  case self::ACTION_UPDATE_CERTIFICATE:
990  $target_name = "updateCertificate";
991  break;
992  case self::ACTION_REMOVE_CERTIFICATE:
993  $target_name = "removeCertificate";
994  break;
995  default:
996  throw new ilException("Unknown action: $action");
997  }
998 
999  $this->ctrl->setParameter($this, "prgrs_id", $prgrs_id);
1000  $link = $this->ctrl->getLinkTarget($this, $target_name);
1001  $this->ctrl->setParameter($this, "prgrs_id", null);
1002  return $link;
1003  }
1004 
1005  protected function mayCurrentUserEditProgressForUser(int $usr_id): bool
1006  {
1007  return in_array(
1008  $usr_id,
1009  $this->permissions->getUserIdsSusceptibleTo(ilOrgUnitOperation::OP_EDIT_INDIVIDUAL_PLAN)
1010  );
1011  }
1012 
1013  protected function getMessageCollection(string $topic): ilPRGMessageCollection
1014  {
1015  return $this->messages->getMessageCollection($topic);
1016  }
1017 
1018  protected function showMessages(ilPRGMessageCollection $msg): void
1019  {
1020  $this->messages->showMessages($msg);
1021  }
1022 
1023  protected function mailToSelectedUsers(): void
1024  {
1025  $dic = ilStudyProgrammeDIC::specificDicFor($this->object);
1026  $gui = $dic['ilStudyProgrammeMailMemberSearchGUI'];
1027  $selected = $this->getPostPrgsIds();
1028  $selected_ids = array_map(
1029  fn($id) => $id->getAssignmentId(),
1030  $selected
1031  );
1032 
1033  $assignments = array_filter(
1034  $this->getAssignmentsById(),
1035  fn($ass) => in_array($ass->getId(), $selected_ids)
1036  );
1037  $gui->setAssignments($assignments);
1038  $this->tabs->clearTargets();
1039  $this->tabs->setBackTarget(
1040  $this->lng->txt('btn_back'),
1041  $this->ctrl->getLinkTarget($this, $this->getDefaultCommand())
1042  );
1043  $this->ctrl->forwardCommand($gui);
1044  }
1045 
1046  public function updateCertificate(): string
1047  {
1048  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateCertificate'));
1049  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_certificate'));
1050  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateCertificate');
1051  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1052 
1053  $prgs_id = $this->getPrgrsId();
1054  $user_name = ilObjUser::_lookupFullname($prgs_id->getUsrId());
1055  $this->confirmation_gui->addItem(
1056  self::F_SELECTED_PROGRESS_IDS,
1057  (string) $prgs_id,
1058  $user_name
1059  );
1060  return $this->confirmation_gui->getHTML();
1061  }
1062 
1063  public function updateCertificateMulti(): string
1064  {
1065  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmUpdateCertificate'));
1066  $this->confirmation_gui->setHeaderText($this->lng->txt('header_update_certificate'));
1067  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedUpdateCertificate');
1068  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1069 
1070  foreach ($this->getPostPrgsIds() as $progress_id) {
1071  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
1072  $this->confirmation_gui->addItem(
1073  self::F_SELECTED_PROGRESS_IDS . '[]',
1074  (string) $progress_id,
1075  $user_name
1076  );
1077  }
1078  return $this->confirmation_gui->getHTML();
1079  }
1080 
1081  public function confirmedUpdateCertificate(): void
1082  {
1083  $msgs = $this->getMessageCollection('msg_update_certificate');
1084  foreach ($this->getPostPrgsIds() as $idx => $prgs_id) {
1085  if (!$this->mayCurrentUserEditProgressForUser($prgs_id->getUsrId())) {
1086  $this->showInfoMessage("no_permission_to_update_certificate");
1087  } else {
1088 
1089  $assignment = $this->assignment_db->get($prgs_id->getAssignmentId());
1090  $progress = $assignment->getProgressForNode($prgs_id->getNodeId());
1091  if (!$progress->isSuccessful()) {
1092  $msgs->add(false, 'will_not_update_cert_for_unsuccessful_progress', (string) $prgs_id);
1093  continue;
1094  }
1095 
1096  if ($this->updateCertificateForPrg(
1097  $prgs_id->getNodeId(),
1098  $prgs_id->getUsrId()
1099  )) {
1100  $msgs->add(true, '', (string) $prgs_id);
1101  } else {
1102  $msgs->add(false, 'error_updating_certificate', (string) $prgs_id);
1103  }
1104  }
1105  }
1106  $this->showMessages($msgs);
1107  $this->ctrl->redirect($this, "view");
1108  }
1109 
1110  public function removeCertificate(): string
1111  {
1112  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmRemovalOfCertificate'));
1113  $this->confirmation_gui->setHeaderText($this->lng->txt('header_remove_certificate'));
1114  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedRemovalOfCertificate');
1115  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1116 
1117  $prgs_id = $this->getPrgrsId();
1118  $user_name = ilObjUser::_lookupFullname($prgs_id->getUsrId());
1119  $this->confirmation_gui->addItem(
1120  self::F_SELECTED_PROGRESS_IDS,
1121  (string) $prgs_id,
1122  $user_name
1123  );
1124  return $this->confirmation_gui->getHTML();
1125  }
1126 
1127  public function removeCertificateMulti(): string
1128  {
1129  $this->confirmation_gui->setFormAction($this->ctrl->getFormAction($this, 'confirmRemovalOfCertificate'));
1130  $this->confirmation_gui->setHeaderText($this->lng->txt('header_remove_certificate'));
1131  $this->confirmation_gui->setConfirm($this->lng->txt('confirm'), 'confirmedRemovalOfCertificate');
1132  $this->confirmation_gui->setCancel($this->lng->txt('cancel'), 'view');
1133 
1134  foreach ($this->getPostPrgsIds() as $progress_id) {
1135  $user_name = ilObjUser::_lookupFullname($progress_id->getUsrId());
1136  $this->confirmation_gui->addItem(
1137  self::F_SELECTED_PROGRESS_IDS . '[]',
1138  (string) $progress_id,
1139  $user_name
1140  );
1141  }
1142 
1143  return $this->confirmation_gui->getHTML();
1144  }
1145 
1146  public function confirmedRemovalOfCertificate(): void
1147  {
1148  $msgs = $this->getMessageCollection('msg_remove_certificate');
1149  $pgs_ids = $this->getPostPrgsIds();
1150  foreach ($pgs_ids as $idx => $prgs_id) {
1151  if (!$this->mayCurrentUserEditProgressForUser($prgs_id->getUsrId())) {
1152  $this->showInfoMessage("no_permission_to_remove_certificate");
1153  } else {
1154  $this->removeCertificateForUser(
1155  $prgs_id->getNodeId(),
1156  $prgs_id->getUsrId(),
1157  );
1158  }
1159  }
1160  $this->showSuccessMessage("successfully_removed_certificate");
1161  $this->ctrl->redirect($this, "view");
1162  }
1163 
1164  protected function deliverCertificate(int $obj_id, int $usr_id): void
1165  {
1166  $repository = new ilUserCertificateRepository();
1167  $pdf_action = new ilCertificatePdfAction(
1168  new ilPdfGenerator($repository),
1170  $this->lng->txt('error_creating_certificate_pdf')
1171  );
1172  $pdf_action->downloadPdf($usr_id, $obj_id);
1173  }
1174 }
$_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)
Util around ilPRGMessageCollection factors and output collections.
static _lookupFullname(int $a_user_id)
Interface Observer Contains several chained tasks and infos about them.
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.
add(bool $success, string $message, string $record_identitifer)
static _lookupObjId(int $ref_id)
initMailToMemberButton(ilToolbarGUI $toolbar, bool $separator=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$messages
Definition: xapiexit.php:21
getLinkTargetForAction(string $action, string $prgrs_id, int $ass_id)
Get the link target for an action on user progress.
static createFromString(string $id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showInfoMessage(string $lng_var)
Shows ilUtil failed message.
Class ilObjectGUI Basic methods of all Output classes.
trait ilPRGCertificateHelper
view()
Shows table with all members of the SP.
static specificDicFor(ilObjStudyProgramme $prg)
ilObjStudyProgrammeMembersGUI: ilStudyProgrammeRepositorySearchGUI ilObjStudyProgrammeMembersGUI: il...
Builds data types.
Definition: Factory.php:35
getStudyProgramme(?int $ref_id=null)
Get studyprogramm object for ref_id Use this ref_id if argument is null.
Both role and OrgU-based permissions are relevant in many places of the PRG.
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
global $lng
Definition: privfeed.php:31
$dic
Definition: result.php:31
static getRefIdFor(int $obj_id)
addUsers(array $user_ids)
Assigns a users to SP.
unmarkAccreditedByProgressId(PRGProgressId $prgrs_id, ilPRGMessageCollection $msgs)
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.
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)