skill.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  48. $interbreadcrumb[] = array('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. $item->setProfile($profile);
  58. $em->persist($item);
  59. $em->flush();
  60. header('Location: '.$listAction);
  61. exit;
  62. }
  63. break;
  64. case 'delete':
  65. $toolbarAction = Display::toolbarAction('toolbar', [Display::url(get_lang('List'), $listAction)]);
  66. $em->remove($item);
  67. $em->flush();
  68. header('Location: '.$listAction);
  69. exit;
  70. break;
  71. default:
  72. break;
  73. }
  74. $tpl->assign('list', $list);
  75. $view = $tpl->get_template('admin/skill.tpl');
  76. $contentTemplate = $tpl->fetch($view);
  77. $tpl->assign('actions', $toolbarAction);
  78. $tpl->assign('content', $contentTemplate);
  79. $tpl->display_one_col_template();