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