ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSkillProfileGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Skill/classes/class.ilSkillProfile.php");
6
16{
20 protected $ctrl;
21
25 protected $lng;
26
30 protected $tabs;
31
35 protected $tpl;
36
40 protected $help;
41
45 protected $toolbar;
46
47 protected $profile = null;
51 public $access;
55 public $ref_id;
56
60 public function __construct()
61 {
62 global $DIC;
63
64 $this->ctrl = $DIC->ctrl();
65 $this->lng = $DIC->language();
66 $this->tabs = $DIC->tabs();
67 $this->tpl = $DIC["tpl"];
68 $this->help = $DIC["ilHelp"];
69 $this->toolbar = $DIC->toolbar();
70 $ilCtrl = $DIC->ctrl();
71 $ilAccess = $DIC->access();
72
73 $ilCtrl->saveParameter($this, "sprof_id");
74 $this->access = $ilAccess;
75 $this->ref_id = (int) $_GET["ref_id"];
76
77 if ((int) $_GET["sprof_id"] > 0) {
78 $this->id = (int) $_GET["sprof_id"];
79 }
80
81 if ($this->id > 0) {
82 $this->profile = new ilSkillProfile($this->id);
83 }
84 }
85
92 public function checkPermissionBool($a_perm)
93 {
94 return $this->access->checkAccess($a_perm, "", $this->ref_id);
95 }
96
100 public function executeCommand()
101 {
104
105 $cmd = $ilCtrl->getCmd("listProfiles");
106 $next_class = $ilCtrl->getNextClass();
107 switch ($next_class) {
108 case 'ilrepositorysearchgui':
109 include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
110 $user_search = new ilRepositorySearchGUI();
111 $user_search->setTitle($lng->txt('skmg_add_user_to_profile'));
112 $user_search->setCallback($this, 'assignUser');
113 $user_search->setRoleCallback($this, 'assignRole');
114
115 // Set tabs
116 //$this->tabs_gui->setTabActive('user_assignment');
117 $ilCtrl->setReturn($this, 'showUsers');
118 $ret = $ilCtrl->forwardCommand($user_search);
119 break;
120
121 default:
122 if (in_array($cmd, array("listProfiles", "create", "edit", "save", "update",
123 "confirmDeleteProfiles", "deleteProfiles", "showLevels", "assignLevel",
124 "assignLevelSelectSkill", "assignLevelToProfile",
125 "confirmLevelAssignmentRemoval", "removeLevelAssignments",
126 "showUsers", "assignUser", "assignRole",
127 "confirmUserRemoval", "removeUsers", "exportProfiles", "showImportForm", "importProfiles"))) {
128 $this->$cmd();
129 }
130 break;
131 }
132 }
133
140 public function setTabs($a_active)
141 {
142 $ilTabs = $this->tabs;
146 $ilHelp = $this->help;
147
148 $tpl->setTitle($lng->txt("skmg_profile") . ": " .
149 $this->profile->getTitle());
150 $tpl->setDescription("");
151
152 $ilTabs->clearTargets();
153 $ilHelp->setScreenIdComponent("skmg_prof");
154
155 $ilTabs->setBackTarget(
156 $lng->txt("back"),
157 $ilCtrl->getLinkTarget($this, "")
158 );
159
160 // users
161 $ilTabs->addTab(
162 "users",
163 $lng->txt("skmg_assigned_users"),
164 $ilCtrl->getLinkTarget($this, "showUsers")
165 );
166
167 // levels
168 $ilTabs->addTab(
169 "levels",
170 $lng->txt("skmg_assigned_skill_levels"),
171 $ilCtrl->getLinkTarget($this, "showLevels")
172 );
173
174 // settings
175 $ilTabs->addTab(
176 "settings",
177 $lng->txt("settings"),
178 $ilCtrl->getLinkTarget($this, "edit")
179 );
180
181 $ilTabs->activateTab($a_active);
182 }
183
184
188 public function listProfiles()
189 {
191 $ilToolbar = $this->toolbar;
194
195 if ($this->checkPermissionBool("write")) {
196 $ilToolbar->addButton(
197 $lng->txt("skmg_add_profile"),
198 $ilCtrl->getLinkTarget($this, "create")
199 );
200
201 $ilToolbar->addButton(
202 $lng->txt("import"),
203 $ilCtrl->getLinkTarget($this, "showImportForm")
204 );
205 }
206
207 include_once("./Services/Skill/classes/class.ilSkillProfileTableGUI.php");
208 $tab = new ilSkillProfileTableGUI($this, "listProfiles", $this->checkPermissionBool("write"));
209
210 $tpl->setContent($tab->getHTML());
211 }
212
216 public function create()
217 {
219
220 $form = $this->initProfileForm("create");
221 $tpl->setContent($form->getHTML());
222 }
223
227 public function edit()
228 {
230
231 $this->setTabs("settings");
232 $form = $this->initProfileForm("edit");
233 $tpl->setContent($form->getHTML());
234 }
235
236
242 public function initProfileForm($a_mode = "edit")
243 {
246
247 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
248 $form = new ilPropertyFormGUI();
249
250 // title
251 $ti = new ilTextInputGUI($lng->txt("title"), "title");
252 $ti->setMaxLength(200);
253 $ti->setSize(40);
254 $ti->setRequired(true);
255 $form->addItem($ti);
256
257 // description
258 $desc = new ilTextAreaInputGUI($lng->txt("description"), "description");
259 $desc->setCols(40);
260 $desc->setRows(4);
261 $form->addItem($desc);
262
263 // save and cancel commands
264 if ($this->checkPermissionBool("write")) {
265 if ($a_mode == "create") {
266 $form->addCommandButton("save", $lng->txt("save"));
267 $form->addCommandButton("listProfiles", $lng->txt("cancel"));
268 $form->setTitle($lng->txt("skmg_add_profile"));
269 } else {
270 // set values
271 $ti->setValue($this->profile->getTitle());
272 $desc->setValue($this->profile->getDescription());
273
274 $form->addCommandButton("update", $lng->txt("save"));
275 $form->addCommandButton("listProfiles", $lng->txt("cancel"));
276 $form->setTitle($lng->txt("skmg_edit_profile"));
277 }
278 }
279
280 $form->setFormAction($ilCtrl->getFormAction($this));
281
282 return $form;
283 }
284
288 public function save()
289 {
293
294 if (!$this->checkPermissionBool("write")) {
295 return;
296 }
297
298 $form = $this->initProfileForm("create");
299 if ($form->checkInput()) {
300 $prof = new ilSkillProfile();
301 $prof->setTitle($form->getInput("title"));
302 $prof->setDescription($form->getInput("description"));
303 $prof->create();
304 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
305 $ilCtrl->redirect($this, "listProfiles");
306 } else {
307 $form->setValuesByPost();
308 $tpl->setContent($form->getHtml());
309 }
310 }
311
315 public function update()
316 {
320
321 if (!$this->checkPermissionBool("write")) {
322 return;
323 }
324
325 $form = $this->initProfileForm("edit");
326 if ($form->checkInput()) {
327 $this->profile->setTitle($form->getInput("title"));
328 $this->profile->setDescription($form->getInput("description"));
329 $this->profile->update();
330
331 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
332 $ilCtrl->redirect($this, "listProfiles");
333 } else {
334 $form->setValuesByPost();
335 $tpl->setContent($form->getHtml());
336 }
337 }
338
342 public function confirmDeleteProfiles()
343 {
347
348 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
349 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
350 $ilCtrl->redirect($this, "listProfiles");
351 } else {
352 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
353 $cgui = new ilConfirmationGUI();
354 $cgui->setFormAction($ilCtrl->getFormAction($this));
355 $cgui->setHeaderText($lng->txt("skmg_delete_profiles"));
356 $cgui->setCancel($lng->txt("cancel"), "listProfiles");
357 $cgui->setConfirm($lng->txt("delete"), "deleteProfiles");
358
359 foreach ($_POST["id"] as $i) {
360 $cgui->addItem("id[]", $i, ilSkillProfile::lookupTitle($i));
361 }
362
363 $tpl->setContent($cgui->getHTML());
364 }
365 }
366
370 public function deleteProfiles()
371 {
375
376 if (!$this->checkPermissionBool("write")) {
377 return;
378 }
379
380 if (is_array($_POST["id"])) {
381 foreach ($_POST["id"] as $i) {
382 $prof = new ilSkillProfile($i);
383 $prof->delete();
384 }
385 ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
386 }
387
388 $ilCtrl->redirect($this, "listProfiles");
389 }
390
394
401 public function showLevels()
402 {
406 $ilToolbar = $this->toolbar;
407
408 $this->setTabs("levels");
409
410 if ($this->checkPermissionBool("write")) {
411 $ilToolbar->addButton(
412 $lng->txt("skmg_assign_level"),
413 $ilCtrl->getLinkTarget($this, "assignLevel")
414 );
415 }
416
417 include_once("./Services/Skill/classes/class.ilSkillProfileLevelsTableGUI.php");
419 $this,
420 "showLevels",
421 $this->profile,
422 $this->checkPermissionBool("write")
423 );
424 $tpl->setContent($tab->getHTML());
425 }
426
430 public function assignLevel()
431 {
433 $ilTabs = $this->tabs;
436
437 $tpl->setTitle($lng->txt("skmg_profile") . ": " .
438 $this->profile->getTitle());
439 $tpl->setDescription("");
440
441 //$this->setTabs("levels");
442
443 ilUtil::sendInfo($lng->txt("skmg_select_skill_level_assign"));
444
445 $ilTabs->clearTargets();
446 $ilTabs->setBackTarget(
447 $lng->txt("back"),
448 $ilCtrl->getLinkTarget($this, "showLevels")
449 );
450
451 include_once("./Services/Skill/classes/class.ilSkillSelectorGUI.php");
452 $exp = new ilSkillSelectorGUI($this, "assignLevel", $this, "assignLevelSelectSkill", "cskill_id");
453 if (!$exp->handleCommand()) {
454 $tpl->setContent($exp->getHTML());
455 }
456 }
457
461 public function assignLevelSelectSkill()
462 {
466 $ilTabs = $this->tabs;
467
468 $ilCtrl->saveParameter($this, "cskill_id");
469
470 $tpl->setTitle($lng->txt("skmg_profile") . ": " .
471 $this->profile->getTitle());
472 $tpl->setDescription("");
473
474 $ilTabs->clearTargets();
475 $ilTabs->setBackTarget(
476 $lng->txt("back"),
477 $ilCtrl->getLinkTarget($this, "showLevels")
478 );
479
480 include_once("./Services/Skill/classes/class.ilSkillLevelProfileAssignmentTableGUI.php");
482 $this,
483 "assignLevelSelectSkill",
484 $_GET["cskill_id"]
485 );
486 $tpl->setContent($tab->getHTML());
487 }
488
492 public function assignLevelToProfile()
493 {
496
497 if (!$this->checkPermissionBool("write")) {
498 return;
499 }
500
501
502 $parts = explode(":", $_GET["cskill_id"]);
503
504 $this->profile->addSkillLevel(
505 (int) $parts[0],
506 (int) $parts[1],
507 (int) $_GET["level_id"]
508 );
509 $this->profile->update();
510
511 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
512 $ilCtrl->redirect($this, "showLevels");
513 }
514
519 {
523
524 $this->setTabs("levels");
525
526 if (!is_array($_POST["ass_id"]) || count($_POST["ass_id"]) == 0) {
527 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
528 $ilCtrl->redirect($this, "showLevels");
529 } else {
530 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
531 $cgui = new ilConfirmationGUI();
532 $cgui->setFormAction($ilCtrl->getFormAction($this));
533 $cgui->setHeaderText($lng->txt("skmg_confirm_remove_level_ass"));
534 $cgui->setCancel($lng->txt("cancel"), "showLevels");
535 $cgui->setConfirm($lng->txt("remove"), "removeLevelAssignments");
536
537 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
538 foreach ($_POST["ass_id"] as $i) {
539 $id_arr = explode(":", $i);
540 $cgui->addItem(
541 "ass_id[]",
542 $i,
543 ilBasicSkill::_lookupTitle($id_arr[0]) . ": " .
545 );
546 }
547
548 $tpl->setContent($cgui->getHTML());
549 }
550 }
551
558 public function removeLevelAssignments()
559 {
561
562 if (!$this->checkPermissionBool("write")) {
563 return;
564 }
565
566 if (is_array($_POST["ass_id"])) {
567 foreach ($_POST["ass_id"] as $i) {
568 $id_arr = explode(":", $i);
569 $this->profile->removeSkillLevel($id_arr[0], $id_arr[1], $id_arr[2]);
570 }
571 $this->profile->update();
572 }
573
574 $ilCtrl->redirect($this, "showLevels");
575 }
576
580 public function showUsers()
581 {
584 $ilToolbar = $this->toolbar;
585
586 // add member
587 if ($this->checkPermissionBool("write")) {
588 include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
590 $this,
591 $ilToolbar,
592 array(
593 'auto_complete_name' => $lng->txt('user'),
594 'submit_name' => $lng->txt('skmg_assign_user')
595 )
596 );
597 }
598
599 $ilToolbar->addSeparator();
600
601 $button = ilLinkButton::getInstance();
602 $button->setCaption("skmg_add_assignment");
603 $button->setUrl($this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', 'start'));
604 $ilToolbar->addButtonInstance($button);
605
606 $this->setTabs("users");
607
608 include_once("./Services/Skill/classes/class.ilSkillProfileUserTableGUI.php");
610 $this,
611 "showUsers",
612 $this->profile,
613 $this->checkPermissionBool("write")
614 );
615 $tpl->setContent($tab->getHTML());
616 }
617
624 public function assignUser()
625 {
628
629 if (!$this->checkPermissionBool("write")) {
630 return;
631 }
632
633 // user assignment with toolbar
634 $user_id = ilObjUser::_lookupId(ilUtil::stripSlashes($_POST["user_login"]));
635 if ($user_id > 0) {
636 $this->profile->addUserToProfile($user_id);
637 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
638 }
639
640 // user assignment with ilRepositorySearchGUI
641 $users = $_POST['user'];
642 if (is_array($users)) {
643 foreach ($users as $id) {
644 if ($id > 0) {
645 $this->profile->addUserToProfile($id);
646 }
647 }
648 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
649 }
650
651 $ilCtrl->redirect($this, "showUsers");
652 }
653
657 public function assignRole(array $role_ids)
658 {
661
662 if (!$this->checkPermissionBool("write")) {
663 return;
664 }
665
666 $success = false;
667 foreach ($role_ids as $id) {
668 if ($id > 0) {
669 $this->profile->addRoleToProfile($id);
670 $success = true;
671 }
672 }
673 if ($success) {
674 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
675 }
676
677 $ilCtrl->redirect($this, "showUsers");
678 }
679
683 public function confirmUserRemoval()
684 {
688
689 if (!$this->checkPermissionBool("write")) {
690 return;
691 }
692
693 $this->setTabs("users");
694
695 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
696 ilUtil::sendInfo($lng->txt("no_checkbox"), true);
697 $ilCtrl->redirect($this, "showUsers");
698 } else {
699 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
700 $cgui = new ilConfirmationGUI();
701 $cgui->setFormAction($ilCtrl->getFormAction($this));
702 $cgui->setHeaderText($lng->txt("skmg_confirm_user_removal"));
703 $cgui->setCancel($lng->txt("cancel"), "showUsers");
704 $cgui->setConfirm($lng->txt("remove"), "removeUsers");
705
706 foreach ($_POST["id"] as $i) {
708
709 switch ($type) {
710 case 'usr':
712 $cgui->addItem(
713 "id[]",
714 $i,
715 $usr_name
716 );
717 break;
718
719 case 'role':
720 $role_name = ilObjRole::_lookupTitle($i);
721 $cgui->addItem(
722 "id[]",
723 $i,
724 $role_name
725 );
726 break;
727
728 default:
729 echo 'not defined';
730 }
731 }
732
733 $tpl->setContent($cgui->getHTML());
734 }
735 }
736
740 public function removeUsers()
741 {
744
745 if (!$this->checkPermissionBool("write")) {
746 return;
747 }
748
749 if (is_array($_POST["id"])) {
750 foreach ($_POST["id"] as $i) {
752 switch ($type) {
753 case 'usr':
754 $this->profile->removeUserFromProfile((int) $i);
755 break;
756
757 case 'role':
758 $this->profile->removeRoleFromProfile((int) $i);
759 break;
760
761 default:
762 echo 'not deleted';
763 }
764 }
765 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
766 }
767 $ilCtrl->redirect($this, "showUsers");
768 }
769
776 public function exportProfiles()
777 {
779
780 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
781 $ilCtrl->redirect($this, "");
782 }
783
784 include_once("./Services/Export/classes/class.ilExport.php");
785 $exp = new ilExport();
786 $conf = $exp->getConfig("Services/Skill");
788 $conf->setSelectedProfiles($_POST["id"]);
789 $exp->exportObject("skmg", ilObject::_lookupObjId((int) $_GET["ref_id"]));
790
791 //ilExport::_createExportDirectory(0, "xml", "");
792 //$export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
793 //$exp->exportEntity("skprof", $_POST["id"], "", "Services/Skill", $a_title, $a_export_dir, "skprof");
794
795 $ilCtrl->redirectByClass(array("iladministrationgui", "ilobjskillmanagementgui", "ilexportgui"), "");
796 }
797
801 public function showImportForm()
802 {
804 $ilTabs = $this->tabs;
805
806 $tpl->setContent($this->initInputForm()->getHTML());
807 }
808
812 public function initInputForm()
813 {
816
817 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
818 $form = new ilPropertyFormGUI();
819
820 include_once("./Services/Form/classes/class.ilFileInputGUI.php");
821 $fi = new ilFileInputGUI($lng->txt("skmg_input_file"), "import_file");
822 $fi->setSuffixes(array("zip"));
823 $fi->setRequired(true);
824 $form->addItem($fi);
825
826 // save and cancel commands
827 $form->addCommandButton("importProfiles", $lng->txt("import"));
828 $form->addCommandButton("", $lng->txt("cancel"));
829
830 $form->setTitle($lng->txt("import"));
831 $form->setFormAction($ilCtrl->getFormAction($this));
832
833 return $form;
834 }
835
839 public function importProfiles()
840 {
844 $ilTabs = $this->tabs;
845
846 $form = $this->initInputForm();
847 if ($form->checkInput()) {
848 include_once("./Services/Export/classes/class.ilImport.php");
849 $imp = new ilImport();
850 $imp->importEntity($_FILES["import_file"]["tmp_name"], $_FILES["import_file"]["name"], "skmg", "Services/Skill");
851
852 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
853 $ilCtrl->redirect($this, "");
854 } else {
855 $form->setValuesByPost();
856 $tpl->setContent($form->getHtml());
857 }
858 }
859}
$success
Definition: Utf8Test.php:86
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static lookupLevelTitle($a_id)
Lookup level title.
Confirmation screen class.
This class represents a file property in a property form.
Import class.
static getInstance()
Factory.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
TableGUI class for skill profile skill level assignment.
Skill profile GUI class.
confirmLevelAssignmentRemoval()
Confirm level assignment removal.
importProfiles()
Import profiles.
deleteProfiles()
Delete profiles.
executeCommand()
Execute command.
showImportForm()
Show import form.
save()
Save profile form.
assignRole(array $role_ids)
Assign role.
initInputForm()
Init input form.
assignLevelToProfile()
Assign level to profile.
removeLevelAssignments()
Remove level assignment.
checkPermissionBool($a_perm)
Check permission pool.
confirmDeleteProfiles()
Confirm profile deletion.
exportProfiles()
Export profiles.
assignLevelSelectSkill()
Output level table for profile assignment.
confirmUserRemoval()
Confirm user removal.
showLevels()
Show skill levels.
initProfileForm($a_mode="edit")
Init profile form.
setTabs($a_active)
Set tabs.
TableGUI class for skill profile levels.
TableGUI class for skill profiles.
TableGUI class for skill profile user assignment.
static lookupTitle($a_id)
Lookup title.
Explorer class that works on tree objects (Services/Tree)
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
This class represents a text area property in a property form.
This class represents a text property in a property form.
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 stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
help()
Definition: help.php:2
global $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
$ret
Definition: parser.php:6
$type
$DIC
Definition: xapitoken.php:46