skills_profile.php 4.3 KB

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