skill_list.php 5.7 KB

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