ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSkillCategoryGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
32 {
33  protected ilCtrl $ctrl;
35  protected ilTabsGUI $tabs;
36  protected ilLanguage $lng;
37  protected ilHelpGUI $help;
38 
39  public function __construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id = 0)
40  {
41  global $DIC;
42 
43  $this->ctrl = $DIC->ctrl();
44  $this->tpl = $DIC["tpl"];
45  $this->tabs = $DIC->tabs();
46  $this->lng = $DIC->language();
47  $this->help = $DIC["ilHelp"];
48  $ilCtrl = $DIC->ctrl();
49 
50  $ilCtrl->saveParameter($this, "node_id");
51 
52  parent::__construct($node_manager, $a_node_id);
53  }
54 
55  public function getType(): string
56  {
57  return "scat";
58  }
59 
60  public function executeCommand(): void
61  {
62  $ilCtrl = $this->ctrl;
63  $tpl = $this->tpl;
64  $ilTabs = $this->tabs;
65 
66  //$tpl->getStandardTemplate();
67 
68  $next_class = $ilCtrl->getNextClass($this);
69  $cmd = $ilCtrl->getCmd();
70 
71  switch ($next_class) {
72  default:
73  $ret = $this->$cmd();
74  break;
75  }
76  }
77 
78  public function setTabs(string $a_tab): void
79  {
80  $ilTabs = $this->tabs;
81  $ilCtrl = $this->ctrl;
82  $tpl = $this->tpl;
83  $lng = $this->lng;
84  $ilHelp = $this->help;
85 
86  $ilTabs->clearTargets();
87  $ilHelp->setScreenIdComponent("skmg_scat");
88 
89  // content
90  $ilTabs->addTab(
91  "content",
92  $lng->txt("content"),
93  $ilCtrl->getLinkTarget($this, 'listItems')
94  );
95 
96  // properties
97  $ilTabs->addTab(
98  "properties",
99  $lng->txt("settings"),
100  $ilCtrl->getLinkTarget($this, 'editProperties')
101  );
102 
103  // usage
104  $this->addUsageTab($ilTabs);
105 
106  $parent_node_id = $this->tree_repo->getParentNodeIdForNodeId($this->requested_node_id);
107  $parent_title = ilSkillTreeNode::_lookupTitle($parent_node_id);
108  $parent_type = ilSkillTreeNode::_lookupType($parent_node_id);
109 
110  // back link
111  if ($parent_type === "scat") {
112  $ilCtrl->setParameter(
113  $this,
114  "node_id",
115  $parent_node_id
116  );
117  $ilTabs->setBackTarget(
118  $parent_title,
119  $ilCtrl->getLinkTarget($this, "listItems")
120  );
121  $ilCtrl->setParameter(
122  $this,
123  "node_id",
124  $this->requested_node_id
125  );
126  } else {
127  $ilCtrl->setParameterByClass(
128  "ilskillrootgui",
129  "node_id",
130  $this->skill_tree_node_manager->getRootId()
131  );
132  $ilTabs->setBackTarget(
133  $lng->txt("skmg_skills"),
134  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "listSkills")
135  );
136  $ilCtrl->setParameterByClass(
137  "ilskillrootgui",
138  "node_id",
139  $this->requested_node_id
140  );
141  }
142 
143  parent::setTitleIcon();
144  $tpl->setTitle(
145  $lng->txt("scat") . ": " . $this->node_object->getTitle()
146  );
147  $this->setSkillNodeDescription();
148 
149  $ilTabs->activateTab($a_tab);
150  }
151 
152  public function editProperties(): void
153  {
154  $tpl = $this->tpl;
155 
156  $this->setTabs("properties");
157  parent::editProperties();
158  }
159 
160  public function edit(): void
161  {
162  $tpl = $this->tpl;
163 
164  $this->initForm();
165  $this->getValues();
166  $tpl->setContent($this->form->getHTML());
167  }
168 
169  public function initForm(string $a_mode = "edit"): void
170  {
171  $lng = $this->lng;
172  $ilCtrl = $this->ctrl;
173 
174  $this->form = new ilPropertyFormGUI();
175 
176  // title
177  $ti = new ilTextInputGUI($lng->txt("title"), "title");
178  $ti->setMaxLength(200);
179  $ti->setSize(50);
180  $ti->setRequired(true);
181  $this->form->addItem($ti);
182 
183  // description
184  $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
185  $ta->setRows(5);
186  $this->form->addItem($ta);
187 
188  // status
189  $this->addStatusInput($this->form);
190 
191  // selectable
192  $cb = new ilCheckboxInputGUI($lng->txt("skmg_selectable"), "self_eval");
193  $cb->setInfo($lng->txt("skmg_selectable_info"));
194  $this->form->addItem($cb);
195 
196  // save and cancel commands
197  if ($this->tree_access_manager->hasManageCompetencesPermission()) {
198  if ($a_mode == "create") {
199  $this->form->addCommandButton("save", $lng->txt("save"));
200  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
201  $this->form->setTitle($lng->txt("skmg_create_skill_category"));
202  } else {
203  $this->form->addCommandButton("update", $lng->txt("save"));
204  $this->form->setTitle($lng->txt("skmg_edit_scat"));
205  }
206  } else {
207  foreach ($this->form->getItems() as $item) {
208  $item->setDisabled(true);
209  }
210  }
211 
212  $ilCtrl->setParameter($this, "node_id", $this->requested_node_id);
213  $this->form->setFormAction($ilCtrl->getFormAction($this));
214  }
215 
216  public function saveItem(): void
217  {
218  if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
219  return;
220  }
221 
222  $it = new ilSkillCategory();
223  $it->setTitle($this->form->getInput("title"));
224  $it->setDescription($this->form->getInput("description"));
225  $it->setSelfEvaluation((bool) $this->form->getInput("self_eval"));
226  $it->setStatus((int) $this->form->getInput("status"));
227  $it->create();
228  $this->skill_tree_node_manager->putIntoTree($it, $this->requested_node_id, ilTree::POS_LAST_NODE);
229  }
230 
234  public function getValues(): void
235  {
236  $values = [];
237  $values["title"] = $this->node_object->getTitle();
238  $values["description"] = $this->node_object->getDescription();
239  $values["self_eval"] = $this->node_object->getSelfEvaluation();
240  $values["status"] = $this->node_object->getStatus();
241  $this->form->setValuesByArray($values);
242  }
243 
244  public function updateItem(): void
245  {
246  if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
247  return;
248  }
249 
250  $this->node_object->setTitle($this->form->getInput("title"));
251  $this->node_object->setDescription($this->form->getInput("description"));
252  $this->node_object->setSelfEvaluation((bool) $this->form->getInput("self_eval"));
253  $this->node_object->setStatus((int) $this->form->getInput("status"));
254  $this->node_object->update();
255  }
256 
257  public function listItems(): void
258  {
259  $tpl = $this->tpl;
260  $lng = $this->lng;
261 
262  if ($this->isInUse()) {
263  $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
264  }
265 
266  if ($this->tree_access_manager->hasManageCompetencesPermission()) {
267  self::addCreationButtons();
268  }
269  $this->setTabs("content");
270 
271  $table = new ilSkillCatTableGUI(
272  $this,
273  "listItems",
274  $this->requested_node_id,
276  );
277 
278  $tpl->setContent($table->getHTML());
279  }
280 
281  public static function addCreationButtons(): void
282  {
283  global $DIC;
284 
285  $ilCtrl = $DIC->ctrl();
286  $lng = $DIC->language();
287  $ilToolbar = $DIC->toolbar();
288  $ilUser = $DIC->user();
289  $admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
290 
292 
293  // skill
294  $ilCtrl->setParameterByClass(
295  "ilbasicskillgui",
296  "node_id",
298  );
299  $ilToolbar->addButton(
300  $lng->txt("skmg_create_skll"),
301  $ilCtrl->getLinkTargetByClass("ilbasicskillgui", "create")
302  );
303 
304  // skill category
305  $ilCtrl->setParameterByClass(
306  "ilskillcategorygui",
307  "node_id",
309  );
310  $ilToolbar->addButton(
311  $lng->txt("skmg_create_skill_category"),
312  $ilCtrl->getLinkTargetByClass("ilskillcategorygui", "create")
313  );
314 
315  // skill template reference
316  $ilCtrl->setParameterByClass(
317  "ilskilltemplatereferencegui",
318  "node_id",
320  );
321  $ilToolbar->addButton(
322  $lng->txt("skmg_create_skill_template_reference"),
323  $ilCtrl->getLinkTargetByClass("ilskilltemplatereferencegui", "create")
324  );
325 
326  // skills from clipboard
327  $sep = false;
328  if ($ilUser->clipboardHasObjectsOfType("skll")) {
329  $ilToolbar->addSeparator();
330  $sep = true;
331  $ilToolbar->addButton(
332  $lng->txt("skmg_insert_basic_skill_from_clip"),
333  $ilCtrl->getLinkTargetByClass("ilskillcategorygui", "insertBasicSkillClip")
334  );
335  }
336 
337  // skills from clipboard
338  if ($ilUser->clipboardHasObjectsOfType("scat")) {
339  if (!$sep) {
340  $ilToolbar->addSeparator();
341  $sep = true;
342  }
343  $ilToolbar->addButton(
344  $lng->txt("skmg_insert_skill_category_from_clip"),
345  $ilCtrl->getLinkTargetByClass("ilskillcategorygui", "insertSkillCategoryClip")
346  );
347  }
348 
349  // skills from clipboard
350  if ($ilUser->clipboardHasObjectsOfType("sktr")) {
351  if (!$sep) {
352  $ilToolbar->addSeparator();
353  $sep = true;
354  }
355  $ilToolbar->addButton(
356  $lng->txt("skmg_insert_skill_template_reference_from_clip"),
357  $ilCtrl->getLinkTargetByClass("ilskillcategorygui", "insertTemplateReferenceClip")
358  );
359  }
360 
361  // skill template reference
362  $ilToolbar->addButton(
363  $lng->txt("skmg_import_skills"),
364  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "showImportForm")
365  );
366  }
367 
371  public function redirectToParent(bool $a_tmp_mode = false): void
372  {
373  $ilCtrl = $this->ctrl;
374 
375  $t = ilSkillTreeNode::_lookupType($this->requested_node_id);
376 
377  switch ($t) {
378  case "skrt":
379  $ilCtrl->setParameterByClass("ilskillrootgui", "node_id", $this->requested_node_id);
380  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
381  break;
382  }
383 
384  parent::redirectToParent();
385  }
386 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Skill category GUI class.
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...
addUsageTab(ilTabsGUI $a_tabs)
Help GUI class.
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
ilGlobalTemplateInterface $tpl
static _lookupType(int $a_obj_id)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
setContent(string $a_html)
Sets content for standard template.
Basic GUI class for skill tree nodes.
__construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id=0)
setScreenIdComponent(string $a_comp)
initForm(string $a_mode="edit")
redirectToParent(bool $a_tmp_mode=false)
Redirect to parent (identified by current node_id)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
SkillAdminGUIRequest $admin_gui_request
const POS_LAST_NODE
form( $class_path, string $cmd, string $submit_caption="")
This class represents a text area property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getValues()
Get current values for from.
addStatusInput(ilPropertyFormGUI $a_form)