ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilContSkillAdminGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
16 protected $ctrl;
17
21 protected $tabs;
22
26 protected $lng;
27
31 protected $tpl;
32
36 protected $container_gui;
37
41 protected $container;
42
47
51 protected $toolbar;
52
56 protected $access;
57
63 public function __construct($a_container_gui)
64 {
65 global $DIC;
66
67 $this->ctrl = $DIC->ctrl();
68 $this->tabs = $DIC->tabs();
69 $this->lng = $DIC->language();
70 $this->tpl = $DIC["tpl"];
71 $this->toolbar = $DIC->toolbar();
72 $this->access = $DIC->access();
73
74 $this->container_gui = $a_container_gui;
75 $this->container = $a_container_gui->object;
76 $this->ref_id = $this->container->getRefId();
77
78 include_once("./Services/Skill/classes/class.ilSkillTree.php");
79 $this->skill_tree = new ilSkillTree();
80
81 include_once("./Services/Container/Skills/classes/class.ilContainerSkills.php");
82 $this->container_skills = new ilContainerSkills($this->container->getId());
83
84 $this->user_id = (int) $_GET["usr_id"];
85 }
86
90 public function executeCommand()
91 {
92 $next_class = $this->ctrl->getNextClass($this);
93 $cmd = $this->ctrl->getCmd("listMembers");
94
95 switch ($next_class) {
96 default:
97 if (
98 ($this->access->checkAccess("write", "", $this->ref_id) &&
99 in_array($cmd, array("listCompetences", "settings", "saveSettings", "selectSkill",
100 "saveSelectedSkill", "confirmRemoveSelectedSkill", "removeSelectedSkill")))
101 ||
102 ($this->access->checkAccess("grade", "", $this->ref_id) &&
103 in_array($cmd, array("listMembers", "assignCompetences",
104 "saveCompetenceAssignment", "publishAssignments", "deassignCompetencesConfirm", "deassignCompetences")))
105 ) {
106 $this->$cmd();
107 }
108 }
109 }
110
112
116 public function listMembers()
117 {
120
121 $tabs->activateSubTab("members");
122
123 // table
124 include_once("./Services/Container/Skills/classes/class.ilContSkillMemberTableGUI.php");
125 $tab = new ilContSkillMemberTableGUI($this, "listMembers", $this->container_skills);
126
127 $tpl->setContent($tab->getHTML());
128 }
129
133 public function assignCompetences()
134 {
138
139 $ctrl->saveParameter($this, "usr_id");
140 $tabs->activateSubTab("members");
141
142 $form = $this->initCompetenceAssignmentForm();
143 $tpl->setContent($form->getHTML());
144 }
145
150 {
151 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
152 $form = new ilPropertyFormGUI();
153
154 include_once("./Services/Container/Skills/classes/class.ilContainerMemberSkills.php");
155 $mem_skills = new ilContainerMemberSkills($this->container_skills->getId(), $this->user_id);
156 $mem_levels = $mem_skills->getSkillLevels();
157
158 // user name
159 $name = ilObjUser::_lookupName($this->user_id);
160 $ne = new ilNonEditableValueGUI($this->lng->txt("obj_user"), "");
161 $ne->setValue($name["lastname"] . ", " . $name["firstname"] . " [" . $name["login"] . "]");
162 $form->addItem($ne);
163
164 foreach ($this->container_skills->getOrderedSkills() as $sk) {
165 $skill = new ilBasicSkill($sk["skill_id"]);
166
167 // skill level options
168 $options = array(
169 "-1" => $this->lng->txt("cont_skill_do_not_set"),
170 );
171 foreach ($skill->getLevelData() as $l) {
172 $options[$l["id"]] = $l["title"];
173 }
174 $si = new ilSelectInputGUI(ilBasicSkill::_lookupTitle($sk["skill_id"], $sk["tref_id"]), "skill_" . $sk["skill_id"] . "_" . $sk["tref_id"]);
175 $si->setOptions($options);
176 $si->setInfo($this->getPathString($sk["skill_id"], $sk["tref_id"]));
177 if (isset($mem_levels[$sk["skill_id"] . ":" . $sk["tref_id"]])) {
178 $si->setValue($mem_levels[$sk["skill_id"] . ":" . $sk["tref_id"]]);
179 }
180 $form->addItem($si);
181 }
182
183 // save and cancel commands
184 $form->addCommandButton("saveCompetenceAssignment", $this->lng->txt("save"));
185 $form->addCommandButton("listMembers", $this->lng->txt("cancel"));
186
187 $form->setTitle($this->lng->txt("cont_assign_skills"));
188 $form->setFormAction($this->ctrl->getFormAction($this));
189
190 return $form;
191 }
192
198 public function getPathString($a_skill_id, $a_tref_id = 0)
199 {
200 $skill_tree = $this->skill_tree;
201
202 $path = $skill_tree->getSkillTreePath($a_skill_id, $a_tref_id);
203 $titles = array();
204 foreach ($path as $v) {
205 if ($v["type"] != "skrt" && !($v["skill_id"] == $a_skill_id && $v["tref_id"] == $a_tref_id)) {
206 $titles[] = $v["title"];
207 }
208 }
209
210 return implode(" > ", $titles);
211 }
212
218 public function saveCompetenceAssignment()
219 {
222
223 $form = $this->initCompetenceAssignmentForm();
224 $form->checkInput();
225
226 $levels = array();
227 foreach ($this->container_skills->getSkills() as $sk) {
228 $l = $form->getInput("skill_" . $sk["skill_id"] . "_" . $sk["tref_id"]);
229 if ($l != -1) {
230 $levels[$sk["skill_id"] . ":" . $sk["tref_id"]] = $l;
231 }
232 }
233
234 include_once("./Services/Container/Skills/classes/class.ilContainerMemberSkills.php");
235 $mem_skills = new ilContainerMemberSkills($this->container_skills->getId(), $this->user_id);
236 $mem_skills->saveLevelForSkills($levels);
237
238 if (!ilContainer::_lookupContainerSetting($this->container->getId(), "cont_skill_publish", 0)) {
239 $mem_skills->publish($this->container->getRefId());
240 }
241
242 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
243 $ctrl->redirect($this, "listMembers");
244 }
245
249 public function publishAssignments()
250 {
253
254 $user_ids = $_POST["usr_id"];
255 if (!is_array($_POST["usr_id"]) && $_GET["usr_id"] > 0) {
256 $user_ids[] = $_GET["usr_id"];
257 }
258
259 include_once("./Services/Container/Skills/classes/class.ilContainerMemberSkills.php");
260 $not_changed = array();
261 foreach ($user_ids as $user_id) {
262 $mem_skills = new ilContainerMemberSkills($this->container_skills->getId(), $user_id);
263 if (!$mem_skills->publish($this->container->getRefId())) {
264 $not_changed[] = $user_id;
265 }
266 }
267
268 if (count($not_changed) == 0) {
269 ilUtil::sendSuccess($lng->txt("cont_skll_published"), true);
270 } else {
271 $names = array_map(function ($id) {
272 return ilUserUtil::getNamePresentation($id, false, false, "", true);
273 }, $not_changed);
274 ilUtil::sendInfo($lng->txt("cont_skll_published_some_not") . " (" . implode("; ", $names) . ")", true);
275 }
276
277
278 $ctrl->redirect($this, "listMembers");
279 }
280
285 {
290
291 $tabs->activateSubTab("members");
292
293 $user_ids = $_POST["usr_id"];
294 if (!is_array($_POST["usr_id"]) && $_GET["usr_id"] > 0) {
295 $user_ids[] = $_GET["usr_id"];
296 }
297
298 if (!is_array($user_ids) || count($user_ids) == 0) {
299 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
300 $ctrl->redirect($this, "listMembers");
301 } else {
302 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
303 $cgui = new ilConfirmationGUI();
304 $cgui->setFormAction($ctrl->getFormAction($this));
305 $cgui->setHeaderText($lng->txt("cont_really_deassign_skills"));
306 $cgui->setCancel($lng->txt("cancel"), "listMembers");
307 $cgui->setConfirm($lng->txt("cont_deassign_competence"), "deassignCompetences");
308
309 foreach ($user_ids as $i) {
310 $name = ilUserUtil::getNamePresentation($i, false, false, "", true);
311 $cgui->addItem("usr_id[]", $i, $name);
312 }
313
314 $tpl->setContent($cgui->getHTML());
315 }
316 }
317
321 public function deassignCompetences()
322 {
325
326 foreach ($_POST["usr_id"] as $user_id) {
327 include_once("./Services/Container/Skills/classes/class.ilContainerMemberSkills.php");
328 $mem_skills = new ilContainerMemberSkills($this->container_skills->getId(), $user_id);
329 $mem_skills->removeAllSkillLevels($this->container->getRefId());
330 }
331
332 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
333 $ctrl->redirect($this, "listMembers");
334 }
335
336
338
342 public function listCompetences()
343 {
349
350 $tabs->activateSubTab("competences");
351
352 $toolbar->addButton(
353 $lng->txt("cont_add_skill"),
354 $ctrl->getLinkTarget($this, "selectSkill")
355 );
356
357 // table
358 include_once("./Services/Container/Skills/classes/class.ilContSkillTableGUI.php");
359 $tab = new ilContSkillTableGUI($this, "listCompetences", $this->container_skills);
360
361 $tpl->setContent($tab->getHTML());
362 }
363
367 public function selectSkill()
368 {
371
372 $tabs->activateSubTab("competences");
373
374 include_once("./Services/Skill/classes/class.ilSkillSelectorGUI.php");
375 $sel = new ilSkillSelectorGUI($this, "selectSkill", $this, "saveSelectedSkill");
376 if (!$sel->handleCommand()) {
377 $tpl->setContent($sel->getHTML());
378 }
379 }
380
384 public function saveSelectedSkill()
385 {
388
389 $s = explode(":", ($_GET["selected_skill"]));
390
391 $this->container_skills->addSkill((int) $s[0], (int) $s[1]);
392 $this->container_skills->save();
393
394 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
395
396 $ctrl->redirect($this, "listCompetences");
397 }
398
403 {
407
408 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
409 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
410 $ctrl->redirect($this, "listCompetences");
411 } else {
412 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
413 $cgui = new ilConfirmationGUI();
414 $cgui->setFormAction($ctrl->getFormAction($this));
415 $cgui->setHeaderText($lng->txt("cont_really_remove_skill_from_course"));
416 $cgui->setCancel($lng->txt("cancel"), "listCompetences");
417 $cgui->setConfirm($lng->txt("remove"), "removeSelectedSkill");
418
419 foreach ($_POST["id"] as $i) {
420 $s = explode(":", $i);
421 $cgui->addItem("id[]", $i, ilBasicSkill::_lookupTitle((int) $s[0], (int) $s[1]));
422 }
423
424 $tpl->setContent($cgui->getHTML());
425 }
426 }
427
431 public function removeSelectedSkill()
432 {
435
436 if (is_array($_POST["id"]) && count($_POST["id"]) > 0) {
437 foreach ($_POST["id"] as $id) {
438 $s = explode(":", $id);
439 $this->container_skills->removeSkill($s[0], $s[1]);
440 }
441 $this->container_skills->save();
442 }
443 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
444
445 $ctrl->redirect($this, "listCompetences");
446 }
447
448
450
454 public function settings()
455 {
458
459 $tabs->activateSubTab("settings");
460
461 $form = $this->initSettingsForm();
462
463 $tpl->setContent($form->getHTML());
464 }
465
469 public function initSettingsForm()
470 {
473
474 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
475 $form = new ilPropertyFormGUI();
476
477 // publish
478 $radg = new ilRadioGroupInputGUI($lng->txt("cont_skill_publish"), "cont_skill_publish");
479 $op1 = new ilRadioOption($lng->txt("cont_skill_publish_auto"), 0, $lng->txt("cont_skill_publish_auto_info"));
480 $radg->addOption($op1);
481 $op2 = new ilRadioOption($lng->txt("cont_skill_publish_manual"), 1, $lng->txt("cont_skill_publish_manual_info"));
482 $radg->addOption($op2);
483 $form->addItem($radg);
484 $radg->setValue(ilContainer::_lookupContainerSetting($this->container->getId(), "cont_skill_publish", 0));
485
486 $form->addCommandButton("saveSettings", $lng->txt("save"));
487
488 $form->setTitle($lng->txt("settings"));
489 $form->setFormAction($ctrl->getFormAction($this));
490
491 return $form;
492 }
493
497 public function saveSettings()
498 {
501
502 $form = $this->initSettingsForm();
503 $form->checkInput();
504 ilContainer::_writeContainerSetting($this->container->getId(), "cont_skill_publish", $form->getInput("cont_skill_publish"));
505
506 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
507
508 $ctrl->redirect($this, "settings");
509 }
510}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
Container skills administration.
selectSkill()
Select skill for container.
initCompetenceAssignmentForm()
Init competence assignment form.
__construct($a_container_gui)
Constructor.
initSettingsForm()
Init settings form.
saveSelectedSkill()
Save selected skill.
publishAssignments()
Publish assignments.
executeCommand()
Execute command.
listCompetences()
Select competences.
deassignCompetences()
Deassign competences.
removeSelectedSkill()
Remove skill from course selection.
saveCompetenceAssignment()
Save competence assignment.
getPathString($a_skill_id, $a_tref_id=0)
Get path string.
deassignCompetencesConfirm()
Deassign competences confirmation.
assignCompetences()
Assign competences to a member.
TableGUI class for container members / skill assignments.
TableGUI class for competences in containers.
Skills of a container.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _writeContainerSetting($a_id, $a_keyword, $a_value)
This class represents a non editable value in a property form.
static _lookupName($a_user_id)
lookup user name
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
Explorer class that works on tree objects (Services/Tree)
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if($format !==null) $name
Definition: metadata.php:230
$i
Definition: metadata.php:24
$DIC
Definition: xapitoken.php:46