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