skill_profile.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 __DIR__.'/../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. $toolbar = null;
  39. $tpl = new Template($action);
  40. switch ($action) {
  41. case 'move_up':
  42. /** @var \Chamilo\SkillBundle\Entity\Level $item */
  43. $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
  44. $position = $item->getPosition();
  45. if (!empty($position)) {
  46. $item->setPosition($position - 1);
  47. }
  48. $em->persist($item);
  49. $em->flush();
  50. header('Location: '.$listAction);
  51. exit;
  52. break;
  53. case 'move_down':
  54. /** @var \Chamilo\SkillBundle\Entity\Level $item */
  55. $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']);
  56. $position = $item->getPosition();
  57. $item->setPosition($position + 1);
  58. $em->persist($item);
  59. $em->flush();
  60. header('Location: '.$listAction);
  61. exit;
  62. break;
  63. case 'add':
  64. $tpl->assign('form', $formToDisplay);
  65. if ($form->validate()) {
  66. $values = $form->exportValues();
  67. $item = new \Chamilo\SkillBundle\Entity\Profile();
  68. $item->setName($values['name']);
  69. $em->persist($item);
  70. $em->flush();
  71. header('Location: '.$listAction);
  72. exit;
  73. }
  74. $toolbar = Display::url(
  75. Display::return_icon(
  76. 'list_badges.png',
  77. get_lang('List'),
  78. null,
  79. ICON_SIZE_MEDIUM
  80. ),
  81. $listAction,
  82. ['title' => get_lang('List')]
  83. );
  84. break;
  85. case 'edit':
  86. $tpl->assign('form', $formToDisplay);
  87. $toolbar = Display::url(
  88. Display::return_icon(
  89. 'list_badges.png',
  90. get_lang('List'),
  91. null,
  92. ICON_SIZE_MEDIUM
  93. ),
  94. $listAction,
  95. ['title' => get_lang('List')]
  96. );
  97. if ($form->validate()) {
  98. $values = $form->exportValues();
  99. $item->setName($values['name']);
  100. $em->persist($item);
  101. $em->flush();
  102. header('Location: '.$listAction);
  103. exit;
  104. }
  105. break;
  106. case 'delete':
  107. $toolbar = Display::url(
  108. Display::return_icon(
  109. 'list_badges.png',
  110. get_lang('List'),
  111. null,
  112. ICON_SIZE_MEDIUM
  113. ),
  114. $listAction,
  115. ['title' => get_lang('List')]
  116. );
  117. $em->remove($item);
  118. $em->flush();
  119. header('Location: '.$listAction);
  120. exit;
  121. break;
  122. default:
  123. $toolbar = Display::url(
  124. Display::return_icon(
  125. 'add.png',
  126. get_lang('Add'),
  127. null,
  128. ICON_SIZE_MEDIUM
  129. ),
  130. api_get_self().'?action=add',
  131. ['title' => get_lang('Add')]
  132. );
  133. }
  134. $tpl->assign('list', $list);
  135. $templateName = $tpl->get_template('admin/skill_profile.tpl');
  136. $contentTemplate = $tpl->fetch($templateName);
  137. if ($toolbar) {
  138. $tpl->assign(
  139. 'actions',
  140. Display::toolbarAction('toolbar', [$toolbar])
  141. );
  142. }
  143. $tpl->assign('content', $contentTemplate);
  144. $tpl->display_one_col_template();