ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_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  {
103  $lng = $this->lng;
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 
114  // Set tabs
115  //$this->tabs_gui->setTabActive('user_assignment');
116  $ilCtrl->setReturn($this, 'listUsers');
117  $ret = $ilCtrl->forwardCommand($user_search);
118  break;
119 
120  default:
121  if (in_array($cmd, array("listProfiles", "create", "edit", "save", "update",
122  "confirmDeleteProfiles", "deleteProfiles", "showLevels", "assignLevel",
123  "assignLevelSelectSkill", "assignLevelToProfile",
124  "confirmLevelAssignmentRemoval", "removeLevelAssignments",
125  "showUsers", "assignUser",
126  "confirmUserRemoval", "removeUsers", "exportProfiles", "showImportForm", "importProfiles"))) {
127  $this->$cmd();
128  }
129  break;
130  }
131  }
132 
139  public function setTabs($a_active)
140  {
141  $ilTabs = $this->tabs;
142  $lng = $this->lng;
144  $tpl = $this->tpl;
145  $ilHelp = $this->help;
146 
147  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
148  $this->profile->getTitle());
149  $tpl->setDescription("");
150 
151  $ilTabs->clearTargets();
152  $ilHelp->setScreenIdComponent("skmg_prof");
153 
154  $ilTabs->setBackTarget(
155  $lng->txt("back"),
156  $ilCtrl->getLinkTarget($this, "")
157  );
158 
159  // users
160  $ilTabs->addTab(
161  "users",
162  $lng->txt("skmg_assigned_users"),
163  $ilCtrl->getLinkTarget($this, "showUsers")
164  );
165 
166  // levels
167  $ilTabs->addTab(
168  "levels",
169  $lng->txt("skmg_assigned_skill_levels"),
170  $ilCtrl->getLinkTarget($this, "showLevels")
171  );
172 
173  // settings
174  $ilTabs->addTab(
175  "settings",
176  $lng->txt("settings"),
177  $ilCtrl->getLinkTarget($this, "edit")
178  );
179 
180  $ilTabs->activateTab($a_active);
181  }
182 
183 
187  public function listProfiles()
188  {
189  $tpl = $this->tpl;
190  $ilToolbar = $this->toolbar;
191  $lng = $this->lng;
193 
194  if ($this->checkPermissionBool("write")) {
195  $ilToolbar->addButton(
196  $lng->txt("skmg_add_profile"),
197  $ilCtrl->getLinkTarget($this, "create")
198  );
199 
200  $ilToolbar->addButton(
201  $lng->txt("import"),
202  $ilCtrl->getLinkTarget($this, "showImportForm")
203  );
204  }
205 
206  include_once("./Services/Skill/classes/class.ilSkillProfileTableGUI.php");
207  $tab = new ilSkillProfileTableGUI($this, "listProfiles", $this->checkPermissionBool("write"));
208 
209  $tpl->setContent($tab->getHTML());
210  }
211 
215  public function create()
216  {
217  $tpl = $this->tpl;
218 
219  $form = $this->initProfileForm("create");
220  $tpl->setContent($form->getHTML());
221  }
222 
226  public function edit()
227  {
228  $tpl = $this->tpl;
229 
230  $this->setTabs("settings");
231  $form = $this->initProfileForm("edit");
232  $tpl->setContent($form->getHTML());
233  }
234 
235 
241  public function initProfileForm($a_mode = "edit")
242  {
243  $lng = $this->lng;
245 
246  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
247  $form = new ilPropertyFormGUI();
248 
249  // title
250  $ti = new ilTextInputGUI($lng->txt("title"), "title");
251  $ti->setMaxLength(200);
252  $ti->setSize(40);
253  $ti->setRequired(true);
254  $form->addItem($ti);
255 
256  // description
257  $desc = new ilTextAreaInputGUI($lng->txt("description"), "description");
258  $desc->setCols(40);
259  $desc->setRows(4);
260  $form->addItem($desc);
261 
262  // save and cancel commands
263  if ($this->checkPermissionBool("write")) {
264  if ($a_mode == "create") {
265  $form->addCommandButton("save", $lng->txt("save"));
266  $form->addCommandButton("listProfiles", $lng->txt("cancel"));
267  $form->setTitle($lng->txt("skmg_add_profile"));
268  } else {
269  // set values
270  $ti->setValue($this->profile->getTitle());
271  $desc->setValue($this->profile->getDescription());
272 
273  $form->addCommandButton("update", $lng->txt("save"));
274  $form->addCommandButton("listProfiles", $lng->txt("cancel"));
275  $form->setTitle($lng->txt("skmg_edit_profile"));
276  }
277  }
278 
279  $form->setFormAction($ilCtrl->getFormAction($this));
280 
281  return $form;
282  }
283 
287  public function save()
288  {
289  $tpl = $this->tpl;
290  $lng = $this->lng;
292 
293  if (!$this->checkPermissionBool("write")) {
294  return;
295  }
296 
297  $form = $this->initProfileForm("create");
298  if ($form->checkInput()) {
299  $prof = new ilSkillProfile();
300  $prof->setTitle($form->getInput("title"));
301  $prof->setDescription($form->getInput("description"));
302  $prof->create();
303  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
304  $ilCtrl->redirect($this, "listProfiles");
305  } else {
306  $form->setValuesByPost();
307  $tpl->setContent($form->getHtml());
308  }
309  }
310 
314  public function update()
315  {
316  $lng = $this->lng;
318  $tpl = $this->tpl;
319 
320  if (!$this->checkPermissionBool("write")) {
321  return;
322  }
323 
324  $form = $this->initProfileForm("edit");
325  if ($form->checkInput()) {
326  $this->profile->setTitle($form->getInput("title"));
327  $this->profile->setDescription($form->getInput("description"));
328  $this->profile->update();
329 
330  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
331  $ilCtrl->redirect($this, "listProfiles");
332  } else {
333  $form->setValuesByPost();
334  $tpl->setContent($form->getHtml());
335  }
336  }
337 
341  public function confirmDeleteProfiles()
342  {
344  $tpl = $this->tpl;
345  $lng = $this->lng;
346 
347  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
348  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
349  $ilCtrl->redirect($this, "listProfiles");
350  } else {
351  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
352  $cgui = new ilConfirmationGUI();
353  $cgui->setFormAction($ilCtrl->getFormAction($this));
354  $cgui->setHeaderText($lng->txt("skmg_delete_profiles"));
355  $cgui->setCancel($lng->txt("cancel"), "listProfiles");
356  $cgui->setConfirm($lng->txt("delete"), "deleteProfiles");
357 
358  foreach ($_POST["id"] as $i) {
359  $cgui->addItem("id[]", $i, ilSkillProfile::lookupTitle($i));
360  }
361 
362  $tpl->setContent($cgui->getHTML());
363  }
364  }
365 
369  public function deleteProfiles()
370  {
372  $tpl = $this->tpl;
373  $lng = $this->lng;
374 
375  if (!$this->checkPermissionBool("write")) {
376  return;
377  }
378 
379  if (is_array($_POST["id"])) {
380  foreach ($_POST["id"] as $i) {
381  $prof = new ilSkillProfile($i);
382  $prof->delete();
383  }
384  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
385  }
386 
387  $ilCtrl->redirect($this, "listProfiles");
388  }
389 
393 
400  public function showLevels()
401  {
402  $tpl = $this->tpl;
404  $lng = $this->lng;
405  $ilToolbar = $this->toolbar;
406 
407  $this->setTabs("levels");
408 
409  if ($this->checkPermissionBool("write")) {
410  $ilToolbar->addButton(
411  $lng->txt("skmg_assign_level"),
412  $ilCtrl->getLinkTarget($this, "assignLevel")
413  );
414  }
415 
416  include_once("./Services/Skill/classes/class.ilSkillProfileLevelsTableGUI.php");
418  $this,
419  "showLevels",
420  $this->profile,
421  $this->checkPermissionBool("write")
422  );
423  $tpl->setContent($tab->getHTML());
424  }
425 
429  public function assignLevel()
430  {
431  $lng = $this->lng;
432  $ilTabs = $this->tabs;
434  $tpl = $this->tpl;
435 
436  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
437  $this->profile->getTitle());
438  $tpl->setDescription("");
439 
440  //$this->setTabs("levels");
441 
442  ilUtil::sendInfo($lng->txt("skmg_select_skill_level_assign"));
443 
444  $ilTabs->clearTargets();
445  $ilTabs->setBackTarget(
446  $lng->txt("back"),
447  $ilCtrl->getLinkTarget($this, "showLevels")
448  );
449 
450  include_once("./Services/Skill/classes/class.ilSkillSelectorGUI.php");
451  $exp = new ilSkillSelectorGUI($this, "assignLevel", $this, "assignLevelSelectSkill", "cskill_id");
452  if (!$exp->handleCommand()) {
453  $tpl->setContent($exp->getHTML());
454  }
455  }
456 
460  public function assignLevelSelectSkill()
461  {
462  $tpl = $this->tpl;
463  $lng = $this->lng;
465  $ilTabs = $this->tabs;
466 
467  $ilCtrl->saveParameter($this, "cskill_id");
468 
469  $tpl->setTitle($lng->txt("skmg_profile") . ": " .
470  $this->profile->getTitle());
471  $tpl->setDescription("");
472 
473  $ilTabs->clearTargets();
474  $ilTabs->setBackTarget(
475  $lng->txt("back"),
476  $ilCtrl->getLinkTarget($this, "showLevels")
477  );
478 
479  include_once("./Services/Skill/classes/class.ilSkillLevelProfileAssignmentTableGUI.php");
481  $this,
482  "assignLevelSelectSkill",
483  $_GET["cskill_id"]
484  );
485  $tpl->setContent($tab->getHTML());
486  }
487 
491  public function assignLevelToProfile()
492  {
494  $lng = $this->lng;
495 
496  if (!$this->checkPermissionBool("write")) {
497  return;
498  }
499 
500 
501  $parts = explode(":", $_GET["cskill_id"]);
502 
503  $this->profile->addSkillLevel(
504  (int) $parts[0],
505  (int) $parts[1],
506  (int) $_GET["level_id"]
507  );
508  $this->profile->update();
509 
510  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
511  $ilCtrl->redirect($this, "showLevels");
512  }
513 
518  {
520  $tpl = $this->tpl;
521  $lng = $this->lng;
522 
523  $this->setTabs("levels");
524 
525  if (!is_array($_POST["ass_id"]) || count($_POST["ass_id"]) == 0) {
526  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
527  $ilCtrl->redirect($this, "showLevels");
528  } else {
529  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
530  $cgui = new ilConfirmationGUI();
531  $cgui->setFormAction($ilCtrl->getFormAction($this));
532  $cgui->setHeaderText($lng->txt("skmg_confirm_remove_level_ass"));
533  $cgui->setCancel($lng->txt("cancel"), "showLevels");
534  $cgui->setConfirm($lng->txt("remove"), "removeLevelAssignments");
535 
536  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
537  foreach ($_POST["ass_id"] as $i) {
538  $id_arr = explode(":", $i);
539  $cgui->addItem(
540  "ass_id[]",
541  $i,
542  ilBasicSkill::_lookupTitle($id_arr[0]) . ": " .
544  );
545  }
546 
547  $tpl->setContent($cgui->getHTML());
548  }
549  }
550 
557  public function removeLevelAssignments()
558  {
560 
561  if (!$this->checkPermissionBool("write")) {
562  return;
563  }
564 
565  if (is_array($_POST["ass_id"])) {
566  foreach ($_POST["ass_id"] as $i) {
567  $id_arr = explode(":", $i);
568  $this->profile->removeSkillLevel($id_arr[0], $id_arr[1], $id_arr[2]);
569  }
570  $this->profile->update();
571  }
572 
573  $ilCtrl->redirect($this, "showLevels");
574  }
575 
579  public function showUsers()
580  {
581  $lng = $this->lng;
582  $tpl = $this->tpl;
583  $ilToolbar = $this->toolbar;
584 
585  // add member
586  if ($this->checkPermissionBool("write")) {
587  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
589  $this,
590  $ilToolbar,
591  array(
592  'auto_complete_name' => $lng->txt('user'),
593  'submit_name' => $lng->txt('skmg_assign_user')
594  )
595  );
596  }
597 
598  $this->setTabs("users");
599 
600  include_once("./Services/Skill/classes/class.ilSkillProfileUserTableGUI.php");
602  $this,
603  "showUsers",
604  $this->profile,
605  $this->checkPermissionBool("write")
606  );
607  $tpl->setContent($tab->getHTML());
608  }
609 
616  public function assignUser()
617  {
619  $lng = $this->lng;
620 
621  if (!$this->checkPermissionBool("write")) {
622  return;
623  }
624 
625  $user_id = ilObjUser::_lookupId(ilUtil::stripSlashes($_POST["user_login"]));
626  if ($user_id > 0) {
627  $this->profile->addUserToProfile($user_id);
628  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
629  }
630 
631  $ilCtrl->redirect($this, "showUsers");
632  }
633 
637  public function confirmUserRemoval()
638  {
640  $tpl = $this->tpl;
641  $lng = $this->lng;
642 
643  if (!$this->checkPermissionBool("write")) {
644  return;
645  }
646 
647  $this->setTabs("users");
648 
649  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
650  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
651  $ilCtrl->redirect($this, "showUsers");
652  } else {
653  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
654  $cgui = new ilConfirmationGUI();
655  $cgui->setFormAction($ilCtrl->getFormAction($this));
656  $cgui->setHeaderText($lng->txt("skmg_confirm_user_removal"));
657  $cgui->setCancel($lng->txt("cancel"), "showUsers");
658  $cgui->setConfirm($lng->txt("remove"), "removeUsers");
659 
660  foreach ($_POST["id"] as $i) {
662  $cgui->addItem(
663  "id[]",
664  $i,
665  $name["lastname"] . ", " . $name["firstname"] .
666  " [" . $name["login"] . "]"
667  );
668  }
669 
670  $tpl->setContent($cgui->getHTML());
671  }
672  }
673 
677  public function removeUsers()
678  {
680  $lng = $this->lng;
681 
682  if (!$this->checkPermissionBool("write")) {
683  return;
684  }
685 
686  if (is_array($_POST["id"])) {
687  foreach ($_POST["id"] as $i) {
688  $this->profile->removeUserFromProfile((int) $i);
689  }
690  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
691  }
692  $ilCtrl->redirect($this, "showUsers");
693  }
694 
701  public function exportProfiles()
702  {
704 
705  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
706  $ilCtrl->redirect($this, "");
707  }
708 
709  include_once("./Services/Export/classes/class.ilExport.php");
710  $exp = new ilExport();
711  $conf = $exp->getConfig("Services/Skill");
712  $conf->setMode(ilSkillExportConfig::MODE_PROFILES);
713  $conf->setSelectedProfiles($_POST["id"]);
714  $exp->exportObject("skmg", ilObject::_lookupObjId((int) $_GET["ref_id"]));
715 
716  //ilExport::_createExportDirectory(0, "xml", "");
717  //$export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
718  //$exp->exportEntity("skprof", $_POST["id"], "", "Services/Skill", $a_title, $a_export_dir, "skprof");
719 
720  $ilCtrl->redirectByClass(array("iladministrationgui", "ilobjskillmanagementgui", "ilexportgui"), "");
721  }
722 
726  public function showImportForm()
727  {
728  $tpl = $this->tpl;
729  $ilTabs = $this->tabs;
730 
731  $tpl->setContent($this->initInputForm()->getHTML());
732  }
733 
737  public function initInputForm()
738  {
739  $lng = $this->lng;
741 
742  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
743  $form = new ilPropertyFormGUI();
744 
745  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
746  $fi = new ilFileInputGUI($lng->txt("skmg_input_file"), "import_file");
747  $fi->setSuffixes(array("zip"));
748  $fi->setRequired(true);
749  $form->addItem($fi);
750 
751  // save and cancel commands
752  $form->addCommandButton("importProfiles", $lng->txt("import"));
753  $form->addCommandButton("", $lng->txt("cancel"));
754 
755  $form->setTitle($lng->txt("import"));
756  $form->setFormAction($ilCtrl->getFormAction($this));
757 
758  return $form;
759  }
760 
764  public function importProfiles()
765  {
766  $tpl = $this->tpl;
767  $lng = $this->lng;
769  $ilTabs = $this->tabs;
770 
771  $form = $this->initInputForm();
772  if ($form->checkInput()) {
773  include_once("./Services/Export/classes/class.ilImport.php");
774  $imp = new ilImport();
775  $imp->importEntity($_FILES["import_file"]["tmp_name"], $_FILES["import_file"]["name"], "skmg", "Services/Skill");
776 
777  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
778  $ilCtrl->redirect($this, "");
779  } else {
780  $form->setValuesByPost();
781  $tpl->setContent($form->getHtml());
782  }
783  }
784 }
TableGUI class for skill profile levels.
static _lookupName($a_user_id)
lookup user name
deleteProfiles()
Delete profiles.
Skill profile GUI class.
setTabs($a_active)
Set tabs.
checkPermissionBool($a_perm)
Check permission pool.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
static lookupLevelTitle($a_id)
Lookup level title.
confirmDeleteProfiles()
Confirm profile deletion.
$_GET["client_id"]
exportProfiles()
Export profiles.
This class represents a file property in a property form.
assignLevelToProfile()
Assign level to profile.
confirmLevelAssignmentRemoval()
Confirm level assignment removal.
TableGUI class for skill profiles.
Import class.
static _lookupId($a_user_str)
Lookup id by login.
removeLevelAssignments()
Remove level assignment.
TableGUI class for skill profile user assignment.
assignLevelSelectSkill()
Output level table for profile assignment.
executeCommand()
Execute command.
initProfileForm($a_mode="edit")
Init profile form.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(isset($_POST['submit'])) $form
static _lookupObjId($a_id)
This class represents a text property in a property form.
initInputForm()
Init input form.
setMaxLength($a_maxlength)
Set Max Length.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
importProfiles()
Import profiles.
static _lookupTitle($a_obj_id, $a_tref_id=0)
Lookup Title.
TableGUI class for skill profile skill level assignment.
confirmUserRemoval()
Confirm user removal.
Explorer class that works on tree objects (Services/Tree)
showLevels()
Show skill levels.
This class represents a text area property in a property form.
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
save()
Save profile form.
static lookupTitle($a_id)
Lookup title.
showImportForm()
Show import form.
setSuffixes($a_suffixes)
Set Accepted Suffixes.
listProfiles()
List profiles.
$_POST["username"]
Confirmation screen class.