skill_list.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. api_protect_admin_script();
  12. if (api_get_setting('allow_skills_tool') != 'true') {
  13. api_not_allowed();
  14. }
  15. $action = isset($_GET['action']) ? $_GET['action'] : 'list';
  16. $skillId = isset($_GET['id']) ? intval($_GET['id']) : 0;
  17. $entityManager = Database::getManager();
  18. switch ($action) {
  19. case 'enable':
  20. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  21. if (is_null($skill)) {
  22. Display::addFlash(
  23. Display::return_message(
  24. get_lang('SkillNotFound'),
  25. 'error'
  26. )
  27. );
  28. } else {
  29. $updatedAt = new DateTime(
  30. api_get_utc_datetime(),
  31. new DateTimeZone(api_get_timezone())
  32. );
  33. $skill->setStatus(1);
  34. $skill->setUpdatedAt($updatedAt);
  35. $entityManager->persist($skill);
  36. $entityManager->flush();
  37. Display::addFlash(
  38. Display::return_message(
  39. sprintf(get_lang('SkillXEnabled'), $skill->getName()),
  40. 'success'
  41. )
  42. );
  43. }
  44. header('Location: '.api_get_self());
  45. exit;
  46. break;
  47. case 'disable':
  48. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  49. if (is_null($skill)) {
  50. Display::addFlash(
  51. Display::return_message(
  52. get_lang('SkillNotFound'),
  53. 'error'
  54. )
  55. );
  56. } else {
  57. $updatedAt = new DateTime(
  58. api_get_utc_datetime(),
  59. new DateTimeZone(api_get_timezone())
  60. );
  61. $skill->setStatus(0);
  62. $skill->setUpdatedAt($updatedAt);
  63. $entityManager->persist($skill);
  64. $skillObj = new Skill();
  65. $childrens = $skillObj->get_children($skill->getId());
  66. foreach ($childrens as $children) {
  67. $skill = $entityManager->find(
  68. 'ChamiloCoreBundle:Skill',
  69. $children['id']
  70. );
  71. if (empty($skill)) {
  72. continue;
  73. }
  74. $skill->setStatus(0);
  75. $skill->setUpdatedAt($updatedAt);
  76. $entityManager->persist($skill);
  77. }
  78. $entityManager->flush();
  79. Display::addFlash(
  80. Display::return_message(
  81. sprintf(get_lang('SkillXDisabled'), $skill->getName()),
  82. 'success'
  83. )
  84. );
  85. }
  86. header('Location: '.api_get_self());
  87. exit;
  88. break;
  89. case 'list':
  90. //no break
  91. default:
  92. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  93. $toolbar = Display::url(
  94. Display::return_icon(
  95. 'add.png',
  96. get_lang('CreateSkill'),
  97. null,
  98. ICON_SIZE_MEDIUM),
  99. api_get_path(WEB_CODE_PATH).'admin/skill_create.php',
  100. ['title' => get_lang('CreateSkill')]
  101. );
  102. $toolbar .= Display::url(
  103. Display::return_icon(
  104. 'wheel_skill.png',
  105. get_lang('SkillsWheel'),
  106. null,
  107. ICON_SIZE_MEDIUM),
  108. api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
  109. ['title' => get_lang('SkillsWheel')]
  110. );
  111. $toolbar .= Display::url(
  112. Display::return_icon(
  113. 'edit-skill.png',
  114. get_lang('BadgesManagement'),
  115. null,
  116. ICON_SIZE_MEDIUM),
  117. api_get_path(WEB_CODE_PATH).'admin/skill_badge_list.php',
  118. ['title' => get_lang('BadgesManagement')]
  119. );
  120. $toolbar .= Display::url(
  121. Display::return_icon(
  122. 'import_csv.png',
  123. get_lang('ImportSkillsListCSV'),
  124. null,
  125. ICON_SIZE_MEDIUM),
  126. api_get_path(WEB_CODE_PATH).'admin/skills_import.php',
  127. ['title' => get_lang('ImportSkillsListCSV')]
  128. );
  129. $extraField = new ExtraField('skill');
  130. $arrayVals = $extraField->get_handler_field_info_by_tags('tags');
  131. $tags = [];
  132. if (isset($arrayVals['options'])) {
  133. foreach ($arrayVals['options'] as $value) {
  134. $tags[] = $value;
  135. }
  136. }
  137. /* View */
  138. $skill = new Skill();
  139. $skillList = $skill->get_all();
  140. $extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;
  141. if ($extraFieldSearchTagId) {
  142. $skills = [];
  143. $skillsFiltered = $extraField->getAllSkillPerTag($arrayVals['id'], $extraFieldSearchTagId);
  144. foreach ($skillList as $index => $value) {
  145. if (array_search($index, $skillsFiltered)) {
  146. $skills[$index] = $value;
  147. }
  148. }
  149. $skillList = $skills;
  150. }
  151. $tpl = new Template(get_lang('ManageSkills'));
  152. $tpl->assign('skills', $skillList);
  153. $tpl->assign('current_tag_id', $extraFieldSearchTagId);
  154. $tpl->assign('tags', $tags);
  155. $templateName = $tpl->get_template('skill/list.tpl');
  156. $content = $tpl->fetch($templateName);
  157. $tpl->assign(
  158. 'actions',
  159. Display::toolbarAction('toolbar', [$toolbar], [12])
  160. );
  161. $tpl->assign('content', $content);
  162. $tpl->display_one_col_template();
  163. break;
  164. }