skills_profile.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. // Language files that need to be included.
  7. $language_file = array('admin');
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'skill.lib.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script();
  13. if (api_get_setting('allow_skills_tool') != 'true') {
  14. api_not_allowed();
  15. }
  16. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
  17. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
  18. $interbreadcrumb[] = array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
  19. $skill = new Skill();
  20. $skill_profile = new SkillProfile();
  21. $skill_rel_user = new SkillRelUser();
  22. $url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php';
  23. $tpl = new Template(get_lang('Skills'));
  24. $form = new FormValidator('profile_search');
  25. $form->addElement('header', get_lang('SearchSkills'));
  26. $form->addElement('select', 'skills', null, null, array('id'=>'skills'));
  27. $form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="btn"');
  28. $profiles = $skill_profile->get_all();
  29. $tpl->assign('profiles', $profiles);
  30. $total_skills_to_search = array();
  31. if ($form->validate()) {
  32. $values = $form->getSubmitValues();
  33. $skills = $values['skills'];
  34. if (!empty($skills)) {
  35. $hidden_skills = isset($values['hidden_skills']) ? $values['hidden_skills'] : array();
  36. $skills = array_merge($skills, $hidden_skills);
  37. $skills = array_filter($skills);
  38. $skills = array_unique($skills);
  39. $_SESSION['skills'] = $skills;
  40. } else {
  41. $skills = isset($_SESSION['skills']) ? $_SESSION['skills']: array();
  42. }
  43. } else {
  44. $skills = isset($_SESSION['skills']) ? $_SESSION['skills']: array();
  45. }
  46. $user_list = array();
  47. $count_skills = count($skills);
  48. $users = $skill_rel_user->get_user_by_skills($skills);
  49. if (!empty($users)) {
  50. foreach ($users as $user) {
  51. $user_info = api_get_user_info($user['user_id']);
  52. $user_list[$user['user_id']]['user'] = $user_info;
  53. $my_user_skills = $skill_rel_user->get_user_skills($user['user_id']);
  54. $user_skills = array();
  55. $found_counts = 0 ;
  56. foreach($my_user_skills as $my_skill) {
  57. $found = false;
  58. if (in_array($my_skill['skill_id'], $skills)) {
  59. $found = true;
  60. $found_counts++;
  61. }
  62. $user_skills[] = array('skill_id' => $my_skill['skill_id'], 'found' => $found);
  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 = array();
  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('user_list', $user_list);
  77. $tpl->assign('order_user_list', $ordered_user_list);
  78. $tpl->assign('total_search_skills', $count_skills);
  79. if (!empty($skills)) {
  80. $counter = 0;
  81. foreach($skills as $hidden_skill_id) {
  82. $form->addElement('hidden', 'hidden_skills[]', $hidden_skill_id);
  83. $counter++;
  84. }
  85. }
  86. if (!empty($skills)) {
  87. foreach($skills as $my_skill) {
  88. $total_skills_to_search[$my_skill] = $my_skill;
  89. }
  90. }
  91. $total_skills_to_search = $skill->get_skills_info($total_skills_to_search);
  92. $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
  93. $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : null;
  94. switch ($action) {
  95. case 'remove_skill':
  96. $new_skill = array();
  97. foreach ($skills as $skill_id) {
  98. if ($id != $skill_id) {
  99. $new_skill[] = $skill_id;
  100. }
  101. }
  102. $skills = $_SESSION['skills'] = $new_skill;
  103. break;
  104. case 'load_profile':
  105. $skill_profile = new SkillRelProfile();
  106. $skills = $skill_profile->get_skills_by_profile($id);
  107. $total_skills_to_search = $skill->get_skills_info($skills);
  108. break;
  109. }
  110. $skill_list = array();
  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->return_form();
  117. //var_dump($total_skills_to_search);
  118. $tpl->assign('form', $form_to_html);
  119. $tpl->assign('url', $url);
  120. $content = $tpl->fetch('default/skill/profile.tpl');
  121. $tpl->assign('content', $content);
  122. $tpl->display_one_col_template();