ILIAS  release_8 Revision v8.23
class.ilPCSkillsGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  protected ilObjUser $user;
27 
28  public function __construct(
29  ilPageObject $a_pg_obj,
30  ?ilPageContent $a_content_obj,
31  string $a_hier_id,
32  string $a_pc_id = ""
33  ) {
34  global $DIC;
35 
36  $this->tpl = $DIC["tpl"];
37  $this->ctrl = $DIC->ctrl();
38  $this->user = $DIC->user();
39  $this->lng = $DIC->language();
40  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
41  }
42 
43  public function executeCommand(): void
44  {
45  // get next class that processes or forwards current command
46  $next_class = $this->ctrl->getNextClass($this);
47 
48  // get current command
49  $cmd = $this->ctrl->getCmd();
50 
51  switch ($next_class) {
52  default:
53  $this->$cmd();
54  break;
55  }
56  }
57 
58  public function insert(ilPropertyFormGUI $a_form = null): void
59  {
60  $tpl = $this->tpl;
61 
62  $this->displayValidationError();
63 
64  // template mode: get skills from global skill tree
65  if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
66  $exp = new ilPersonalSkillExplorerGUI($this, "insert", $this, "create", "skill_id");
67  if (!$exp->handleCommand()) {
68  $tpl->setContent($exp->getHTML());
69  }
70  }
71  // editor mode: use personal skills
72  else {
73  if (!$a_form) {
74  $a_form = $this->initForm(true);
75  }
76  $tpl->setContent($a_form->getHTML());
77  }
78  }
79 
80  public function edit(ilPropertyFormGUI $a_form = null): void
81  {
82  $tpl = $this->tpl;
83 
84  $this->displayValidationError();
85 
86  // template mode: get skills from global skill tree
87  if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
88  $exp = new ilPersonalSkillExplorerGUI($this, "edit", $this, "update", "skill_id");
89  if (!$exp->handleCommand()) {
90  $tpl->setContent($exp->getHTML());
91  }
92  }
93  // editor mode: use personal skills
94  else {
95  if (!$a_form) {
96  $a_form = $this->initForm();
97  }
98  $tpl->setContent($a_form->getHTML());
99  }
100  }
101 
105  protected function initForm(
106  bool $a_insert = false
107  ): ilPropertyFormGUI {
108  $ilCtrl = $this->ctrl;
110 
111  $form = new ilPropertyFormGUI();
112  $form->setFormAction($ilCtrl->getFormAction($this));
113  if ($a_insert) {
114  $form->setTitle($this->lng->txt("cont_insert_skills"));
115  } else {
116  $form->setTitle($this->lng->txt("cont_update_skills"));
117  }
118 
119  $options = array();
120 
122  if ($skills) {
123  foreach ($skills as $skill) {
124  $options[$skill["skill_node_id"]] = $skill["title"];
125  }
126  asort($options);
127  } else {
128  $this->tpl->setOnScreenMessage('failure', "cont_no_skills");
129  }
130  $obj = new ilSelectInputGUI($this->lng->txt("cont_pc_skills"), "skill_id");
131  $obj->setRequired(true);
132  $obj->setOptions($options);
133  $form->addItem($obj);
134 
135  if ($a_insert) {
136  $form->addCommandButton("create_skill", $this->lng->txt("select"));
137  $form->addCommandButton("cancelCreate", $this->lng->txt("cancel"));
138  } else {
139  $obj->setValue($this->content_obj->getSkillId());
140  $form->addCommandButton("update", $this->lng->txt("select"));
141  $form->addCommandButton("cancelUpdate", $this->lng->txt("cancel"));
142  }
143 
144  return $form;
145  }
146 
147  public function create(): void
148  {
149  $valid = false;
150  $data = null;
151  $form = null;
152 
153  // template mode: get skills from global skill tree
154  if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
155  $data = $this->request->getInt("skill_id");
156  $valid = true;
157  }
158  // editor mode: use personal skills
159  else {
160  $form = $this->initForm(true);
161  if ($form->checkInput()) {
162  $data = $form->getInput("skill_id");
163  $valid = true;
164  }
165  }
166 
167  if ($valid) {
168  $this->content_obj = new ilPCSkills($this->getPage());
169  $this->content_obj->create($this->pg_obj, $this->hier_id, $this->pc_id);
170  $this->content_obj->setData($data);
171  $this->updated = $this->pg_obj->update();
172  if ($this->updated === true) {
173  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
174  }
175  }
176 
177  $form->setValuesByPost();
178  $this->insert($form);
179  }
180 
181  public function update(): void
182  {
183  $valid = false;
184  $data = null;
185  $form = null;
186 
187  // template mode: get skills from global skill tree
188  if ($this->getPageConfig()->getEnablePCType("PlaceHolder")) {
189  $data = $this->request->getInt("skill_id");
190  $valid = true;
191  }
192  // editor mode: use personal skills
193  else {
194  $form = $this->initForm();
195  if ($form->checkInput()) {
196  $data = $form->getInput("skill_id");
197  $valid = true;
198  }
199  }
200 
201  if ($valid) {
202  $this->content_obj->setData($data);
203  $this->updated = $this->pg_obj->update();
204  if ($this->updated === true) {
205  $this->ctrl->returnToParent($this, "jump" . $this->hier_id);
206  }
207  }
208 
209  $this->pg_obj->addHierIDs();
210  $form->setValuesByPost();
211  $this->edit($form);
212  }
213 }
edit(ilPropertyFormGUI $a_form=null)
initForm(bool $a_insert=false)
Init skills form.
$valid
Explorer for selecting a personal skill.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_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...
global $DIC
Definition: feed.php:28
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
ilGlobalTemplateInterface $tpl
static getSelectedUserSkills(int $a_user_id)
insert(ilPropertyFormGUI $a_form=null)
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34