ILIAS  release_8 Revision v8.23
class.ilSkillTemplateCategoryGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
29 {
30  protected ilCtrl $ctrl;
32  protected ilTabsGUI $tabs;
33  protected ilLanguage $lng;
34  protected ilHelpGUI $help;
35 
36  protected int $tref_id = 0;
37 
38  public function __construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id = 0, int $a_tref_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  $this->tref_id = $a_tref_id;
51 
52  parent::__construct($node_manager, $a_node_id);
53  }
54 
55  public function getType(): string
56  {
57  return "sctp";
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_sctp");
88 
89  // content
90  $ilTabs->addTab(
91  "content",
92  $lng->txt("content"),
93  $ilCtrl->getLinkTarget($this, 'listItems')
94  );
95 
96 
97  // properties
98  if ($this->tref_id == 0) {
99  $ilTabs->addTab(
100  "properties",
101  $lng->txt("settings"),
102  $ilCtrl->getLinkTarget($this, 'editProperties')
103  );
104  }
105 
106  // usage
107  $this->addUsageTab($ilTabs);
108 
109  $parent_node_id = $this->tree_repo->getParentNodeIdForNodeId($this->requested_node_id);
110  $parent_title = ilSkillTreeNode::_lookupTitle($parent_node_id);
111  $parent_type = ilSkillTreeNode::_lookupType($parent_node_id);
112 
113  // back link
114  if ($this->tref_id == 0) {
115  if ($parent_type === "sctp") {
116  $ilCtrl->setParameter(
117  $this,
118  "node_id",
119  $parent_node_id
120  );
121  $ilTabs->setBackTarget(
122  $parent_title,
123  $ilCtrl->getLinkTarget($this, "listItems")
124  );
125  $ilCtrl->setParameter(
126  $this,
127  "node_id",
128  $this->requested_node_id
129  );
130  } else {
131  $ilCtrl->setParameterByClass(
132  "ilskillrootgui",
133  "node_id",
134  $this->skill_tree_node_manager->getRootId()
135  );
136  $ilTabs->setBackTarget(
137  $lng->txt("skmg_skill_templates"),
138  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "listTemplates")
139  );
140  $ilCtrl->setParameterByClass(
141  "ilskillrootgui",
142  "node_id",
143  $this->requested_node_id
144  );
145  }
146  }
147 
148  parent::setTitleIcon();
149  $tpl->setTitle(
150  $lng->txt("skmg_sctp") . ": " . $this->node_object->getTitle()
151  );
152  $this->setSkillNodeDescription();
153 
154  $ilTabs->activateTab($a_tab);
155  }
156 
157  public function initForm(string $a_mode = "edit"): void
158  {
159  $lng = $this->lng;
160  $ilCtrl = $this->ctrl;
161 
162  $this->form = new ilPropertyFormGUI();
163 
164  // title
165  $ti = new ilTextInputGUI($lng->txt("title"), "title");
166  $ti->setMaxLength(200);
167  $ti->setSize(50);
168  $ti->setRequired(true);
169  $this->form->addItem($ti);
170 
171  // description
172  $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
173  $ta->setRows(5);
174  $this->form->addItem($ta);
175 
176  // save and cancel commands
177  if ($this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
178  if ($a_mode == "create") {
179  $this->form->addCommandButton("save", $lng->txt("save"));
180  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
181  $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
182  } else {
183  $this->form->addCommandButton("update", $lng->txt("save"));
184  $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
185  }
186  } else {
187  foreach ($this->form->getItems() as $item) {
188  $item->setDisabled(true);
189  }
190  }
191 
192  $ilCtrl->setParameter($this, "node_id", $this->requested_node_id);
193  $this->form->setFormAction($ilCtrl->getFormAction($this));
194  }
195 
196  public function listItems(): void
197  {
198  $tpl = $this->tpl;
199  $lng = $this->lng;
200 
201  if ($this->isInUse()) {
202  $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
203  }
204 
205  if ($this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
206  if ($this->tref_id == 0) {
207  self::addCreationButtons();
208  }
209  }
210 
211  $this->setTabs("content");
212 
213  $table = new ilSkillCatTableGUI(
214  $this,
215  "listItems",
216  $this->requested_node_id,
218  $this->tref_id
219  );
220 
221  $tpl->setContent($table->getHTML());
222  }
223 
224  public static function addCreationButtons(): void
225  {
226  global $DIC;
227 
228  $ilCtrl = $DIC->ctrl();
229  $lng = $DIC->language();
230  $ilToolbar = $DIC->toolbar();
231  $ilUser = $DIC->user();
232  $admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
233 
235 
236  $ilCtrl->setParameterByClass("ilobjskillmanagementgui", "tmpmode", 1);
237 
238  $ilCtrl->setParameterByClass(
239  "ilbasicskilltemplategui",
240  "node_id",
242  );
243  $ilToolbar->addButton(
244  $lng->txt("skmg_create_skill_template"),
245  $ilCtrl->getLinkTargetByClass("ilbasicskilltemplategui", "create")
246  );
247  $ilCtrl->setParameterByClass(
248  "ilskilltemplatecategorygui",
249  "node_id",
251  );
252  $ilToolbar->addButton(
253  $lng->txt("skmg_create_skill_template_category"),
254  $ilCtrl->getLinkTargetByClass("ilskilltemplatecategorygui", "create")
255  );
256 
257  // skill templates from clipboard
258  $sep = false;
259  if ($ilUser->clipboardHasObjectsOfType("sktp")) {
260  $ilToolbar->addSeparator();
261  $sep = true;
262  $ilToolbar->addButton(
263  $lng->txt("skmg_insert_skill_template_from_clip"),
264  $ilCtrl->getLinkTargetByClass("ilskilltemplatecategorygui", "insertSkillTemplateClip")
265  );
266  }
267 
268  // template categories from clipboard
269  if ($ilUser->clipboardHasObjectsOfType("sctp")) {
270  if (!$sep) {
271  $ilToolbar->addSeparator();
272  $sep = true;
273  }
274  $ilToolbar->addButton(
275  $lng->txt("skmg_insert_template_category_from_clip"),
276  $ilCtrl->getLinkTargetByClass("ilskilltemplatecategorygui", "insertTemplateCategoryClip")
277  );
278  }
279  }
280 
281  public function editProperties(): void
282  {
283  $this->setTabs("properties");
284  parent::editProperties();
285  }
286 
287  public function saveItem(): void
288  {
289  if (!$this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
290  return;
291  }
292 
293  $it = new ilSkillTemplateCategory();
294  $it->setTitle($this->form->getInput("title"));
295  $it->setDescription($this->form->getInput("description"));
296  $it->create();
297  $this->skill_tree_node_manager->putIntoTree($it, $this->requested_node_id, ilTree::POS_LAST_NODE);
298  }
299 
300  public function updateItem(): void
301  {
302  if (!$this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
303  return;
304  }
305 
306  $this->node_object->setTitle($this->form->getInput("title"));
307  $this->node_object->setDescription($this->form->getInput("description"));
308  $this->node_object->setOrderNr((int) $this->form->getInput("order_nr"));
309  $this->node_object->setSelfEvaluation((bool) $this->form->getInput("self_eval"));
310  $this->node_object->update();
311  }
312 
313  public function afterSave(): void
314  {
315  $this->redirectToParent(true);
316  }
317 
318  public function showUsage(): void
319  {
320  $tpl = $this->tpl;
321 
322  // (a) referenced skill template category in main tree
323  if ($this->tref_id > 0) {
324  parent::showUsage();
325  return;
326  }
327 
328  // (b) skill template category in templates view
329 
330  $this->setTabs("usage");
331 
332  $usage_info = new ilSkillUsage();
333  $usages = $usage_info->getAllUsagesOfTemplate($this->requested_node_id);
334 
335  $html = "";
336  foreach ($usages as $k => $usage) {
337  $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
338  $html .= $tab->getHTML() . "<br/><br/>";
339  }
340 
341  $tpl->setContent($html);
342  }
343 
344  public function redirectToParent(bool $a_tmp_mode = false): void
345  {
346  parent::redirectToParent(true);
347  }
348 }
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Help GUI class.
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static _lookupType(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
Basic GUI class for skill tree nodes.
setScreenIdComponent(string $a_comp)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
TableGUI class for skill usages.
form( $class_path, string $cmd)
SkillAdminGUIRequest $admin_gui_request
Skill template category GUI class.
const POS_LAST_NODE
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
$ilUser
Definition: imgupload.php:34
Skill usage.
__construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id=0, int $a_tref_id=0)