skill.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 '../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. $action = '';
  17. if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete'])) {
  18. $action = $_GET['action'];
  19. }
  20. $id = isset($_GET['id']) ? $_GET['id'] : '';
  21. $item = null;
  22. if (!empty($id)) {
  23. /** @var Skill $item */
  24. $item = $em->getRepository('ChamiloCoreBundle:Skill')->find($id);
  25. if (!$item) {
  26. api_not_allowed();
  27. }
  28. }
  29. $form = new FormValidator('Skill', 'GET', api_get_self().'?action='.$action.'&id='.$id);
  30. $form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles, null, true);
  31. $form->addHidden('action', $action);
  32. $form->addHidden('id', $id);
  33. $form->addButtonSave(get_lang('Update'));
  34. if (!empty($item)) {
  35. $profile = $item->getProfile();
  36. if ($profile) {
  37. $form->setDefaults(
  38. [
  39. 'profile_id' => $item->getProfile()->getId(),
  40. ]
  41. );
  42. }
  43. $form->addHeader($item->getName());
  44. }
  45. $formToDisplay = $form->returnForm();
  46. $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  47. $interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('ManageSkillsLevels'));
  48. $tpl = new Template($action);
  49. switch ($action) {
  50. case 'edit':
  51. $tpl->assign('form', $formToDisplay);
  52. $tpl->assign('actions', Display::url(get_lang('List'), $listAction));
  53. if ($form->validate()) {
  54. $values = $form->exportValues();
  55. $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']);
  56. $item->setProfile($profile);
  57. $em->persist($item);
  58. $em->flush();
  59. header('Location: '.$listAction);
  60. exit;
  61. }
  62. break;
  63. case 'delete':
  64. $tpl->assign('actions', Display::url(get_lang('List'), $listAction));
  65. $em->remove($item);
  66. $em->flush();
  67. header('Location: '.$listAction);
  68. exit;
  69. break;
  70. default:
  71. break;
  72. }
  73. $tpl->assign('list', $list);
  74. $view = $tpl->get_template('admin/skill.tpl');
  75. $contentTemplate = $tpl->fetch($view);
  76. $tpl->assign('content', $contentTemplate);
  77. $tpl->display_one_col_template();