skill.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* For license terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Skill;
  4. /**
  5. * This script manages the skills, levels and profiles assignments.
  6. *
  7. * @package chamilo.skill
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_protect_admin_script();
  12. $em = Database::getManager();
  13. $profiles = $em->getRepository('ChamiloSkillBundle:Profile')->findAll();
  14. $list = $em->getRepository('ChamiloCoreBundle:Skill')->findAll();
  15. $listAction = api_get_self();
  16. $toolbarAction = '';
  17. $action = '';
  18. if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete'])) {
  19. $action = $_GET['action'];
  20. }
  21. $id = isset($_GET['id']) ? $_GET['id'] : '';
  22. $item = null;
  23. if (!empty($id)) {
  24. /** @var Skill $item */
  25. $item = $em->getRepository('ChamiloCoreBundle:Skill')->find($id);
  26. if (!$item) {
  27. api_not_allowed();
  28. }
  29. }
  30. $form = new FormValidator('Skill', 'GET', api_get_self().'?action='.$action.'&id='.$id);
  31. $form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles, null, true);
  32. $form->addHidden('action', $action);
  33. $form->addHidden('id', $id);
  34. $form->addButtonSave(get_lang('Update'));
  35. if (!empty($item)) {
  36. $profile = $item->getProfile();
  37. if ($profile) {
  38. $form->setDefaults(
  39. [
  40. 'profile_id' => $item->getProfile()->getId(),
  41. ]
  42. );
  43. }
  44. $form->addHeader($item->getName());
  45. }
  46. $formToDisplay = $form->returnForm();
  47. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  48. $interbreadcrumb[] = ['url' => api_get_self(), 'name' => get_lang('ManageSkillsLevels')];
  49. $tpl = new Template($action);
  50. switch ($action) {
  51. case 'edit':
  52. $tpl->assign('form', $formToDisplay);
  53. $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);
  54. if ($form->validate()) {
  55. $values = $form->exportValues();
  56. $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
  57. if ($profile) {
  58. $item->setProfile($profile);
  59. $em->persist($item);
  60. $em->flush();
  61. Display::addFlash(Display::return_message(get_lang('Updated')));
  62. }
  63. header('Location: '.$listAction);
  64. exit;
  65. }
  66. break;
  67. case 'delete':
  68. $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);
  69. $em->remove($item);
  70. $em->flush();
  71. header('Location: '.$listAction);
  72. exit;
  73. break;
  74. default:
  75. break;
  76. }
  77. $tpl->assign('list', $list);
  78. $view = $tpl->get_template('admin/skill.tpl');
  79. $contentTemplate = $tpl->fetch($view);
  80. $tpl->assign('actions', $toolbarAction);
  81. $tpl->assign('content', $contentTemplate);
  82. $tpl->display_one_col_template();