ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
17  protected $profile = null;
18 
22  function __construct()
23  {
24  global $ilCtrl;
25 
26  $ilCtrl->saveParameter($this, "sprof_id");
27 
28  if ((int) $_GET["sprof_id"] > 0)
29  {
30  $this->id = (int) $_GET["sprof_id"];
31  }
32 
33  if ($this->id > 0)
34  {
35  $this->profile = new ilSkillProfile($this->id);
36  }
37  }
38 
42  function executeCommand()
43  {
44  global $ilCtrl, $lng;
45 
46  $cmd = $ilCtrl->getCmd("listProfiles");
47  $next_class = $ilCtrl->getNextClass();
48  switch($next_class)
49  {
50  case 'ilrepositorysearchgui':
51  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
52  $user_search = new ilRepositorySearchGUI();
53  $user_search->setTitle($lng->txt('skmg_add_user_to_profile'));
54  $user_search->setCallback($this, 'assignUser');
55 
56  // Set tabs
57  //$this->tabs_gui->setTabActive('user_assignment');
58  $ilCtrl->setReturn($this, 'listUsers');
59  $ret = $ilCtrl->forwardCommand($user_search);
60  break;
61 
62  default:
63  if (in_array($cmd, array("listProfiles", "create", "edit", "save", "update",
64  "confirmDeleteProfiles", "deleteProfiles", "showLevels", "assignLevel",
65  "assignLevelSelectSkill", "assignLevelToProfile",
66  "confirmLevelAssignmentRemoval", "removeLevelAssignments",
67  "showUsers", "assignUser",
68  "confirmUserRemoval", "removeUsers")))
69  {
70  $this->$cmd();
71  }
72  break;
73  }
74  }
75 
82  function setTabs($a_active)
83  {
84  global $ilTabs, $lng, $ilCtrl, $tpl, $ilHelp;
85 
86  $tpl->setTitle($lng->txt("skmg_profile").": ".
87  $this->profile->getTitle());
88  $tpl->setDescription("");
89 
90  $ilTabs->clearTargets();
91  $ilHelp->setScreenIdComponent("skmg_prof");
92 
93  $ilTabs->setBackTarget($lng->txt("back"),
94  $ilCtrl->getLinkTarget($this, ""));
95 
96  // users
97  $ilTabs->addTab("users",
98  $lng->txt("skmg_assigned_users"),
99  $ilCtrl->getLinkTarget($this, "showUsers"));
100 
101  // levels
102  $ilTabs->addTab("levels",
103  $lng->txt("skmg_assigned_skill_levels"),
104  $ilCtrl->getLinkTarget($this, "showLevels"));
105 
106  // settings
107  $ilTabs->addTab("settings",
108  $lng->txt("settings"),
109  $ilCtrl->getLinkTarget($this, "edit"));
110 
111  $ilTabs->activateTab($a_active);
112  }
113 
114 
118  function listProfiles()
119  {
120  global $tpl, $ilToolbar, $lng, $ilCtrl;
121 
122  $ilToolbar->addButton($lng->txt("skmg_add_profile"),
123  $ilCtrl->getLinkTarget($this, "create"));
124 
125  include_once("./Services/Skill/classes/class.ilSkillProfileTableGUI.php");
126  $tab = new ilSkillProfileTableGUI($this, "listProfiles");
127 
128  $tpl->setContent($tab->getHTML());
129  }
130 
134  function create()
135  {
136  global $tpl;
137 
138  $form = $this->initProfileForm("create");
139  $tpl->setContent($form->getHTML());
140  }
141 
145  function edit()
146  {
147  global $tpl;
148 
149  $this->setTabs("settings");
150  $form = $this->initProfileForm("edit");
151  $tpl->setContent($form->getHTML());
152  }
153 
154 
160  public function initProfileForm($a_mode = "edit")
161  {
162  global $lng, $ilCtrl;
163 
164  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
165  $form = new ilPropertyFormGUI();
166 
167  // title
168  $ti = new ilTextInputGUI($lng->txt("title"), "title");
169  $ti->setMaxLength(200);
170  $ti->setSize(40);
171  $ti->setRequired(true);
172  $form->addItem($ti);
173 
174  // description
175  $desc = new ilTextAreaInputGUI($lng->txt("description"), "description");
176  $desc->setCols(40);
177  $desc->setRows(4);
178  $form->addItem($desc);
179 
180  // save and cancel commands
181  if ($a_mode == "create")
182  {
183  $form->addCommandButton("save", $lng->txt("save"));
184  $form->addCommandButton("listProfiles", $lng->txt("cancel"));
185  $form->setTitle($lng->txt("skmg_add_profile"));
186  }
187  else
188  {
189  // set values
190  $ti->setValue($this->profile->getTitle());
191  $desc->setValue($this->profile->getDescription());
192 
193  $form->addCommandButton("update", $lng->txt("save"));
194  $form->addCommandButton("listProfiles", $lng->txt("cancel"));
195  $form->setTitle($lng->txt("skmg_edit_profile"));
196  }
197 
198  $form->setFormAction($ilCtrl->getFormAction($this));
199 
200  return $form;
201  }
202 
206  public function save()
207  {
208  global $tpl, $lng, $ilCtrl;
209 
210  $form = $this->initProfileForm("create");
211  if ($form->checkInput())
212  {
213  $prof = new ilSkillProfile();
214  $prof->setTitle($form->getInput("title"));
215  $prof->setDescription($form->getInput("description"));
216  $prof->create();
217  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
218  $ilCtrl->redirect($this, "listProfiles");
219  }
220  else
221  {
222  $form->setValuesByPost();
223  $tpl->setContent($form->getHtml());
224  }
225  }
226 
230  function update()
231  {
232  global $lng, $ilCtrl, $tpl;
233 
234  $form = $this->initProfileForm("edit");
235  if ($form->checkInput())
236  {
237  $this->profile->setTitle($form->getInput("title"));
238  $this->profile->setDescription($form->getInput("description"));
239  $this->profile->update();
240 
241  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
242  $ilCtrl->redirect($this, "listProfiles");
243  }
244  else
245  {
246  $form->setValuesByPost();
247  $tpl->setContent($form->getHtml());
248  }
249  }
250 
255  {
256  global $ilCtrl, $tpl, $lng;
257 
258  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
259  {
260  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
261  $ilCtrl->redirect($this, "listProfiles");
262  }
263  else
264  {
265  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
266  $cgui = new ilConfirmationGUI();
267  $cgui->setFormAction($ilCtrl->getFormAction($this));
268  $cgui->setHeaderText($lng->txt("skmg_delete_profiles"));
269  $cgui->setCancel($lng->txt("cancel"), "listProfiles");
270  $cgui->setConfirm($lng->txt("delete"), "deleteProfiles");
271 
272  foreach ($_POST["id"] as $i)
273  {
274  $cgui->addItem("id[]", $i, ilSkillProfile::lookupTitle($i));
275  }
276 
277  $tpl->setContent($cgui->getHTML());
278  }
279  }
280 
284  function deleteProfiles()
285  {
286  global $ilCtrl, $tpl, $lng;
287 
288  if (is_array($_POST["id"]))
289  {
290  foreach ($_POST["id"] as $i)
291  {
292  $prof = new ilSkillProfile($i);
293  $prof->delete();
294  }
295  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
296  }
297 
298  $ilCtrl->redirect($this, "listProfiles");
299  }
300 
304 
311  function showLevels()
312  {
313  global $tpl, $ilCtrl, $lng, $ilToolbar;
314 
315  $this->setTabs("levels");
316 
317  $ilToolbar->addButton($lng->txt("skmg_assign_level"),
318  $ilCtrl->getLinkTarget($this, "assignLevel")
319  );
320 
321  include_once("./Services/Skill/classes/class.ilSkillProfileLevelsTableGUI.php");
322  $tab = new ilSkillProfileLevelsTableGUI($this, "showLevels", $this->profile);
323  $tpl->setContent($tab->getHTML());
324  }
325 
329  function assignLevel()
330  {
331  global $lng, $ilTabs, $ilCtrl, $tpl;
332 
333  $tpl->setTitle($lng->txt("skmg_profile").": ".
334  $this->profile->getTitle());
335  $tpl->setDescription("");
336 
337  //$this->setTabs("levels");
338 
339  ilUtil::sendInfo($lng->txt("skmg_select_skill_level_assign"));
340 
341  $ilTabs->clearTargets();
342  $ilTabs->setBackTarget($lng->txt("back"),
343  $ilCtrl->getLinkTarget($this, "showLevels"));
344 
345  include_once("./Services/Skill/classes/class.ilSkillSelectorGUI.php");
346  $exp = new ilSkillSelectorGUI($this, "assignLevel", $this, "assignLevelSelectSkill", "cskill_id");
347  if (!$exp->handleCommand())
348  {
349  $tpl->setContent($exp->getHTML());
350  }
351  }
352 
357  {
358  global $tpl, $lng, $ilCtrl, $ilTabs;
359 
360  $ilCtrl->saveParameter($this, "cskill_id");
361 
362  $tpl->setTitle($lng->txt("skmg_profile").": ".
363  $this->profile->getTitle());
364  $tpl->setDescription("");
365 
366  $ilTabs->clearTargets();
367  $ilTabs->setBackTarget($lng->txt("back"),
368  $ilCtrl->getLinkTarget($this, "showLevels"));
369 
370  include_once("./Services/Skill/classes/class.ilSkillLevelProfileAssignmentTableGUI.php");
371  $tab = new ilSkillLevelProfileAssignmentTableGUI($this, "assignLevelSelectSkill",
372  $_GET["cskill_id"]);
373  $tpl->setContent($tab->getHTML());
374  }
375 
380  {
381  global $ilCtrl, $lng;
382 
383  $parts = explode(":", $_GET["cskill_id"]);
384 
385  $this->profile->addSkillLevel((int) $parts[0],
386  (int) $parts[1], (int) $_GET["level_id"]);
387  $this->profile->update();
388 
389  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
390  $ilCtrl->redirect($this, "showLevels");
391  }
392 
397  {
398  global $ilCtrl, $tpl, $lng;
399 
400  $this->setTabs("levels");
401 
402  if (!is_array($_POST["ass_id"]) || count($_POST["ass_id"]) == 0)
403  {
404  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
405  $ilCtrl->redirect($this, "showLevels");
406  }
407  else
408  {
409  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
410  $cgui = new ilConfirmationGUI();
411  $cgui->setFormAction($ilCtrl->getFormAction($this));
412  $cgui->setHeaderText($lng->txt("skmg_confirm_remove_level_ass"));
413  $cgui->setCancel($lng->txt("cancel"), "showLevels");
414  $cgui->setConfirm($lng->txt("remove"), "removeLevelAssignments");
415 
416  include_once("./Services/Skill/classes/class.ilBasicSkill.php");
417  foreach ($_POST["ass_id"] as $i)
418  {
419  $id_arr = explode(":", $i);
420  $cgui->addItem("ass_id[]", $i,
421  ilBasicSkill::_lookupTitle($id_arr[0]).": ".
422  ilBasicSkill::lookupLevelTitle($id_arr[2]));
423  }
424 
425  $tpl->setContent($cgui->getHTML());
426  }
427  }
428 
436  {
437  global $ilCtrl;
438 
439  if (is_array($_POST["ass_id"]))
440  {
441  foreach ($_POST["ass_id"] as $i)
442  {
443  $id_arr = explode(":", $i);
444  $this->profile->removeSkillLevel($id_arr[0], $id_arr[1], $id_arr[2]);
445  }
446  $this->profile->update();
447  }
448 
449  $ilCtrl->redirect($this, "showLevels");
450  }
451 
455  function showUsers()
456  {
457  global $lng, $tpl, $ilToolbar;
458 
459  // add member
460  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
462  $this,
463  $ilToolbar,
464  array(
465  'auto_complete_name' => $lng->txt('user'),
466  'submit_name' => $lng->txt('skmg_assign_user')
467  )
468  );
469 
470  $this->setTabs("users");
471 
472  include_once("./Services/Skill/classes/class.ilSkillProfileUserTableGUI.php");
473  $tab = new ilSkillProfileUserTableGUI($this, "showUsers",
474  $this->profile);
475  $tpl->setContent($tab->getHTML());
476  }
477 
484  function assignUser()
485  {
486  global $ilCtrl, $lng;
487 
488  $user_id = ilObjUser::_lookupId(ilUtil::stripSlashes($_POST["user_login"]));
489  if ($user_id > 0)
490  {
491  $this->profile->addUserToProfile($user_id);
492  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
493  }
494 
495  $ilCtrl->redirect($this, "showUsers");
496  }
497 
502  {
503  global $ilCtrl, $tpl, $lng;
504 
505  $this->setTabs("users");
506 
507  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
508  {
509  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
510  $ilCtrl->redirect($this, "showUsers");
511  }
512  else
513  {
514  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
515  $cgui = new ilConfirmationGUI();
516  $cgui->setFormAction($ilCtrl->getFormAction($this));
517  $cgui->setHeaderText($lng->txt("skmg_confirm_user_removal"));
518  $cgui->setCancel($lng->txt("cancel"), "showUsers");
519  $cgui->setConfirm($lng->txt("remove"), "removeUsers");
520 
521  foreach ($_POST["id"] as $i)
522  {
523  $name = ilObjUser::_lookupName($i);
524  $cgui->addItem("id[]", $i,
525  $name["lastname"].", ".$name["firstname"].
526  " [".$name["login"]."]");
527  }
528 
529  $tpl->setContent($cgui->getHTML());
530  }
531  }
532 
536  function removeUsers()
537  {
538  global $ilCtrl, $lng;
539 
540  if (is_array($_POST["id"]))
541  {
542  foreach ($_POST["id"] as $i)
543  {
544  $this->profile->removeUserFromProfile((int) $i);
545  }
546  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
547  }
548  $ilCtrl->redirect($this, "showUsers");
549  }
550 }
551 
552 ?>