ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSkillTemplateReferenceGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
30 {
31  public function __construct(Tree\SkillTreeNodeManager $node_manager, int $a_tref_id = 0)
32  {
33  global $DIC;
34 
35  $this->ctrl = $DIC->ctrl();
36  $this->tpl = $DIC["tpl"];
37  $this->tabs = $DIC->tabs();
38  $this->lng = $DIC->language();
39  $this->help = $DIC["ilHelp"];
40  $ilCtrl = $DIC->ctrl();
41 
42  $ilCtrl->saveParameter($this, "node_id");
43  $ilCtrl->saveParameter($this, "tref_id");
44 
45  parent::__construct($node_manager, $a_tref_id);
46 
47  $this->tref_id = $a_tref_id;
48  if (is_object($this->node_object)) {
49  $this->base_skill_id = $this->node_object->getSkillTemplateId();
50  }
51  }
52 
53  public function getType(): string
54  {
55  return "sktr";
56  }
57 
58  public function executeCommand(): void
59  {
60  $ilCtrl = $this->ctrl;
61  $tpl = $this->tpl;
62  $ilTabs = $this->tabs;
63 
64  //$tpl->getStandardTemplate();
65 
66  $next_class = $ilCtrl->getNextClass($this);
67  $cmd = $ilCtrl->getCmd();
68 
69  switch ($next_class) {
70  default:
71  $ret = $this->$cmd();
72  break;
73  }
74  }
75 
76  public function setTabs($a_tab = "levels"): void
77  {
78  $ilTabs = $this->tabs;
79  $ilCtrl = $this->ctrl;
80  $tpl = $this->tpl;
81  $lng = $this->lng;
82  $ilHelp = $this->help;
83 
84  $ilTabs->clearTargets();
85  $ilHelp->setScreenIdComponent("skmg_sktr");
86 
87  if (is_object($this->node_object)) {
88  $sk_id = $this->node_object->getSkillTemplateId();
89  $obj_type = ilSkillTreeNode::_lookupType($sk_id);
90 
91  if ($obj_type == "sctp") {
92  // content
93  $ilTabs->addTab(
94  "content",
95  $lng->txt("content"),
96  $ilCtrl->getLinkTarget($this, 'listItems')
97  );
98  } else {
99  // content
100  $ilTabs->addTab(
101  "content",
102  $lng->txt("skmg_skill_levels"),
103  $ilCtrl->getLinkTarget($this, 'listItems')
104  );
105  }
106 
107  // properties
108  $ilTabs->addTab(
109  "properties",
110  $lng->txt("settings"),
111  $ilCtrl->getLinkTarget($this, 'editProperties')
112  );
113 
114  // usage
115  $this->addUsageTab($ilTabs);
116 
117  // assigned objects
118  if ($obj_type != "sctp") {
119  $this->addObjectsTab($ilTabs);
120  }
121 
122  $ilCtrl->setParameterByClass(
123  "ilskillrootgui",
124  "node_id",
125  $this->skill_tree_node_manager->getRootId()
126  );
127  $ilTabs->setBackTarget(
128  $lng->txt("skmg_skills"),
129  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "listSkills")
130  );
131  $ilCtrl->setParameterByClass(
132  "ilskillrootgui",
133  "node_id",
134  $this->requested_node_id
135  );
136 
137  $tid = ilSkillTemplateReference::_lookupTemplateId($this->node_object->getId());
138  $add = " (" . ilSkillTreeNode::_lookupTitle($tid) . ")";
139 
140  parent::setTitleIcon();
141  $tpl->setTitle(
142  $lng->txt("skmg_sktr") . ": " . $this->node_object->getTitle() . $add
143  );
144  $this->setSkillNodeDescription();
145 
146  $ilTabs->activateTab($a_tab);
147  }
148  }
149 
150  public function insert(): void
151  {
152  $ilCtrl = $this->ctrl;
153  $tpl = $this->tpl;
154 
155  $ilCtrl->saveParameter($this, "parent_id");
156  $ilCtrl->saveParameter($this, "target");
157  $this->initForm("create");
158  $tpl->setContent($this->form->getHTML());
159  }
160 
161  public function editProperties(): void
162  {
163  $tpl = $this->tpl;
164 
165  $this->setTabs("properties");
166 
167  $this->initForm();
168  $this->getValues();
169  $tpl->setContent($this->form->getHTML());
170  }
171 
172  public function initForm(string $a_mode = "edit"): void
173  {
174  $lng = $this->lng;
175  $ilCtrl = $this->ctrl;
176 
177  //TODO: Refactoring to UI Form when non-editable input is available
178 
179  $this->form = new ilPropertyFormGUI();
180 
181  // select skill template
182  $tmplts = $this->skill_tree_node_manager->getTopTemplates();
183 
184  // title
185  $ti = new ilTextInputGUI($lng->txt("title"), "title");
186  $ti->setRequired(true);
187  $this->form->addItem($ti);
188 
189  // description
190  if ($a_mode == "edit") {
191  $desc = ilSkillTreeNode::_lookupDescription($this->node_object->getSkillTemplateId());
192  if (!empty($desc)) {
193  $ne = new ilNonEditableValueGUI($lng->txt("description"), "template_description");
194  $ne->setValue($desc);
195  $ne->setInfo($lng->txt("skmg_description_info"));
196  $this->form->addItem($ne);
197  }
198  }
199 
200  // template
201  $options = array(
202  "" => $lng->txt("please_select"),
203  );
204  foreach ($tmplts as $tmplt) {
205  $options[$tmplt["child"]] = $tmplt["title"];
206  }
207  if ($a_mode != "edit") {
208  $si = new ilSelectInputGUI($lng->txt("skmg_skill_template"), "skill_template_id");
209  $si->setOptions($options);
210  $si->setRequired(true);
211  $this->form->addItem($si);
212  } else {
213  $ne = new ilNonEditableValueGUI($lng->txt("skmg_skill_template"), "");
214  $ne->setValue($options[$this->node_object->getSkillTemplateId()] ?? "");
215  $this->form->addItem($ne);
216  }
217 
218  // status
219  $this->addStatusInput($this->form);
220 
221  // selectable
222  $cb = new ilCheckboxInputGUI($lng->txt("skmg_selectable"), "selectable");
223  $cb->setInfo($lng->txt("skmg_selectable_info"));
224  $this->form->addItem($cb);
225 
226  if ($this->tree_access_manager->hasManageCompetencesPermission()) {
227  if ($a_mode == "create") {
228  $this->form->addCommandButton("save", $lng->txt("save"));
229  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
230  $this->form->setTitle($lng->txt("skmg_new_sktr"));
231  } else {
232  $this->form->addCommandButton("updateSkillTemplateReference", $lng->txt("save"));
233  $this->form->setTitle($lng->txt("skmg_edit_sktr"));
234  }
235  } else {
236  foreach ($this->form->getItems() as $item) {
237  $item->setDisabled(true);
238  }
239  }
240 
241  $this->form->setFormAction($ilCtrl->getFormAction($this));
242  }
243 
244  public function getValues(): void
245  {
246  $values = [];
247  $values["skill_template_id"] = $this->node_object->getSkillTemplateId();
248  $values["title"] = $this->node_object->getTitle();
249  $values["description"] = $this->node_object->getDescription();
250  $values["selectable"] = $this->node_object->getSelfEvaluation();
251  $values["status"] = $this->node_object->getStatus();
252  $this->form->setValuesByArray($values);
253  }
254 
255  public function saveItem(): void
256  {
257  if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
258  return;
259  }
260 
261  $sktr = new ilSkillTemplateReference();
262  $sktr->setTitle($this->form->getInput("title"));
263  $sktr->setDescription($this->form->getInput("description"));
264  $sktr->setSkillTemplateId($this->form->getInput("skill_template_id"));
265  $sktr->setSelfEvaluation((bool) $this->form->getInput("selectable"));
266  $sktr->setStatus($this->form->getInput("status"));
267  $sktr->create();
268  $this->skill_tree_node_manager->putIntoTree($sktr, $this->requested_node_id, ilTree::POS_LAST_NODE);
269  $this->node_object = $sktr;
270  }
271 
272  public function afterSave(): void
273  {
274  $ilCtrl = $this->ctrl;
275 
276  if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
277  return;
278  }
279 
280  $ilCtrl->setParameterByClass(
281  "ilskilltemplatereferencegui",
282  "tref_id",
283  $this->node_object->getId()
284  );
285  $ilCtrl->setParameterByClass(
286  "ilskilltemplatereferencegui",
287  "node_id",
288  $this->node_object->getSkillTemplateId()
289  );
290  $ilCtrl->redirectByClass("ilskilltemplatereferencegui", "listItems");
291  }
292 
293  public function updateSkillTemplateReference(): void
294  {
295  $lng = $this->lng;
296  $ilCtrl = $this->ctrl;
297  $tpl = $this->tpl;
298 
299  if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
300  return;
301  }
302 
303  $this->initForm("edit");
304  if ($this->form->checkInput()) {
305  // perform update
306  $this->node_object->setTitle($this->form->getInput("title"));
307  $this->node_object->setDescription($this->form->getInput("description"));
308  $this->node_object->setSelfEvaluation((bool) $this->form->getInput("selectable"));
309  $this->node_object->setStatus($this->form->getInput("status"));
310  $this->node_object->update();
311 
312  $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
313  $ilCtrl->redirect($this, "editProperties");
314  }
315 
316  $this->form->setValuesByPost();
317  $tpl->setContent($this->form->getHTML());
318  }
319 
320  public function listItems(): void
321  {
322  $tpl = $this->tpl;
323  $lng = $this->lng;
324 
325  if ($this->isInUse()) {
326  $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
327  }
328 
329  $this->setTabs("content");
330 
331  $sk_id = $this->node_object->getSkillTemplateId();
332  $obj_type = ilSkillTreeNode::_lookupType($sk_id);
333 
334  if ($obj_type == "sctp") {
335  $table = new ilSkillCatTableGUI(
336  $this,
337  "listItems",
338  (int) $sk_id,
340  $this->node_object->getId()
341  );
342  $tpl->setContent($table->getHTML());
343  } elseif ($obj_type == "sktp") {
344  $table = new ilSkillLevelTableGUI(
345  (int) $sk_id,
346  $this,
347  "edit",
348  $this->node_object->getId(),
349  false,
350  $this->tree_access_manager->hasManageCompetencesPermission()
351  );
352  $tpl->setContent($table->getHTML());
353  }
354  }
355 
356  public function showObjects(): void
357  {
358  $tpl = $this->tpl;
359 
360  $this->setTabs("objects");
361 
362  $usage_info = new ilSkillUsage();
363  $objects = $usage_info->getAssignedObjectsForSkill($this->base_skill_id, $this->tref_id);
364 
365  $tab = new ilSkillAssignedObjectsTableGUI($this, "showObjects", $objects);
366 
367  $tpl->setContent($tab->getHTML());
368  }
369 
370  public function redirectToParent(bool $a_tmp_mode = false): void
371  {
372  $ilCtrl = $this->ctrl;
373 
374  $ilCtrl->setParameterByClass("ilskillrootgui", "node_id", $this->requested_node_id);
375  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
376  }
377 }
__construct(Tree\SkillTreeNodeManager $node_manager, int $a_tref_id=0)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addUsageTab(ilTabsGUI $a_tabs)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
This class represents a checkbox property in a property form.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
static _lookupType(int $a_obj_id)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupDescription(int $a_obj_id)
global $DIC
Definition: feed.php:28
setContent(string $a_html)
Sets content for standard template.
setScreenIdComponent(string $a_comp)
addObjectsTab(ilTabsGUI $a_tabs)
Skill template reference GUI class.
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
form( $class_path, string $cmd)
const POS_LAST_NODE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
Skill usage.
Basic skill template GUI class.
addStatusInput(ilPropertyFormGUI $a_form)