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