ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSkillProfileGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 use ILIAS\UI;
34 
42 {
43  protected ilCtrl $ctrl;
44  protected ilLanguage $lng;
45  protected ilTabsGUI $tabs;
47  protected ilHelpGUI $help;
49  protected UI\Factory $ui_fac;
50  protected UI\Renderer $ui_ren;
51  protected \ILIAS\Data\Factory $df;
52  protected ServerRequestInterface $request;
54  protected int $id = 0;
55  protected ?Profile\SkillProfile $profile = null;
58  protected int $skill_tree_id = 0;
60  protected int $requested_ref_id = 0;
61  protected int $requested_sprof_id = 0;
63  protected Profile\SkillProfileManager $profile_manager;
64  protected Profile\SkillProfileCompletionManager $profile_completion_manager;
65  protected Table\TableManager $table_manager;
66  protected Usage\SkillUsageManager $usage_manager;
67 
71  protected array $requested_profile_ids = [];
72  protected bool $requested_local_context = false;
73  protected string $requested_cskill_id = "";
74 
78  protected array $requested_level_ass_ids = [];
79 
83  protected array $requested_level_order = [];
84  protected string $requested_user_login = "";
85 
89  protected array $requested_users = [];
90 
94  protected array $requested_user_ids = [];
95  protected string $requested_table_profile_action = "";
96 
100  protected array $requested_table_profile_ids = [];
101  protected int $requested_level_id = 0;
102  protected bool $local_context = false;
103 
104  public function __construct(SkillTreeAccess $skill_tree_access_manager, int $skill_tree_id = 0)
105  {
106  global $DIC;
107 
108  $this->ctrl = $DIC->ctrl();
109  $this->lng = $DIC->language();
110  $this->tabs = $DIC->tabs();
111  $this->tpl = $DIC["tpl"];
112  $this->help = $DIC["ilHelp"];
113  $this->toolbar = $DIC->toolbar();
114  $this->ui_fac = $DIC->ui()->factory();
115  $this->ui_ren = $DIC->ui()->renderer();
116  $this->df = new \ILIAS\Data\Factory();
117  $this->request = $DIC->http()->request();
118  $this->query = $DIC->http()->wrapper()->query();
119  $this->tree_service = $DIC->skills()->tree();
120  $this->skill_tree_access_manager = $skill_tree_access_manager;
121  $this->skill_tree_id = $skill_tree_id;
122  $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
123  $this->skill_factory = $DIC->skills()->internal()->factory();
124  $this->profile_manager = $DIC->skills()->internal()->manager()->getProfileManager();
125  $this->profile_completion_manager = $DIC->skills()->internal()->manager()->getProfileCompletionManager();
126  $this->table_manager = $DIC->skills()->internal()->manager()->getTableManager();
127  $this->usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
128 
129  $this->ctrl->saveParameter($this, ["sprof_id", "local_context"]);
130 
131  $this->requested_ref_id = $this->admin_gui_request->getRefId();
132  $this->requested_sprof_id = $this->admin_gui_request->getSkillProfileId();
133  $this->requested_profile_ids = $this->admin_gui_request->getProfileIds();
134  $this->requested_local_context = $this->admin_gui_request->getLocalContext();
135  $this->requested_cskill_id = $this->admin_gui_request->getCombinedSkillId();
136  $this->requested_level_ass_ids = $this->admin_gui_request->getAssignedLevelIds();
137  $this->requested_level_order = $this->admin_gui_request->getOrder();
138  $this->requested_user_login = $this->admin_gui_request->getUserLogin();
139  $this->requested_users = $this->admin_gui_request->getUsers();
140  $this->requested_user_ids = $this->admin_gui_request->getUserIds();
141  $this->requested_table_profile_action = $this->admin_gui_request->getTableProfileAction();
142  $this->requested_table_profile_ids = $this->admin_gui_request->getTableProfileIds();
143  $this->requested_level_id = $this->admin_gui_request->getLevelId();
144 
145  if ($this->requested_sprof_id > 0) {
146  $this->id = $this->requested_sprof_id;
147  }
148 
149  if ($this->id > 0) {
150  $this->profile = $this->profile_manager->getProfile($this->id);
151  if ($this->skill_tree_id == 0) {
152  $this->skill_tree_id = $this->profile->getSkillTreeId();
153  }
154  if ($this->profile->getRefId() > 0 && $this->requested_local_context) {
155  $this->local_context = true;
156  }
157  }
158  }
159 
160  public function executeCommand(): void
161  {
162  $ilCtrl = $this->ctrl;
163  $lng = $this->lng;
164 
165  $cmd = $ilCtrl->getCmd("listProfiles");
166  $next_class = $ilCtrl->getNextClass();
167  switch ($next_class) {
168  case 'ilrepositorysearchgui':
169  $user_search = new ilRepositorySearchGUI();
170  $user_search->setTitle($lng->txt('skmg_add_user_to_profile'));
171  $user_search->setCallback($this, 'assignUser');
172  $user_search->setRoleCallback($this, 'assignRole');
173 
174  // Set tabs
175  //$this->tabs_gui->setTabActive('user_assignment');
176  $ilCtrl->setReturn($this, 'showUsers');
177  $ret = $ilCtrl->forwardCommand($user_search);
178  break;
179 
180  default:
181  if (in_array($cmd, array("listProfiles", "create", "edit", "save", "update",
182  "deleteProfiles", "showLevels", "assignLevel",
183  "assignLevelSelectSkill", "updateLevelOfSelectedSkill",
184  "assignLevelToProfile", "updateLevelOfProfile",
185  "confirmLevelAssignmentRemoval", "removeLevelAssignments",
186  "showUsers", "assignUser", "assignRole",
187  "confirmUserRemoval", "removeUsers", "exportProfiles", "showImportForm",
188  "importProfiles", "saveLevelOrder", "createLocal", "saveLocal",
189  "listLocalProfiles", "showLevelsWithLocalContext", "showObjects",
190  "showLevelsWithTableContext"))) {
191  $this->$cmd();
192  }
193  break;
194  }
195  }
196 
197  public function setTabs(string $a_active): void
198  {
199  $ilTabs = $this->tabs;
200  $lng = $this->lng;
201  $ilCtrl = $this->ctrl;
202  $tpl = $this->tpl;
203  $ilHelp = $this->help;
204 
205  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
206  $this->profile->getTitle());
207  $tpl->setDescription($this->profile->getDescription());
208 
209  $ilTabs->clearTargets();
210  $ilHelp->setScreenIdComponent("skmg_prof");
211 
212  $ilCtrl->clearParameterByClass(self::class, "sprof_id");
213  $ilTabs->setBackTarget(
214  $lng->txt("skmg_skill_profiles"),
215  $ilCtrl->getLinkTarget($this, "")
216  );
217  $ilCtrl->setParameter($this, "sprof_id", $this->requested_sprof_id);
218 
219  // levels
220  $ilTabs->addTab(
221  "levels",
222  $lng->txt("skmg_assigned_skill_levels"),
223  $ilCtrl->getLinkTarget($this, "showLevels")
224  );
225 
226  // users
227  $ilTabs->addTab(
228  "users",
229  $lng->txt("skmg_assigned_users"),
230  $ilCtrl->getLinkTarget($this, "showUsers")
231  );
232 
233  // objects
234  $ilTabs->addTab(
235  "objects",
236  $lng->txt("skmg_assigned_objects"),
237  $ilCtrl->getLinkTarget($this, "showObjects")
238  );
239 
240  // settings
241  if ($this->skill_tree_access_manager->hasManageProfilesPermission()) {
242  $ilTabs->addTab(
243  "settings",
244  $lng->txt("settings"),
245  $ilCtrl->getLinkTarget($this, "edit")
246  );
247  }
248 
249  $ilTabs->activateTab($a_active);
250  }
251 
252  public function listProfiles(): void
253  {
254  $tpl = $this->tpl;
255  $ilToolbar = $this->toolbar;
256  $lng = $this->lng;
257  $ilCtrl = $this->ctrl;
258 
259  if ($this->skill_tree_access_manager->hasManageProfilesPermission()) {
260  $ilToolbar->addButton(
261  $lng->txt("skmg_add_profile"),
262  $ilCtrl->getLinkTarget($this, "create")
263  );
264 
265  $ilToolbar->addButton(
266  $lng->txt("import"),
267  $ilCtrl->getLinkTarget($this, "showImportForm")
268  );
269  }
270 
271  $table = $this->table_manager->getProfileTable($this->requested_ref_id, $this->skill_tree_id)->getComponent();
272 
273  $tpl->setContent($this->ui_ren->render($table));
274  }
275 
276  public function listLocalProfiles(): void
277  {
278  $ilCtrl = $this->ctrl;
279 
280  $ilCtrl->redirectByClass("ilcontskilladmingui", "listProfiles");
281  }
282 
283  public function create(): void
284  {
285  $tpl = $this->tpl;
286 
287  $form = $this->initProfileForm("create");
288  $tpl->setContent($this->ui_ren->render($form));
289  }
290 
291  public function createLocal(): void
292  {
293  $tpl = $this->tpl;
294  $lng = $this->lng;
295  $ctrl = $this->ctrl;
296  $tabs = $this->tabs;
297 
298  $tabs->clearTargets();
299  $tabs->setBackTarget(
300  $lng->txt("back_to_course"),
301  $ctrl->getLinkTargetByClass("ilcontskilladmingui", "listProfiles")
302  );
303 
304  $form = $this->initProfileForm("createLocal");
305  $tpl->setContent($this->ui_ren->render($form));
306  }
307 
308  public function edit(): void
309  {
310  $tpl = $this->tpl;
311 
312  $this->setTabs("settings");
313  $form = $this->initProfileForm("edit");
314  $tpl->setContent($this->ui_ren->render($form));
315  }
316 
317  public function initProfileForm(string $a_mode = "edit"): \ILIAS\UI\Component\Input\Container\Form\Form
318  {
319  $lng = $this->lng;
320  $ilCtrl = $this->ctrl;
321 
322  $ilCtrl->setParameter(
323  $this,
324  "profile",
325  "profile_settings"
326  );
327 
328  // title
329  $ti = $this->ui_fac->input()->field()->text($lng->txt("title"))
330  ->withRequired(true);
331 
332  // description
333  $desc = $this->ui_fac->input()->field()->textarea($lng->txt("description"));
334 
335  // skill trees (if local profile)
336  $se = null;
337  if ($a_mode == "createLocal") {
338  $options = [];
339  $trees = $this->tree_service->getObjSkillTrees();
340  foreach ($trees as $tree) {
341  $options[$tree->getId()] = $tree->getTitle();
342  }
343  $se = $this->ui_fac->input()->field()->select($lng->txt("skmg_skill_tree"), $options)->withRequired(true);
344  }
345 
346  // image
347  $img = $this->ui_fac->input()->field()->file(new ilSkillProfileUploadHandlerGUI(), $lng->txt("image"))
348  ->withAcceptedMimeTypes([MimeType::IMAGE__PNG, MimeType::IMAGE__JPEG]);
349 
350  // save commands
351  $sec_des = "";
352  $form_action = "";
353  if ($this->skill_tree_access_manager->hasManageProfilesPermission()) {
354  if ($a_mode == "create") {
355  $sec_des = $lng->txt("skmg_add_profile");
356  $form_action = $ilCtrl->getFormAction($this, "save");
357  } elseif ($a_mode == "createLocal") {
358  $sec_des = $lng->txt("skmg_add_local_profile");
359  $form_action = $ilCtrl->getFormAction($this, "saveLocal");
360  } else {
361  // set values
362  $ti = $ti->withValue($this->profile->getTitle());
363  $desc = $desc->withValue($this->profile->getDescription());
364  $img = $this->profile->getImageId() ? $img->withValue([$this->profile->getImageId()]) : $img;
365 
366  $sec_des = $lng->txt("skmg_edit_profile");
367  $form_action = $ilCtrl->getFormAction($this, "update");
368  }
369  }
370 
371  if (is_null($se)) {
372  $section_basic = $this->ui_fac->input()->field()->section(
373  ["title" => $ti, "description" => $desc],
374  $sec_des
375  );
376  } else {
377  $section_basic = $this->ui_fac->input()->field()->section(
378  ["title" => $ti, "description" => $desc, "skill_tree" => $se],
379  $sec_des
380  );
381  }
382  $section_advanced = $this->ui_fac->input()->field()->section(["image" => $img], $lng->txt("skmg_form_presentation"));
383 
384  $form = $this->ui_fac->input()->container()->form()->standard(
385  $form_action,
386  ["section_basic" => $section_basic, "section_advanced" => $section_advanced]
387  );
388 
389  return $form;
390  }
391 
392  public function save(): void
393  {
394  $tpl = $this->tpl;
395  $lng = $this->lng;
396  $ilCtrl = $this->ctrl;
397 
398  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
399  return;
400  }
401 
402  $form = $this->initProfileForm("create");
403  if ($this->request->getMethod() == "POST"
404  && $this->request->getQueryParams()["profile"] == "profile_settings") {
405  $form = $form->withRequest($this->request);
406  $result = $form->getData();
407  if (is_null($result)) {
408  $tpl->setContent($this->ui_ren->render($form));
409  return;
410  }
411  $profile = $this->skill_factory->profile()->profile(
412  0,
413  $result["section_basic"]["title"],
414  $result["section_basic"]["description"],
415  $this->skill_tree_id,
416  $result["section_advanced"]["image"][0] ?? ""
417  );
418  $this->profile_manager->createProfile($profile);
419 
420  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
421  $ilCtrl->redirect($this, "listProfiles");
422  }
423  $ilCtrl->redirect($this, "listProfiles");
424  }
425 
426  public function saveLocal(): void
427  {
428  $tpl = $this->tpl;
429  $lng = $this->lng;
430  $ilCtrl = $this->ctrl;
431 
432  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
433  return;
434  }
435 
436  $form = $this->initProfileForm("createLocal");
437  if ($this->request->getMethod() == "POST"
438  && $this->request->getQueryParams()["profile"] == "profile_settings") {
439  $form = $form->withRequest($this->request);
440  $result = $form->getData();
441  if (is_null($result)) {
442  $tpl->setContent($this->ui_ren->render($form));
443  return;
444  }
445  $profile = $this->skill_factory->profile()->profile(
446  0,
447  $result["section_basic"]["title"],
448  $result["section_basic"]["description"],
449  (int) $result["section_basic"]["skill_tree"],
450  $result["section_advanced"]["image"][0] ?? "",
451  $this->requested_ref_id
452  );
453  $new_profile = $this->profile_manager->createProfile($profile);
454  $this->profile_manager->addRoleToProfile(
455  $new_profile->getId(),
456  ilParticipants::getDefaultMemberRole($this->requested_ref_id)
457  );
458  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
459  $ilCtrl->redirectByClass("ilcontskilladmingui", "listProfiles");
460  }
461  $ilCtrl->redirectByClass("ilcontskilladmingui", "listProfiles");
462  }
463 
464  public function update(): void
465  {
466  $lng = $this->lng;
467  $ilCtrl = $this->ctrl;
468  $tpl = $this->tpl;
469 
470  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
471  return;
472  }
473 
474  $form = $this->initProfileForm("edit");
475  if ($this->request->getMethod() == "POST"
476  && $this->request->getQueryParams()["profile"] == "profile_settings") {
477  $form = $form->withRequest($this->request);
478  $result = $form->getData();
479  if (is_null($result)) {
480  $tpl->setContent($this->ui_ren->render($form));
481  return;
482  }
483  $profile = $this->skill_factory->profile()->profile(
484  $this->profile->getId(),
485  $result["section_basic"]["title"],
486  $result["section_basic"]["description"],
487  $this->profile->getSkillTreeId(),
488  $result["section_advanced"]["image"][0] ?? "",
489  $this->profile->getRefId()
490  );
491  $this->profile_manager->updateProfile($profile);
492 
493  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
494  $ilCtrl->redirect($this, "edit");
495  }
496  $ilCtrl->redirect($this, "listProfiles");
497  }
498 
499  public function deleteProfiles(): void
500  {
501  $ilCtrl = $this->ctrl;
502  $tpl = $this->tpl;
503  $lng = $this->lng;
504 
505  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
506  return;
507  }
508 
509  if (!empty($this->requested_profile_ids)) {
510  foreach ($this->requested_profile_ids as $i) {
511  $this->profile_manager->delete($i);
512  $this->profile_completion_manager->deleteEntriesForProfile($i);
513  }
514  $this->tpl->setOnScreenMessage('info', $lng->txt("msg_obj_modified"), true);
515  }
516 
517  $ilCtrl->redirect($this, "listProfiles");
518  }
519 
523 
524  public function showLevelsWithTableContext(): void
525  {
526  $ilCtrl = $this->ctrl;
527 
528  if ($this->requested_table_profile_action === "editProfile" && !empty($this->requested_table_profile_ids)) {
529  $ilCtrl->setParameter($this, "sprof_id", $this->requested_table_profile_ids[0]);
530  $ilCtrl->redirect($this, "showLevels");
531  }
532  }
533 
534  public function showLevels(): void
535  {
536  $tpl = $this->tpl;
537  $ilCtrl = $this->ctrl;
538  $lng = $this->lng;
539  $ilToolbar = $this->toolbar;
540 
541  $this->setTabs("levels");
542 
543  if ($this->skill_tree_access_manager->hasManageProfilesPermission()) {
544  $ilToolbar->addButton(
545  $lng->txt("skmg_assign_level"),
546  $ilCtrl->getLinkTarget($this, "assignLevel")
547  );
548  }
549 
550  $tab = new ilSkillProfileLevelsTableGUI(
551  $this,
552  "showLevels",
553  $this->profile
554  );
555  $tpl->setContent($tab->getHTML());
556  }
557 
558  public function showLevelsWithLocalContext(): void
559  {
560  $tpl = $this->tpl;
561  $lng = $this->lng;
562  $ctrl = $this->ctrl;
563  $tabs = $this->tabs;
564  $toolbar = $this->toolbar;
565 
566  $tabs->clearTargets();
567  $tabs->setBackTarget(
568  $lng->txt("back_to_course"),
569  $ctrl->getLinkTargetByClass("ilcontskilladmingui", "listProfiles")
570  );
571 
572  if ($this->skill_tree_access_manager->hasManageProfilesPermission()) {
573  $toolbar->addButton(
574  $lng->txt("skmg_assign_level"),
575  $ctrl->getLinkTarget($this, "assignLevel")
576  );
577  }
578 
579  $tab = new ilSkillProfileLevelsTableGUI(
580  $this,
581  "showLevelsWithLocalContext",
582  $this->profile
583  );
584  $tpl->setContent($tab->getHTML());
585  }
586 
587  public function assignLevel(): void
588  {
589  $lng = $this->lng;
590  $ilTabs = $this->tabs;
591  $ilCtrl = $this->ctrl;
592  $tpl = $this->tpl;
593  $local = $this->local_context;
594 
595  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
596  $this->profile->getTitle());
597  $tpl->setDescription("");
598 
599  //$this->setTabs("levels");
600 
601  $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_select_skill_level_assign"));
602 
603  $ilTabs->clearTargets();
604  if ($local) {
605  $ilTabs->setBackTarget(
606  $lng->txt("back"),
607  $ilCtrl->getLinkTarget($this, "showLevelsWithLocalContext")
608  );
609  } else {
610  $ilTabs->setBackTarget(
611  $lng->txt("back"),
612  $ilCtrl->getLinkTarget($this, "showLevels")
613  );
614  }
615 
616 
617  $exp = new ilSkillSelectorGUI(
618  $this,
619  "assignLevel",
620  $this,
621  "assignLevelSelectSkill",
622  "cskill_id",
623  $this->skill_tree_id
624  );
625  if (!$exp->handleCommand()) {
626  $tpl->setContent($exp->getHTML());
627  }
628  }
629 
633  public function assignLevelSelectSkill(bool $update = false): void
634  {
635  $tpl = $this->tpl;
636  $lng = $this->lng;
637  $ilCtrl = $this->ctrl;
638  $ilTabs = $this->tabs;
639  $local = $this->local_context;
640 
641  $ilCtrl->saveParameter($this, "cskill_id");
642 
643  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
644  $this->profile->getTitle());
645  $tpl->setDescription("");
646 
647  $ilTabs->clearTargets();
648  if ($local) {
649  $ilTabs->setBackTarget(
650  $lng->txt("back"),
651  $ilCtrl->getLinkTarget($this, "showLevelsWithLocalContext")
652  );
653  } else {
654  $ilTabs->setBackTarget(
655  $lng->txt("back"),
656  $ilCtrl->getLinkTarget($this, "showLevels")
657  );
658  }
659 
660  $id_parts = explode(":", $this->requested_cskill_id);
661  $skill_id = (int) $id_parts[0];
662  $skill = new ilBasicSkill($skill_id);
663  $level_data = $skill->getLevelData();
664 
665  $items = [];
666  foreach ($level_data as $levels) {
667  $ilCtrl->setParameterByClass(self::class, "level_id", $levels["id"]);
668  $items[] = $this->ui_fac->item()->standard($levels["title"])->withMainAction(
669  $this->ui_fac->link()->standard(
670  $lng->txt("skmg_assign_level"),
671  $ilCtrl->getLinkTarget($this, $update ? "updateLevelOfProfile" : "assignLevelToProfile")
672  )
673  );
674  $ilCtrl->clearParameterByClass(self::class, "level_id");
675  }
676 
677  $list = $this->ui_fac->panel()->listing()->standard(
678  $skill->getTitle() . ", " . $lng->txt("skmg_skill_levels"),
679  [
680  $this->ui_fac->item()->group("", $items)
681  ]
682  );
683 
684  $tpl->setContent($this->ui_ren->render($list));
685  }
686 
687  public function updateLevelOfSelectedSkill(): void
688  {
689  $this->assignLevelSelectSkill(true);
690  }
691 
692  public function assignLevelToProfile(Profile\SkillProfileLevel $level = null): void
693  {
694  $ilCtrl = $this->ctrl;
695  $lng = $this->lng;
696  $local = $this->local_context;
697 
698  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
699  return;
700  }
701 
702  if ($level) {
703  $this->profile_manager->updateSkillLevel($level);
704  } else {
705  $parts = explode(":", $this->requested_cskill_id);
706  $level = $this->skill_factory->profile()->profileLevel(
707  $this->profile->getId(),
708  (int) $parts[0],
709  (int) $parts[1],
711  $this->profile_manager->getMaxLevelOrderNr($this->profile->getId()) + 10
712  );
713  $this->profile_manager->addSkillLevel($level);
714  }
715 
716  // profile completion check because of profile editing
717  $this->profile_completion_manager->writeCompletionEntryForAllAssignedUsersOfProfile($this->profile->getId());
718 
719  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
720  if ($local) {
721  $ilCtrl->redirect($this, "showLevelsWithLocalContext");
722  }
723  $ilCtrl->redirect($this, "showLevels");
724  }
725 
726  public function updateLevelOfProfile(): void
727  {
728  $parts = explode(":", $this->requested_cskill_id);
729  $level = $this->profile_manager->getSkillLevel($this->profile->getId(), (int) $parts[0], (int) $parts[1]);
730  $level_updated = $this->skill_factory->profile()->profileLevel(
731  $level->getProfileId(),
732  $level->getBaseSkillId(),
733  $level->getTrefId(),
735  $level->getOrderNr()
736  );
737  $this->assignLevelToProfile($level_updated);
738  }
739 
740  public function confirmLevelAssignmentRemoval(): void
741  {
742  $ilCtrl = $this->ctrl;
743  $tpl = $this->tpl;
744  $lng = $this->lng;
745  $tabs = $this->tabs;
746  $local = $this->local_context;
747 
748  if ($local) {
749  $tabs->clearTargets();
750  } else {
751  $this->setTabs("levels");
752  }
753 
754  if (empty($this->requested_level_ass_ids)) {
755  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
756  if ($local) {
757  $ilCtrl->redirect($this, "showLevelsWithLocalContext");
758  }
759  $ilCtrl->redirect($this, "showLevels");
760  } else {
761  $cgui = new ilConfirmationGUI();
762  $cgui->setFormAction($ilCtrl->getFormAction($this));
763  $cgui->setHeaderText($lng->txt("skmg_confirm_remove_level_ass"));
764  if ($local) {
765  $cgui->setCancel($lng->txt("cancel"), "showLevelsWithLocalContext");
766  } else {
767  $cgui->setCancel($lng->txt("cancel"), "showLevels");
768  }
769  $cgui->setConfirm($lng->txt("remove"), "removeLevelAssignments");
770 
771  foreach ($this->requested_level_ass_ids as $i) {
772  $id_arr = explode(":", $i);
773  $cgui->addItem(
774  "ass_id[]",
775  $i,
776  ilBasicSkill::_lookupTitle((int) $id_arr[0]) . ": " .
777  ilBasicSkill::lookupLevelTitle((int) $id_arr[2])
778  );
779  }
780 
781  $tpl->setContent($cgui->getHTML());
782  }
783  }
784 
785  public function removeLevelAssignments(): void
786  {
787  $ilCtrl = $this->ctrl;
788  $local = $this->local_context;
789 
790  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
791  return;
792  }
793 
794  if (!empty($this->requested_level_ass_ids)) {
795  foreach ($this->requested_level_ass_ids as $i) {
796  $id_arr = explode(":", $i);
797  $level = $this->skill_factory->profile()->profileLevel(
798  $this->profile->getId(),
799  (int) $id_arr[0],
800  (int) $id_arr[1],
801  (int) $id_arr[2],
802  (int) $id_arr[3]
803  );
804  $this->profile_manager->removeSkillLevel($level);
805  }
806  $this->profile_manager->fixSkillOrderNumbering($this->profile->getId());
807  }
808 
809  // profile completion check because of profile editing
810  $this->profile_completion_manager->writeCompletionEntryForAllAssignedUsersOfProfile($this->profile->getId());
811 
812  if ($local) {
813  $ilCtrl->redirect($this, "showLevelsWithLocalContext");
814  }
815  $ilCtrl->redirect($this, "showLevels");
816  }
817 
818  public function saveLevelOrder(): void
819  {
820  $lng = $this->lng;
821  $ilCtrl = $this->ctrl;
822  $local = $this->local_context;
823 
824  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
825  return;
826  }
827 
828  $order = ilArrayUtil::stripSlashesArray($this->requested_level_order);
829  $this->profile_manager->updateSkillOrder($this->profile->getId(), $order);
830 
831  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
832  if ($local) {
833  $ilCtrl->redirect($this, "showLevelsWithLocalContext");
834  }
835  $ilCtrl->redirect($this, "showLevels");
836  }
837 
838  public function showUsers(): void
839  {
840  $lng = $this->lng;
841  $tpl = $this->tpl;
842  $ilToolbar = $this->toolbar;
843 
844  // add member
845  if ($this->skill_tree_access_manager->hasManageProfilesPermission() && !$this->profile->getRefId() > 0) {
847  $this,
848  $ilToolbar,
849  array(
850  'auto_complete_name' => $lng->txt('user'),
851  'submit_name' => $lng->txt('skmg_assign_user')
852  )
853  );
854 
855  $ilToolbar->addSeparator();
856 
857  $button = $this->ui_fac->button()->standard(
858  $this->lng->txt("skmg_add_assignment"),
859  $this->ctrl->getLinkTargetByClass("ilRepositorySearchGUI", "start")
860  );
861  $ilToolbar->addComponent($button);
862  }
863 
864  $this->setTabs("users");
865 
866  $table = $this->table_manager->getProfileUserAssignmentTable(
867  $this->profile,
868  $this->skill_tree_access_manager
869  )->getComponent();
870  $tpl->setContent($this->ui_ren->render($table));
871  }
872 
873  public function assignUser(): void
874  {
875  $ilCtrl = $this->ctrl;
876  $lng = $this->lng;
877 
878  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
879  return;
880  }
881 
882  // user assignment with toolbar
883  $user_id = ilObjUser::_lookupId($this->requested_user_login);
884  if ($user_id > 0) {
885  $this->profile_manager->addUserToProfile($this->profile->getId(), $user_id);
886  // profile completion check for added user
887  $this->profile_completion_manager->writeCompletionEntryForSingleProfileOfUser($user_id, $this->profile->getId());
888  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
889  }
890 
891  // user assignment with ilRepositorySearchGUI
892  $users = $this->requested_users;
893  if (!empty($users)) {
894  foreach ($users as $id) {
895  if ($id > 0) {
896  $this->profile_manager->addUserToProfile($this->profile->getId(), $id);
897  // profile completion check for added user
898  $this->profile_completion_manager->writeCompletionEntryForSingleProfileOfUser($id, $this->profile->getId());
899  }
900  }
901  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
902  }
903 
904  $ilCtrl->redirect($this, "showUsers");
905  }
906 
907  public function assignRole(array $role_ids): void
908  {
909  $ilCtrl = $this->ctrl;
910  $lng = $this->lng;
911 
912  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
913  return;
914  }
915 
916  $success = false;
917  foreach ($role_ids as $id) {
918  if ($id > 0) {
919  $this->profile_manager->addRoleToProfile($this->profile->getId(), $id);
920  $this->profile_completion_manager->writeCompletionEntryForRole($id, $this->profile->getId());
921  $success = true;
922  }
923  }
924  if ($success) {
925  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
926  }
927 
928  $ilCtrl->redirect($this, "showUsers");
929  }
930 
931  public function removeUsers(): void
932  {
933  $ilCtrl = $this->ctrl;
934  $lng = $this->lng;
935 
936  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
937  return;
938  }
939 
940  if (!empty($this->requested_user_ids)) {
941  foreach ($this->requested_user_ids as $i) {
942  $type = ilObject::_lookupType($i);
943  switch ($type) {
944  case "usr":
945  $this->profile_manager->removeUserFromProfile($this->profile->getId(), $i);
946  break;
947 
948  case "role":
949  $this->profile_manager->removeRoleFromProfile($this->profile->getId(), $i);
950  break;
951 
952  default:
953  echo "not deleted";
954  }
955  }
956  $this->tpl->setOnScreenMessage("success", $lng->txt("msg_obj_modified"), true);
957  }
958  $ilCtrl->redirect($this, "showUsers");
959  }
960 
961  public function showObjects(): void
962  {
963  $tpl = $this->tpl;
964 
965  $this->setTabs("objects");
966 
967  $objects = $this->usage_manager->getAssignedObjectsForSkillProfile($this->profile->getId());
968 
969  $table = $this->table_manager->getAssignedObjectsTable(
970  $this,
971  $objects,
972  0,
973  0,
974  $this->profile->getId()
975  )->getComponent();
976  $tpl->setContent($this->ui_ren->render($table));
977  }
978 
979  public function exportProfiles(): void
980  {
981  $ilCtrl = $this->ctrl;
982  $lng = $this->lng;
983 
984  if (!$this->skill_tree_access_manager->hasManageProfilesPermission()) {
985  return;
986  }
987 
988  $profiles_to_export = [];
989  if ($this->requested_table_profile_action === "exportProfiles"
990  && !empty($this->requested_table_profile_ids)
991  && $this->requested_table_profile_ids[0] === "ALL_OBJECTS"
992  ) {
993  $profiles = $this->skill_tree_id
994  ? $this->profile_manager->getProfilesForSkillTree($this->skill_tree_id)
995  : $this->profile_manager->getProfilesForAllSkillTrees();
996  foreach ($profiles as $profile) {
997  $profiles_to_export[] = $profile->getId();
998  }
999  } elseif ($this->requested_table_profile_action === "exportProfiles") {
1000  $profiles_to_export = array_map("intval", $this->requested_table_profile_ids);
1001  }
1002 
1003  if (empty($profiles_to_export)) {
1004  $this->tpl->setOnScreenMessage('info', $lng->txt("no_checkbox"), true);
1005  $ilCtrl->redirect($this, "");
1006  }
1007 
1008  $exp = new ilExport();
1009  $conf = $exp->getConfig("Services/Skill");
1010  $conf->setMode(ilSkillExportConfig::MODE_PROFILES);
1011  $conf->setSelectedProfiles($profiles_to_export);
1012  $conf->setSkillTreeId($this->skill_tree_id);
1013  $exp->exportObject("skmg", ilObject::_lookupObjId($this->requested_ref_id));
1014 
1015  //ilExport::_createExportDirectory(0, "xml", "");
1016  //$export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
1017  //$exp->exportEntity("skprof", $_POST["id"], "", "Services/Skill", $a_title, $a_export_dir, "skprof");
1018 
1019  $ilCtrl->redirectByClass(array("ilobjskilltreegui", "ilexportgui"), "");
1020  }
1021 
1022  public function showImportForm(): void
1023  {
1024  $tpl = $this->tpl;
1025  $ilTabs = $this->tabs;
1026 
1027  $tpl->setContent($this->initInputForm()->getHTML());
1028  }
1029 
1031  {
1032  $lng = $this->lng;
1033  $ilCtrl = $this->ctrl;
1034 
1035  $form = new ilPropertyFormGUI();
1036 
1037  $fi = new ilFileInputGUI($lng->txt("skmg_input_file"), "import_file");
1038  $fi->setSuffixes(array("zip"));
1039  $fi->setRequired(true);
1040  $form->addItem($fi);
1041 
1042  // save and cancel commands
1043  $form->addCommandButton("importProfiles", $lng->txt("import"));
1044  $form->addCommandButton("", $lng->txt("cancel"));
1045 
1046  $form->setTitle($lng->txt("import"));
1047  $form->setFormAction($ilCtrl->getFormAction($this));
1048 
1049  return $form;
1050  }
1051 
1052  public function importProfiles(): void
1053  {
1054  $tpl = $this->tpl;
1055  $lng = $this->lng;
1056  $ilCtrl = $this->ctrl;
1057 
1058  $form = $this->initInputForm();
1059  if ($form->checkInput()) {
1060  $imp = new ilImport();
1061  $conf = $imp->getConfig("Services/Skill");
1062  $conf->setSkillTreeId($this->skill_tree_id);
1063  $imp->importEntity($_FILES["import_file"]["tmp_name"], $_FILES["import_file"]["name"], "skmg", "Services/Skill");
1064 
1065  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
1066  $ilCtrl->redirect($this, "");
1067  } else {
1068  $form->setValuesByPost();
1069  $tpl->setContent($form->getHTML());
1070  }
1071  }
1072 }
TableGUI class for skill profile levels.
getLinkTargetByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
Skill profile GUI class.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
SkillTreeAccess $skill_tree_access_manager
Class ilSkillProfileUploadHandlerGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Profile SkillProfile $profile
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
Class ChatMainBarProvider .
Request wrapper for guis in skill administration.
Help GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
Import class.
static _lookupId($a_user_str)
setSuffixes(array $a_suffixes)
static lookupLevelTitle(int $a_id)
assignLevelSelectSkill(bool $update=false)
Output level table for profile assignment.
Export.
static getDefaultMemberRole(int $a_ref_id)
SkillAdminGUIRequest $admin_gui_request
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Table TableManager $table_manager
initProfileForm(string $a_mode="edit")
static _lookupObjId(int $ref_id)
ilGlobalTemplateInterface $tpl
global $DIC
Definition: feed.php:28
ILIAS Data Factory $df
SkillTreeService $tree_service
addButton(string $a_txt, string $a_cmd, string $a_target="", ?int $a_acc_key=null, string $a_additional_attrs='', string $a_id="", string $a_class='submit')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContent(string $a_html)
Sets content for standard template.
setBackTarget(string $a_title, string $a_target, string $a_frame="")
ServerRequestInterface $request
static fillAutoCompleteToolbar(object $parent_object, ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt(&#39;user&#39;), auto_complete_size = 15, user_type = array(ilCoursePar...
__construct(SkillTreeAccess $skill_tree_access_manager, int $skill_tree_id=0)
clearTargets()
clear all targets
assignLevelToProfile(Profile\SkillProfileLevel $level=null)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ArrayBasedRequestWrapper $query
Explorer class that works on tree objects (Services/Tree)
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
Profile SkillProfileManager $profile_manager
setDescription(string $a_descr)
Sets description below title in standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
SkillInternalFactoryService $skill_factory
static _lookupType(int $id, bool $reference=false)
Basic Skill.
Profile SkillProfileCompletionManager $profile_completion_manager
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashesArray(array $a_arr, bool $a_strip_html=true, string $a_allow="")
Usage SkillUsageManager $usage_manager