skill_profile.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Add a skill Profile
  5. *
  6. * @package chamilo.skill
  7. */
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. api_protect_admin_script();
  11. $em = Database::getManager();
  12. $list = $em->getRepository('ChamiloSkillBundle:Profile')->findAll();
  13. $listAction = api_get_self();
  14. $action = '';
  15. if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete', 'move_up', 'move_down'])) {
  16. $action = $_GET['action'];
  17. }
  18. $id = isset($_GET['id']) ? $_GET['id'] : '';
  19. $item = null;
  20. if (!empty($id)) {
  21. $item = $em->getRepository('ChamiloSkillBundle:Profile')->find($id);
  22. if (!$item) {
  23. api_not_allowed();
  24. }
  25. }
  26. $form = new FormValidator('Profile', 'GET', api_get_self().'?action='.$action.'&id='.$id);
  27. $form->addText('name', get_lang('Name'));
  28. $form->addHidden('action', $action);
  29. $form->addHidden('id', $id);
  30. $form->addButtonSave(get_lang('Save'));
  31. if (!empty($item)) {
  32. $form->setDefaults(['name' => $item->getName()]);
  33. }
  34. $formToDisplay = $form->returnForm();
  35. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  36. $interbreadcrumb[] = array ('url' => 'skill.php', 'name' => get_lang('ManageSkillsLevels'));
  37. $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('SkillProfile'));
  38. $tpl = new Template($action);
  39. switch ($action) {
  40. case 'move_up':
  41. /** @var \Chamilo\SkillBundle\Entity\Level $item */
  42. $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
  43. $position = $item->getPosition();
  44. if (!empty($position)) {
  45. $item->setPosition($position-1);
  46. }
  47. $em->persist($item);
  48. $em->flush();
  49. header('Location: '.$listAction);
  50. exit;
  51. break;
  52. case 'move_down':
  53. /** @var \Chamilo\SkillBundle\Entity\Level $item */
  54. $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
  55. $position = $item->getPosition();
  56. $item->setPosition($position+1);
  57. $em->persist($item);
  58. $em->flush();
  59. header('Location: '.$listAction);
  60. exit;
  61. break;
  62. case 'add':
  63. $tpl->assign('form', $formToDisplay);
  64. if ($form->validate()) {
  65. $values = $form->exportValues();
  66. $item = new \Chamilo\SkillBundle\Entity\Profile();
  67. $item->setName($values['name']);
  68. $em->persist($item);
  69. $em->flush();
  70. header('Location: '.$listAction);
  71. exit;
  72. }
  73. $tpl->assign('actions', Display::url(get_lang('List'), $listAction));
  74. break;
  75. case 'edit':
  76. $tpl->assign('form', $formToDisplay);
  77. $tpl->assign('actions', Display::url(get_lang('List'), $listAction));
  78. if ($form->validate()) {
  79. $values = $form->exportValues();
  80. $item->setName($values['name']);
  81. $em->persist($item);
  82. $em->flush();
  83. header('Location: '.$listAction);
  84. exit;
  85. }
  86. break;
  87. case 'delete':
  88. $tpl->assign('actions', Display::url(get_lang('List'), $listAction));
  89. $em->remove($item);
  90. $em->flush();
  91. header('Location: '.$listAction);
  92. exit;
  93. break;
  94. default:
  95. $tpl->assign('actions', Display::url(get_lang('Add'), api_get_self().'?action=add'));
  96. }
  97. $tpl->assign('list', $list);
  98. $templateName = $tpl->get_template('admin/skill_profile.tpl');
  99. $contentTemplate = $tpl->fetch($templateName);
  100. $tpl->assign('content', $contentTemplate);
  101. $tpl->display_one_col_template();