skills_profile.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script();
  11. Skill::isAllowed();
  12. $interbreadcrumb[] = [
  13. 'url' => 'index.php',
  14. "name" => get_lang('Administration'),
  15. ];
  16. $skill = new Skill();
  17. $skill_profile = new SkillProfile();
  18. $skill_rel_user = new SkillRelUser();
  19. $url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php';
  20. $tpl = new Template(get_lang('Skills'));
  21. $form = new FormValidator('profile_search');
  22. $form->addElement('header', get_lang('Search skills'));
  23. $form->addElement('select', 'skills', null, null, ['id' => 'skills']);
  24. $form->addButtonSearch(get_lang('Search'));
  25. $profiles = $skill_profile->get_all();
  26. $tpl->assign('profiles', $profiles);
  27. $total_skills_to_search = [];
  28. if ($form->validate()) {
  29. $values = $form->getSubmitValues();
  30. $skills = $values['skills'];
  31. if (!empty($skills)) {
  32. $hidden_skills = isset($values['hidden_skills']) ? $values['hidden_skills'] : [];
  33. $skills = array_merge($skills, $hidden_skills);
  34. $skills = array_filter($skills);
  35. $skills = array_unique($skills);
  36. Session::write('skills', $skills);
  37. } else {
  38. $skills = Session::read('skills', []);
  39. }
  40. } else {
  41. $skills = Session::read('skills', []);
  42. }
  43. $user_list = [];
  44. $count_skills = count($skills);
  45. $users = $skill_rel_user->getUserBySkills($skills);
  46. if (!empty($users)) {
  47. foreach ($users as $user) {
  48. $user_info = api_get_user_info($user['user_id']);
  49. $user_list[$user['user_id']]['user'] = $user_info;
  50. $my_user_skills = $skill_rel_user->getUserSkills($user['user_id']);
  51. $user_skills = [];
  52. $found_counts = 0;
  53. foreach ($my_user_skills as $my_skill) {
  54. $found = false;
  55. if (in_array($my_skill['skill_id'], $skills)) {
  56. $found = true;
  57. $found_counts++;
  58. }
  59. $user_skills[] = [
  60. 'skill_id' => $my_skill['skill_id'],
  61. 'found' => $found,
  62. ];
  63. $total_skills_to_search[$my_skill['skill_id']] = $my_skill['skill_id'];
  64. }
  65. $user_list[$user['user_id']]['skills'] = $user_skills;
  66. $user_list[$user['user_id']]['total_found_skills'] = $found_counts;
  67. }
  68. $ordered_user_list = [];
  69. foreach ($user_list as $user_id => $user_data) {
  70. $ordered_user_list[$user_data['total_found_skills']][] = $user_data;
  71. }
  72. if (!empty($ordered_user_list)) {
  73. asort($ordered_user_list);
  74. }
  75. }
  76. $tpl->assign('order_user_list', $ordered_user_list);
  77. $tpl->assign('total_search_skills', $count_skills);
  78. if (!empty($skills)) {
  79. $counter = 0;
  80. foreach ($skills as $hidden_skill_id) {
  81. $form->addElement('hidden', 'hidden_skills[]', $hidden_skill_id);
  82. $counter++;
  83. }
  84. }
  85. if (!empty($skills)) {
  86. foreach ($skills as $my_skill) {
  87. $total_skills_to_search[$my_skill] = $my_skill;
  88. }
  89. }
  90. $total_skills_to_search = $skill->getSkillsInfo($total_skills_to_search);
  91. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  92. $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  93. switch ($action) {
  94. case 'remove_skill':
  95. $new_skill = [];
  96. foreach ($skills as $skill_id) {
  97. if ($id != $skill_id) {
  98. $new_skill[] = $skill_id;
  99. }
  100. }
  101. $skills = $new_skill;
  102. Session::write('skills', $skills);
  103. break;
  104. case 'load_profile':
  105. $skill_profile = new SkillRelProfile();
  106. $skills = $skill_profile->getSkillsByProfile($id);
  107. $total_skills_to_search = $skill->getSkillsInfo($skills);
  108. break;
  109. }
  110. $skill_list = [];
  111. foreach ($total_skills_to_search as $skill_info) {
  112. $skill_list[$skill_info['id']] = $skill_info;
  113. }
  114. $tpl->assign('skill_list', $skill_list);
  115. $tpl->assign('search_skill_list', $skills);
  116. $form_to_html = $form->returnForm();
  117. $tpl->assign('form', $form_to_html);
  118. $tpl->assign('url', $url);
  119. $templateName = $tpl->get_template('skill/profile.tpl');
  120. $content = $tpl->fetch($templateName);
  121. $tpl->assign('content', $content);
  122. $tpl->display_one_col_template();