skills_profile.php 4.3 KB

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