skills_profile.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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::isAllow();
  12. $interbreadcrumb[] = array(
  13. 'url' => 'index.php',
  14. "name" => get_lang('PlatformAdmin'),
  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('SearchSkills'));
  23. $form->addElement('select', 'skills', null, null, array('id'=>'skills'));
  24. $form->addButtonSearch(get_lang('Search'));
  25. $profiles = $skill_profile->get_all();
  26. $tpl->assign('profiles', $profiles);
  27. $total_skills_to_search = array();
  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'] : array();
  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 = array();
  44. $count_skills = count($skills);
  45. $users = $skill_rel_user->get_user_by_skills($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 = array();
  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[] = array(
  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 = 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 = $new_skill;
  103. Session::write('skills', $skills);
  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->returnForm();
  118. $tpl->assign('form', $form_to_html);
  119. $tpl->assign('url', $url);
  120. $templateName = $tpl->get_template('skill/profile.tpl');
  121. $content = $tpl->fetch($templateName);
  122. $tpl->assign('content', $content);
  123. $tpl->display_one_col_template();