ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjSkillManagementGUI.php
Go to the documentation of this file.
1 <?php
2 
27 
36 {
39  protected ilTabsGUI $tabs;
40  protected Factory $ui_fac;
41  protected Renderer $ui_ren;
46  protected Tree\SkillTreeNodeManager $skill_tree_node_manager;
49  protected int $requested_node_id = 0;
50  protected int $requested_tref_id = 0;
51  protected int $requested_templates_tree = 0;
52  protected string $requested_skexpand = "";
53  protected int $requested_tmpmode = 0;
54 
58  protected array $requested_titles = [];
59 
63  protected array $requested_node_ids = [];
64 
71  public function __construct(
72  $a_data,
73  int $a_id,
74  bool $a_call_by_reference = true,
75  bool $a_prepare_output = true
76  ) {
77  global $DIC;
78 
79  $this->ctrl = $DIC->ctrl();
80  $this->rbacsystem = $DIC->rbac()->system();
81  $this->error = $DIC["ilErr"];
82  $this->access = $DIC->access();
83  $this->tabs = $DIC->tabs();
84  $this->lng = $DIC->language();
85  $this->settings = $DIC->settings();
86  $this->tpl = $DIC["tpl"];
87  $this->toolbar = $DIC->toolbar();
88  $this->user = $DIC->user();
89  $this->ui_fac = $DIC->ui()->factory();
90  $this->ui_ren = $DIC->ui()->renderer();
91  $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
92  $ilCtrl = $DIC->ctrl();
93 
94  $this->tool_context = $DIC->globalScreen()->tool()->context();
95 
96  $this->type = 'skmg';
97  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
98 
99  $this->lng->loadLanguageModule('skmg');
100 
101  $ilCtrl->saveParameter($this, "node_id");
102  $this->skill_manager = $DIC->skills()->internal()->manager();
103  $this->skill_tree_node_manager = $this->skill_manager->getTreeNodeManager($this->object->getId());
104  $this->management_access_manager = $this->skill_manager->getManagementAccessManager($this->object->getRefId());
105 
106  $this->requested_node_id = $this->admin_gui_request->getNodeId();
107  $this->requested_tref_id = $this->admin_gui_request->getTrefId();
108  $this->requested_templates_tree = $this->admin_gui_request->getTemplatesTree();
109  $this->requested_skexpand = $this->admin_gui_request->getSkillExpand();
110  $this->requested_tmpmode = $this->admin_gui_request->getTemplateMode();
111  $this->requested_titles = $this->admin_gui_request->getTitles();
112  $this->requested_node_ids = $this->admin_gui_request->getNodeIds();
113  }
114 
115  public function executeCommand(): void
116  {
117  $rbacsystem = $this->rbacsystem;
119  $ilTabs = $this->tabs;
120 
121  $next_class = $this->ctrl->getNextClass($this);
122  $cmd = $this->ctrl->getCmd();
123 
124  if (!$this->management_access_manager->hasReadManagementPermission()) {
125  $ilErr->raiseError($this->lng->txt('no_permission'), $ilErr->WARNING);
126  }
127 
128  switch ($next_class) {
129  case "ilskilltreeadmingui":
130  $this->prepareOutput();
131  $ilTabs->activateTab("skill_trees");
132  $gui = new ilSkillTreeAdminGUI($this->skill_manager);
133  $this->ctrl->forwardCommand($gui);
134  break;
135 
136  case 'ilpermissiongui':
137  $this->prepareOutput();
138  $this->tabs_gui->activateTab('permissions');
139  $perm_gui = new ilPermissionGUI($this);
140  $ret = $this->ctrl->forwardCommand($perm_gui);
141  break;
142 
143  default:
144  $this->prepareOutput();
145  if (!$cmd || $cmd == 'view') {
146  $cmd = "listTrees";
147  }
148 
149  if ($cmd == "showTree") {
150  $this->showTree((bool) $this->requested_templates_tree);
151  } else {
152  $this->$cmd();
153  }
154  break;
155  }
156  }
157 
158  public function getAdminTabs(): void
159  {
160  $rbacsystem = $this->rbacsystem;
161  $ilAccess = $this->access;
162  $lng = $this->lng;
163 
164  if ($this->management_access_manager->hasReadManagementPermission()) {
165  $this->tabs_gui->addTab(
166  "skill_trees",
167  $lng->txt("skmg_skill_trees"),
168  $this->ctrl->getLinkTargetByClass("ilskilltreeadmingui", "")
169  );
170 
171  $this->tabs_gui->addTab(
172  "settings",
173  $lng->txt("settings"),
174  $this->ctrl->getLinkTarget($this, "editSettings")
175  );
176  }
177 
178  if ($this->management_access_manager->hasEditManagementPermissionsPermission()) {
179  $this->tabs_gui->addTab(
180  "permissions",
181  $lng->txt("perm_settings"),
182  $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm")
183  );
184  }
185  }
186 
187  public function editSettings(): void
188  {
189  $ilCtrl = $this->ctrl;
190  $lng = $this->lng;
191  $ilTabs = $this->tabs;
192 
193  $ilTabs->activateTab("settings");
194 
195  $skmg_set = new ilSkillManagementSettings();
196 
197  // Enable skill management
198  $check_enable = $this->ui_fac->input()->field()->checkbox($lng->txt("skmg_enable_skmg"))
199  ->withValue($skmg_set->isActivated());
200 
201  // Hide Competence Profile Data before Self-Assessment
202  $check_hide_prof = $this->ui_fac->input()->field()->checkbox(
203  $lng->txt("skmg_hide_profile_self_eval"),
204  $lng->txt("skmg_hide_profile_self_eval_info")
205  )->withValue($skmg_set->getHideProfileBeforeSelfEval());
206 
207  // Allow local assignment of global profiles
208  $check_loc_ass_prof = $this->ui_fac->input()->field()->checkbox($lng->txt("skmg_local_assignment_profiles"))
209  ->withValue($skmg_set->getLocalAssignmentOfProfiles());
210 
211  // Allow creation of local profiles
212  $check_create_loc_prof = $this->ui_fac->input()->field()->checkbox(
213  $lng->txt("skmg_allow_local_profiles"),
214  $lng->txt("skmg_allow_local_profiles_info")
215  )->withValue($skmg_set->getAllowLocalProfiles());
216 
217  //section
218  $section_settings = $this->ui_fac->input()->field()->section(
219  ["check_enable" => $check_enable,
220  "check_hide_prof" => $check_hide_prof,
221  "check_loc_ass_prof" => $check_loc_ass_prof,
222  "check_create_loc_prof" => $check_create_loc_prof],
223  $lng->txt("skmg_settings")
224  );
225 
226  // form and form action handling
227  $ilCtrl->setParameterByClass(
228  'ilobjskillmanagementgui',
229  'skill_settings',
230  'skill_settings_config'
231  );
232 
233  $form = $this->ui_fac->input()->container()->form()->standard(
234  $ilCtrl->getFormAction($this, "editSettings"),
235  ["section_settings" => $section_settings]
236  );
237 
238  if ($this->request->getMethod() == "POST"
239  && $this->request->getQueryParams()["skill_settings"] == "skill_settings_config") {
240  if (!$this->management_access_manager->hasEditManagementSettingsPermission()) {
241  return;
242  }
243 
244  $form = $form->withRequest($this->request);
245  $result = $form->getData();
246 
247  $skmg_set->activate($result["section_settings"]["check_enable"]);
248  $skmg_set->setHideProfileBeforeSelfEval($result["section_settings"]["check_hide_prof"]);
249  $skmg_set->setLocalAssignmentOfProfiles($result["section_settings"]["check_loc_ass_prof"]);
250  $skmg_set->setAllowLocalProfiles($result["section_settings"]["check_create_loc_prof"]);
251 
252  $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
253  $ilCtrl->redirect($this, "editSettings");
254  }
255 
256  $this->tpl->setContent($this->ui_ren->render([$form]));
257  }
258 
259  public function listTrees(): void
260  {
261  $this->ctrl->clearParameterByClass(get_class($this), "node_id");
262  $this->ctrl->redirectByClass("ilskilltreeadmingui", "listTrees");
263  }
264 
265  public function saveAllTitles(bool $a_succ_mess = true): void
266  {
267  $ilCtrl = $this->ctrl;
268  $lng = $this->lng;
269 
270  if (!count($this->requested_titles) == 0) {
271  foreach ($this->requested_titles as $id => $title) {
273  if (is_object($node_obj)) {
274  // update title
276  }
277  }
278  if ($a_succ_mess) {
279  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
280  }
281  }
282  $ilCtrl->redirect($this, "editSkills");
283  }
284 
285  public function saveAllTemplateTitles(bool $a_succ_mess = true): void
286  {
287  $ilCtrl = $this->ctrl;
288  $lng = $this->lng;
289 
290  if (!count($this->requested_titles) == 0) {
291  foreach ($this->requested_titles as $id => $title) {
293  if (is_object($node_obj)) {
294  // update title
296  }
297  }
298  if ($a_succ_mess) {
299  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
300  }
301  }
302  $ilCtrl->redirect($this, "editSkillTemplates");
303  }
304 
305  public function expandAll(bool $a_redirect = true): void
306  {
307  $this->requested_skexpand = "";
308  $n_id = ($this->requested_node_id > 0)
309  ? $this->requested_node_id
310  : $this->skill_tree->readRootId();
311  $stree = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($n_id));
312  $n_arr = [];
313  foreach ($stree as $n) {
314  $n_arr[] = $n["child"];
315  ilSession::set("skexpand", $n_arr);
316  }
317  $this->saveAllTitles(false);
318  }
319 
320  public function collapseAll(bool $a_redirect = true): void
321  {
322  $this->requested_skexpand = "";
323  $n_id = ($this->requested_node_id > 0)
324  ? $this->requested_node_id
325  : $this->skill_tree->readRootId();
326  $stree = $this->skill_tree->getSubTree($this->skill_tree->getNodeData($n_id));
327  $old = ilSession::get("skexpand");
328  foreach ($stree as $n) {
329  if (in_array($n["child"], $old) && $n["child"] != $n_id) {
330  $k = array_search($n["child"], $old);
331  unset($old[$k]);
332  }
333  }
334  ilSession::set("skexpand", $old);
335  $this->saveAllTitles(false);
336  }
337 
338  public function deleteNodes(object $a_gui): void
339  {
340  $lng = $this->lng;
341  $tpl = $this->tpl;
342  $ilCtrl = $this->ctrl;
343  $ilTabs = $this->tabs;
344  $ilToolbar = $this->toolbar;
345 
346  if (empty($this->requested_node_ids)) {
347  $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE);
348  }
349 
350  $ilTabs->clearTargets();
351 
352  // check usages
353  $mode = "";
354  $cskill_ids = [];
355  foreach ($this->requested_node_ids as $id) {
356  if (in_array(ilSkillTreeNode::_lookupType($id), array("skll", "scat", "sktr"))) {
357  if ($mode == "templates") {
358  $this->ilias->raiseError("Skill Deletion - type mismatch.", $this->ilias->error_obj->MESSAGE);
359  }
360  $mode = "basic";
361  $skill_id = $id;
362  $tref_id = 0;
363  if (ilSkillTreeNode::_lookupType($id) == "sktr") {
365  $tref_id = $id;
366  }
367  $cskill_ids[] = array("skill_id" => $skill_id, "tref_id" => $tref_id);
368  }
369  if (in_array(ilSkillTreeNode::_lookupType($id), array("sktp", "sctp"))) {
370  if ($mode == "basic") {
371  $this->ilias->raiseError("Skill Deletion - type mismatch.", $this->ilias->error_obj->MESSAGE);
372  }
373  $mode = "templates";
374 
375  foreach (ilSkillTemplateReference::_lookupTrefIdsForTemplateId($id) as $tref_id) {
376  $cskill_ids[] = array("skill_id" => $id, "tref_id" => $tref_id);
377  }
378  }
379  // for cats, skills and template references, get "real" usages
380  // for skill and category templates check usage in references
381  }
382 
383  if ($mode == "basic" || $mode == "templates") {
384  $u = new ilSkillUsage();
385  $usages = $u->getAllUsagesInfoOfSubtrees($cskill_ids);
386  if (count($usages) > 0) {
387  $html = "";
388  foreach ($usages as $k => $usage) {
389  $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
390  $html .= $tab->getHTML() . "<br/><br/>";
391  }
393  $ilCtrl->saveParameter($a_gui, "tmpmode");
394  $ilToolbar->addButton(
395  $lng->txt("back"),
396  $ilCtrl->getLinkTarget($a_gui, "cancelDelete")
397  );
398  $this->tpl->setOnScreenMessage('failure', $lng->txt("skmg_cannot_delete_nodes_in_use"));
399  return;
400  }
401  } else {
402  $this->ilias->raiseError("Skill Deletion - type mismatch.", $this->ilias->error_obj->MESSAGE);
403  }
404 
405  // SAVE POST VALUES
406  ilSession::set("saved_post", $this->requested_node_ids);
407 
408  $confirmation_gui = new ilConfirmationGUI();
409 
410  $ilCtrl->setParameter($a_gui, "tmpmode", $this->requested_tmpmode);
411  $a_form_action = $this->ctrl->getFormAction($a_gui);
412  $confirmation_gui->setFormAction($a_form_action);
413  $confirmation_gui->setHeaderText($this->lng->txt("info_delete_sure"));
414 
415  // Add items to delete
416  foreach ($this->requested_node_ids as $id) {
417  if ($id != ilTree::POS_FIRST_NODE) {
418  $node_obj = ilSkillTreeNodeFactory::getInstance($id);
419  $confirmation_gui->addItem(
420  "id[]",
421  $node_obj->getId(),
422  $node_obj->getTitle(),
423  ilUtil::getImagePath("icon_" . $node_obj->getType() . ".svg")
424  );
425  }
426  }
427 
428  $confirmation_gui->setCancel($lng->txt("cancel"), "cancelDelete");
429  $confirmation_gui->setConfirm($lng->txt("confirm"), "confirmedDelete");
430 
431  $tpl->setContent($confirmation_gui->getHTML());
432  }
433 
434  public function cancelDelete(): void
435  {
436  $this->ctrl->redirect($this, "editSkills");
437  }
438 
439  public function confirmedDelete(): void
440  {
441  $ilCtrl = $this->ctrl;
442 
443  // delete all selected objects
444  foreach ($this->requested_node_ids as $id) {
445  if ($id != ilTree::POS_FIRST_NODE) {
447  $node_data = $this->skill_tree->getNodeData($id);
448  if (is_object($obj)) {
449  $obj->delete();
450  }
451  if ($this->skill_tree->isInTree($id)) {
452  $this->skill_tree->deleteTree($node_data);
453  }
454  }
455  }
456 
457  // feedback
458  $this->tpl->setOnScreenMessage('info', $this->lng->txt("info_deleted"), true);
459  }
460 
461  //
462  // Skill Templates
463  //
464 
465  public function editSkillTemplates(): void
466  {
467  $tpl = $this->tpl;
468  $ilTabs = $this->tabs;
469  $lng = $this->lng;
470  $ilCtrl = $this->ctrl;
471 
472  $ilTabs->activateTab("skill_templates");
473  $ilCtrl->setParameterByClass("ilobjskillmanagementgui", "node_id", $this->skill_tree->readRootId());
474  $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
475  }
476 
477  //
478  // Tree
479  //
480 
481  public function showTree(bool $a_templates, $a_gui = null, string $a_gui_cmd = ""): void
482  {
484  $tpl = $this->tpl;
485  $ilCtrl = $this->ctrl;
486  $lng = $this->lng;
487 
488  if ($a_templates) {
489  if ($this->requested_node_id == 0 || $this->requested_node_id == 1) {
490  return;
491  }
492 
493  if ($this->requested_node_id > 1) {
494  $path = $this->skill_tree->getPathId($this->requested_node_id);
495  if (ilSkillTreeNode::_lookupType($path[1]) == "sktp") {
496  return;
497  }
498  }
499  }
500 
501  $ilCtrl->setParameter($this, "templates_tree", (int) $a_templates);
502 
503  if ($a_templates) {
504  $this->tool_context->current()->addAdditionalData(ilSkillGSToolProvider::SHOW_TEMPLATE_TREE, true);
505  $exp = new ilSkillTemplateTreeExplorerGUI($this, "showTree", $this->skill_tree->getTreeId());
506  } else {
507  $this->tool_context->current()->addAdditionalData(ilSkillGSToolProvider::SHOW_SKILL_TREE, true);
508  $exp = new ilSkillTreeExplorerGUI($this, "showTree", $this->skill_tree->getTreeId());
509  }
510  if (!$exp->handleCommand()) {
511  $tpl->setLeftNavContent($exp->getHTML());
512  }
513  }
514 }
static get(string $a_var)
An entity that renders components to a string output.
Definition: Renderer.php:30
__construct( $a_data, int $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
Skill tree administration.
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...
showTree(bool $a_templates, $a_gui=null, string $a_gui_cmd="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree SkillTreeNodeManager $skill_tree_node_manager
prepareOutput(bool $show_sub_objects=true)
Request wrapper for guis in skill administration.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
SkillManagementAccess $management_access_manager
Explorer class that works on tree objects (Services/Tree)
setParameterByClass(string $a_class, string $a_parameter, $a_value)
static _lookupType(int $a_obj_id)
SkillInternalManagerService $skill_manager
$ilErr
Definition: raiseError.php:17
$path
Definition: ltiservices.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
const POS_FIRST_NODE
ilLanguage $lng
saveAllTemplateTitles(bool $a_succ_mess=true)
ilGlobalTemplateInterface $tpl
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjectGUI Basic methods of all Output classes.
ilToolbarGUI $toolbar
header include for all ilias files.
TableGUI class for skill usages.
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
activateTab(string $a_id)
Error Handling & global info handling uses PEAR error class.
__construct(Container $dic, ilPlugin $plugin)
ilAccessHandler $access
$ilUser
Definition: imgupload.php:34
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
Explorer class that works on tree objects (Services/Tree)
Skill usage.
static _writeTitle(int $a_obj_id, string $a_title)
static set(string $a_var, $a_val)
Set a value.
setLeftNavContent(string $a_content)
Sets content of left navigation column.
Skill management main GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...