ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilBasicSkillTemplateGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
31 {
32  protected ilCtrl $ctrl;
33  protected ilLanguage $lng;
34  protected ilTabsGUI $tabs;
36  protected ilHelpGUI $help;
38 
39  public function __construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id = 0, int $a_tref_id = 0)
40  {
41  global $DIC;
42 
43  $this->ctrl = $DIC->ctrl();
44  $this->lng = $DIC->language();
45  $this->tabs = $DIC->tabs();
46  $this->tpl = $DIC["tpl"];
47  $this->help = $DIC["ilHelp"];
48  $this->toolbar = $DIC->toolbar();
49  $ilCtrl = $DIC->ctrl();
50 
51  $this->tref_id = $a_tref_id;
52 
53  $ilCtrl->saveParameter($this, array("node_id", "level_id"));
54 
55  parent::__construct($node_manager, $a_node_id);
56  }
57 
58  public function getType(): string
59  {
60  return "sktp";
61  }
62 
63  public function initForm(string $a_mode = "edit"): void
64  {
65  $lng = $this->lng;
66  $ilCtrl = $this->ctrl;
67 
68  $this->form = new ilPropertyFormGUI();
69 
70  // title
71  $ti = new ilTextInputGUI($lng->txt("title"), "title");
72  $ti->setMaxLength(200);
73  $ti->setSize(50);
74  $ti->setRequired(true);
75  $this->form->addItem($ti);
76 
77  // description
78  $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
79  $ta->setRows(5);
80  $this->form->addItem($ta);
81 
82  // save and cancel commands
83  if ($this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
84  if ($a_mode == "create") {
85  $this->form->addCommandButton("save", $lng->txt("save"));
86  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
87  $this->form->setTitle($lng->txt("skmg_create_skll"));
88  } else {
89  $this->form->addCommandButton("update", $lng->txt("save"));
90  $this->form->setTitle($lng->txt("skmg_edit_skll"));
91  }
92  } else {
93  foreach ($this->form->getItems() as $item) {
94  $item->setDisabled(true);
95  }
96  }
97 
98  $ilCtrl->setParameter($this, "node_id", $this->requested_node_id);
99  $this->form->setFormAction($ilCtrl->getFormAction($this));
100  }
101 
102  public function setLevelHead(): void
103  {
104  $ilTabs = $this->tabs;
105  $ilCtrl = $this->ctrl;
106  $tpl = $this->tpl;
107  $lng = $this->lng;
108  $ilHelp = $this->help;
109 
110  // tabs
111  $ilTabs->clearTargets();
112  $ilHelp->setScreenIdComponent("skmg_lev");
113  $ilTabs->setBackTarget(
114  $lng->txt("skmg_skill_levels"),
115  $ilCtrl->getLinkTarget($this, "edit")
116  );
117 
118  if ($this->requested_level_id > 0) {
119  if ($this->tref_id == 0) {
120  $ilTabs->addTab(
121  "level_settings",
122  $lng->txt("settings"),
123  $ilCtrl->getLinkTarget($this, "editLevel")
124  );
125  } else {
126  $ilTabs->addTab(
127  "level_resources",
128  $lng->txt("skmg_resources"),
129  $ilCtrl->getLinkTarget($this, "showLevelResources")
130  );
131  }
132  }
133 
134  // title
135  if ($this->requested_level_id > 0) {
136  $tpl->setTitle($lng->txt("skmg_skill_level") . ": " .
137  ilBasicSkill::lookupLevelTitle($this->requested_level_id));
138  } else {
139  $tpl->setTitle($lng->txt("skmg_skill_level"));
140  }
141 
142  $desc = $this->skill_tree_node_manager->getWrittenPath($this->node_object->getId());
143  $tpl->setDescription($desc);
144 
145  $tpl->setTitleIcon(
147  0,
148  "sktp",
149  "",
150  0
151  )
152  );
153  }
154 
155  public function setTabs(string $a_tab = "levels"): void
156  {
157  $ilTabs = $this->tabs;
158  $ilCtrl = $this->ctrl;
159  $tpl = $this->tpl;
160  $lng = $this->lng;
161  $ilHelp = $this->help;
162 
163  $ilTabs->clearTargets();
164  $ilHelp->setScreenIdComponent("skmg_sktp");
165 
166  $parent_node_id = $this->tree_repo->getParentNodeIdForNodeId($this->requested_node_id);
167  $parent_title = ilSkillTreeNode::_lookupTitle($parent_node_id);
168  $parent_type = ilSkillTreeNode::_lookupType($parent_node_id);
169 
170  if ($this->tref_id == 0) {
171  if ($parent_type === "sctp") {
172  $ilCtrl->setParameterByClass(
173  "ilskilltemplatecategorygui",
174  "node_id",
175  $parent_node_id
176  );
177  $ilTabs->setBackTarget(
178  $parent_title,
179  $ilCtrl->getLinkTargetByClass("ilskilltemplatecategorygui", "listItems")
180  );
181  $ilCtrl->setParameterByClass(
182  "ilskilltemplatecategorygui",
183  "node_id",
184  ""
185  );
186  } else {
187  $ilTabs->setBackTarget(
188  $lng->txt("skmg_skill_templates"),
189  $ilCtrl->getLinkTargetByClass("ilobjskilltreegui", "editSkillTemplates")
190  );
191  }
192  }
193 
194  if (is_object($this->node_object)) {
195  if ($this->tref_id == 0) {
196  $tpl->setTitle($lng->txt("skmg_skill_template") . ": " .
197  $this->node_object->getTitle());
198  } else {
199  $tpl->setTitle(
200  $this->node_object->getTitle()
201  );
202  }
203 
204  // levels
205  $ilTabs->addTab(
206  "levels",
207  $lng->txt("skmg_skill_levels"),
208  $ilCtrl->getLinkTarget($this, 'edit')
209  );
210 
211  // properties
212  if ($this->tref_id == 0) {
213  $ilTabs->addTab(
214  "properties",
215  $lng->txt("settings"),
216  $ilCtrl->getLinkTarget($this, 'editProperties')
217  );
218  }
219 
220  // if ($this->tref_id > 0)
221  // {
222  // usage
223  $this->addUsageTab($ilTabs);
224  // }
225 
226  // assigned objects
227  $this->addObjectsTab($ilTabs);
228 
229  $ilTabs->activateTab($a_tab);
230 
231  parent::setTitleIcon();
232 
233  $this->setSkillNodeDescription();
234  } else {
235  $tpl->setTitle($lng->txt("skmg_skill"));
236  $tpl->setDescription("");
237  }
238  }
239 
240  public function saveItem(): void
241  {
242  if (!$this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
243  return;
244  }
245 
246  $it = new ilBasicSkillTemplate();
247  $it->setTitle($this->form->getInput("title"));
248  $it->setDescription($this->form->getInput("description"));
249  $it->create();
250  $this->skill_tree_node_manager->putIntoTree($it, $this->requested_node_id, ilTree::POS_LAST_NODE);
251  $this->node_object = $it;
252  }
253 
254  public function afterSave(): void
255  {
256  $ilCtrl = $this->ctrl;
257 
258  if (!$this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
259  return;
260  }
261 
262  $ilCtrl->setParameterByClass(
263  "ilbasicskilltemplategui",
264  "node_id",
265  $this->node_object->getId()
266  );
267  $ilCtrl->redirectByClass("ilbasicskilltemplategui", "edit");
268  }
269 
270  public function edit(): void
271  {
272  $tpl = $this->tpl;
273  $ilToolbar = $this->toolbar;
274  $lng = $this->lng;
275  $ilCtrl = $this->ctrl;
276 
277  $this->setTabs("levels");
278 
279  if ($this->isInUse()) {
280  $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
281  } elseif ($this->tree_access_manager->hasManageCompetenceTemplatesPermission()) {
282  if ($this->tref_id == 0) {
283  $ilToolbar->addButton(
284  $lng->txt("skmg_add_level"),
285  $ilCtrl->getLinkTarget($this, "addLevel")
286  );
287  }
288  }
289 
290  $table = new ilSkillLevelTableGUI(
291  $this->requested_node_id,
292  $this,
293  "edit",
294  $this->tref_id,
295  $this->isInUse(),
296  $this->tree_access_manager->hasManageCompetenceTemplatesPermission()
297  );
298  $tpl->setContent($table->getHTML());
299  }
300 
301  public function showUsage(): void
302  {
303  $tpl = $this->tpl;
304 
305 
306  // (a) referenced skill template in main tree
307  if ($this->tref_id > 0) {
308  parent::showUsage();
309  return;
310  }
311 
312  // (b) skill template in templates view
313 
314  $this->setTabs("usage");
315 
316  $usages = $this->usage_manager->getAllUsagesOfTemplate($this->base_skill_id);
317 
318  $html = "";
319  foreach ($usages as $k => $usage) {
320  $usages_ui = $this->skill_ui_service->getUsagesUI($k, $usage);
321  $html .= $usages_ui->render() . "<br/><br/>";
322  }
323 
324  $tpl->setContent($html);
325  }
326 
327  public function showObjects(): void
328  {
329  $tpl = $this->tpl;
330 
331  // (a) referenced skill template in main tree
332  if ($this->tref_id > 0) {
333  parent::showObjects();
334  return;
335  }
336 
337  // (b) skill template in templates view
338 
339  $this->setTabs("objects");
340 
341  $objects = $this->usage_manager->getAssignedObjectsForSkillTemplate($this->base_skill_id);
342 
343  $table = $this->table_manager->getAssignedObjectsTable(
344  $this,
345  $objects,
346  $this->base_skill_id
347  )->getComponent();
348 
349  $tpl->setContent($this->ui_ren->render($table));
350  }
351 
352  public function redirectToParent(bool $a_tmp_mode = false): void
353  {
354  $ilCtrl = $this->ctrl;
355 
356  $ilCtrl->setParameterByClass("ilskillrootgui", "node_id", $this->requested_node_id);
357  $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
358  }
359 }
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)
setParameterByClass(string $a_class, string $a_parameter, $a_value)
static lookupLevelTitle(int $a_id)
static _lookupType(int $a_obj_id)
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id=0, int $a_tref_id=0)
setContent(string $a_html)
Sets content for standard template.
setScreenIdComponent(string $a_comp)
addObjectsTab(ilTabsGUI $a_tabs)
global $DIC
Definition: shib_login.php:25
static getIconPath(int $a_obj_id, string $a_type, string $a_size="", int $a_status=0)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
const POS_LAST_NODE
form( $class_path, string $cmd, string $submit_caption="")
__construct(Container $dic, ilPlugin $plugin)
setDescription(string $a_descr)
Sets description below title in standard template.
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...
Basic skill GUI class.
redirectToParent(bool $a_tmp_mode=false)
Basic skill template GUI class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...