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