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