skill_list.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Skill list for management
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.admin
  7. */
  8. use ChamiloSession as Session;
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. if (api_get_setting('allow_skills_tool') != 'true') {
  14. api_not_allowed();
  15. }
  16. $action = isset($_GET['action']) ? $_GET['action'] : 'list';
  17. $skillId = isset($_GET['id']) ? intval($_GET['id']): 0;
  18. $entityManager = Database::getManager();
  19. switch ($action) {
  20. case 'enable':
  21. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  22. if (is_null($skill)) {
  23. Display::addFlash(
  24. Display::return_message(
  25. get_lang('SkillNotFound'),
  26. 'error'
  27. )
  28. );
  29. } else {
  30. $updatedAt = new DateTime(
  31. api_get_utc_datetime(),
  32. new DateTimeZone(_api_get_timezone())
  33. );
  34. $skill->setStatus(1);
  35. $skill->setUpdatedAt($updatedAt);
  36. $entityManager->persist($skill);
  37. $entityManager->flush();
  38. Display::addFlash(
  39. Display::return_message(
  40. sprintf(get_lang('SkillXEnabled'), $skill->getName()),
  41. 'success'
  42. )
  43. );
  44. }
  45. header('Location: ' . api_get_self());
  46. exit;
  47. break;
  48. case 'disable':
  49. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  50. if (is_null($skill)) {
  51. Display::addFlash(
  52. Display::return_message(
  53. get_lang('SkillNotFound'),
  54. 'error'
  55. )
  56. );
  57. } else {
  58. $updatedAt = new DateTime(
  59. api_get_utc_datetime(),
  60. new DateTimeZone(_api_get_timezone())
  61. );
  62. $skill->setStatus(0);
  63. $skill->setUpdatedAt($updatedAt);
  64. $entityManager->persist($skill);
  65. $skillObj = new Skill();
  66. $childrens = $skillObj->get_children($skill->getId());
  67. foreach ($childrens as $children) {
  68. $skill = $entityManager->find(
  69. 'ChamiloCoreBundle:Skill',
  70. $children['id']
  71. );
  72. if (empty($skill)) {
  73. continue;
  74. }
  75. $skill->setStatus(0);
  76. $skill->setUpdatedAt($updatedAt);
  77. $entityManager->persist($skill);
  78. }
  79. $entityManager->flush();
  80. Display::addFlash(
  81. Display::return_message(
  82. sprintf(get_lang('SkillXDisabled'), $skill->getName()),
  83. 'success'
  84. )
  85. );
  86. }
  87. header('Location: ' . api_get_self());
  88. exit;
  89. break;
  90. case 'list':
  91. //no break
  92. default:
  93. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  94. $message = Session::has('message') ? Session::read('message') : null;
  95. $toolbar = Display::toolbarButton(
  96. get_lang('CreateSkill'),
  97. api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
  98. 'plus',
  99. 'success',
  100. ['title' => get_lang('CreateSkill')]
  101. );
  102. $toolbar .= Display::toolbarButton(
  103. get_lang('SkillsWheel'),
  104. api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
  105. 'bullseye',
  106. 'primary',
  107. ['title' => get_lang('CreateSkill')]
  108. );
  109. $toolbar .= Display::toolbarButton(
  110. get_lang('BadgesManagement'),
  111. api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
  112. 'shield',
  113. 'warning',
  114. ['title' => get_lang('BadgesManagement')]
  115. );
  116. /* View */
  117. $skill = new Skill();
  118. $skillList = $skill->get_all();
  119. $tpl = new Template(get_lang('ManageSkills'));
  120. $tpl->assign('message', $message);
  121. $tpl->assign('skills', $skillList);
  122. $content = $tpl->fetch('default/skill/list.tpl');
  123. $tpl->assign('actions', $toolbar);
  124. $tpl->assign('content', $content);
  125. $tpl->display_one_col_template();
  126. Session::erase('message');
  127. break;
  128. }