skill_list.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Framework\Container;
  5. /**
  6. * Skill list for management
  7. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  8. * @package chamilo.admin
  9. */
  10. $cidReset = true;
  11. //require_once '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. if (api_get_setting('skill.allow_skills_tool') != 'true') {
  15. api_not_allowed();
  16. }
  17. $action = isset($_GET['action']) ? $_GET['action'] : 'list';
  18. $skillId = isset($_GET['id']) ? intval($_GET['id']): 0;
  19. $entityManager = Database::getManager();
  20. switch ($action) {
  21. case 'enable':
  22. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  23. if (is_null($skill)) {
  24. Display::addFlash(
  25. Display::return_message(
  26. get_lang('SkillNotFound'),
  27. 'error'
  28. )
  29. );
  30. } else {
  31. $updatedAt = new DateTime(
  32. api_get_utc_datetime(),
  33. new DateTimeZone(api_get_timezone())
  34. );
  35. $skill->setStatus(1);
  36. $skill->setUpdatedAt($updatedAt);
  37. $entityManager->persist($skill);
  38. $entityManager->flush();
  39. Display::addFlash(
  40. Display::return_message(
  41. sprintf(get_lang('SkillXEnabled'), $skill->getName()),
  42. 'success'
  43. )
  44. );
  45. }
  46. header('Location: ' . api_get_self());
  47. exit;
  48. break;
  49. case 'disable':
  50. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  51. if (is_null($skill)) {
  52. Display::addFlash(
  53. Display::return_message(
  54. get_lang('SkillNotFound'),
  55. 'error'
  56. )
  57. );
  58. } else {
  59. $updatedAt = new DateTime(
  60. api_get_utc_datetime(),
  61. new DateTimeZone(api_get_timezone())
  62. );
  63. $skill->setStatus(0);
  64. $skill->setUpdatedAt($updatedAt);
  65. $entityManager->persist($skill);
  66. $skillObj = new Skill();
  67. $childrens = $skillObj->get_children($skill->getId());
  68. foreach ($childrens as $children) {
  69. $skill = $entityManager->find(
  70. 'ChamiloCoreBundle:Skill',
  71. $children['id']
  72. );
  73. if (empty($skill)) {
  74. continue;
  75. }
  76. $skill->setStatus(0);
  77. $skill->setUpdatedAt($updatedAt);
  78. $entityManager->persist($skill);
  79. }
  80. $entityManager->flush();
  81. Display::addFlash(
  82. Display::return_message(
  83. sprintf(get_lang('SkillXDisabled'), $skill->getName()),
  84. 'success'
  85. )
  86. );
  87. }
  88. header('Location: ' . api_get_self());
  89. exit;
  90. break;
  91. case 'list':
  92. default:
  93. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  94. $toolbar = Display::toolbarButton(
  95. get_lang('CreateSkill'),
  96. api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
  97. 'plus',
  98. 'success',
  99. ['title' => get_lang('CreateSkill')]
  100. );
  101. $toolbar .= Display::toolbarButton(
  102. get_lang('SkillsWheel'),
  103. api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
  104. 'bullseye',
  105. 'primary',
  106. ['title' => get_lang('CreateSkill')]
  107. );
  108. $toolbar .= Display::toolbarButton(
  109. get_lang('BadgesManagement'),
  110. api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
  111. 'shield',
  112. 'warning',
  113. ['title' => get_lang('BadgesManagement')]
  114. );
  115. $toolbar .= Display::toolbarButton(
  116. get_lang('ImportSkillsListCSV'),
  117. api_get_path(WEB_CODE_PATH) . 'admin/skills_import.php',
  118. 'arrow-up',
  119. 'info',
  120. ['title' => get_lang('BadgesManagement')]
  121. );
  122. $extraField = new ExtraField('skill');
  123. $arrayVals = $extraField->get_handler_field_info_by_tags('tags');
  124. $tags = [];
  125. /* Nested View */
  126. if (isset($arrayVals['options'])) {
  127. foreach ($arrayVals['options'] as $value) {
  128. $tags[] = $value;
  129. }
  130. }
  131. //extra JS lib for the collapsible table
  132. $skill = new Skill();
  133. $skillList = $skill->get_all();
  134. $extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;
  135. //obtain all skills
  136. if ($extraFieldSearchTagId) {
  137. $skills = [];
  138. //order the skill list by a nested view array
  139. $skillsFiltered = $extraField->getAllSkillPerTag($arrayVals['id'], $extraFieldSearchTagId);
  140. foreach ($skillList as $index => $value) {
  141. if (array_search($index, $skillsFiltered)) {
  142. $skills[$index] = $value;
  143. }
  144. }
  145. $skillList = $skills;
  146. }
  147. $tpl = new Template(get_lang('ManageSkills'));
  148. $tpl->assign('skills', $skillList);
  149. $tpl->assign('current_tag_id', $extraFieldSearchTagId);
  150. $tpl->assign('tags', $tags);
  151. $templateName = $tpl->get_template('skill/list.tpl');
  152. $content = $tpl->fetch($templateName);
  153. //$tpl = new Template(get_lang('ManageSkills'));
  154. $tpl->assign('actions', $toolbar);
  155. $tpl->assign('content', $content);
  156. $tpl->display_one_col_template();
  157. //no break
  158. break;
  159. }