skill_list.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Skill list for management.
  5. *
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. *
  8. * @package chamilo.admin
  9. */
  10. $cidReset = true;
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. Skill::isAllowed();
  15. $action = isset($_GET['action']) ? $_GET['action'] : 'list';
  16. $skillId = isset($_GET['id']) ? (int) $_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('Skill not found'),
  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('Skill "%s" enabled'), $skill->getName()),
  40. 'success'
  41. )
  42. );
  43. }
  44. header('Location: '.api_get_self());
  45. exit;
  46. break;
  47. case 'disable':
  48. /** @var \Chamilo\CoreBundle\Entity\Skill $skill */
  49. $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
  50. if (is_null($skill)) {
  51. Display::addFlash(
  52. Display::return_message(
  53. get_lang('Skill not found'),
  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. $children = $skillObj->getChildren($skill->getId());
  67. foreach ($children as $child) {
  68. $skill = $entityManager->find(
  69. 'ChamiloCoreBundle:Skill',
  70. $child['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('Skill "%s" disabled'), $skill->getName()),
  83. 'success'
  84. )
  85. );
  86. }
  87. header('Location: '.api_get_self());
  88. exit;
  89. break;
  90. case 'list':
  91. default:
  92. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
  93. $toolbar = Display::url(
  94. Display::return_icon(
  95. 'add.png',
  96. get_lang('Create skill'),
  97. null,
  98. ICON_SIZE_MEDIUM
  99. ),
  100. api_get_path(WEB_CODE_PATH).'admin/skill_create.php',
  101. ['title' => get_lang('Create skill')]
  102. );
  103. $toolbar .= Display::url(
  104. Display::return_icon(
  105. 'wheel_skill.png',
  106. get_lang('Skills wheel'),
  107. null,
  108. ICON_SIZE_MEDIUM
  109. ),
  110. api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
  111. ['title' => get_lang('Skills wheel')]
  112. );
  113. $toolbar .= Display::url(
  114. Display::return_icon(
  115. 'import_csv.png',
  116. get_lang('Import skills from a CSV file'),
  117. null,
  118. ICON_SIZE_MEDIUM
  119. ),
  120. api_get_path(WEB_CODE_PATH).'admin/skills_import.php',
  121. ['title' => get_lang('Import skills from a CSV file')]
  122. );
  123. $extraField = new ExtraField('skill');
  124. $arrayVals = $extraField->get_handler_field_info_by_tags('tags');
  125. $tags = [];
  126. if (isset($arrayVals['options'])) {
  127. foreach ($arrayVals['options'] as $value) {
  128. $tags[] = $value;
  129. }
  130. }
  131. /* View */
  132. $skill = new Skill();
  133. $skillList = $skill->get_all();
  134. $extraFieldSearchTagId = isset($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : 0;
  135. if ($extraFieldSearchTagId) {
  136. $skills = [];
  137. $skillsFiltered = $extraField->getAllSkillPerTag($arrayVals['id'], $extraFieldSearchTagId);
  138. foreach ($skillList as $index => $value) {
  139. if (array_search($index, $skillsFiltered)) {
  140. $skills[$index] = $value;
  141. }
  142. }
  143. $skillList = $skills;
  144. }
  145. $tpl = new Template(get_lang('Manage skills'));
  146. $tpl->assign('skills', $skillList);
  147. $tpl->assign('current_tag_id', $extraFieldSearchTagId);
  148. $tpl->assign('tags', $tags);
  149. $templateName = $tpl->get_template('skill/list.tpl');
  150. $content = $tpl->fetch($templateName);
  151. $tpl->assign(
  152. 'actions',
  153. Display::toolbarAction('toolbar', [$toolbar], [12])
  154. );
  155. $tpl->assign('content', $content);
  156. $tpl->display_one_col_template();
  157. break;
  158. }