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