skill_rel_user.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\SkillBundle\Entity\SkillRelItem;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. if (api_get_configuration_value('allow_skill_rel_items') == false) {
  6. api_not_allowed(true);
  7. }
  8. api_protect_course_script();
  9. GradebookUtils::block_students();
  10. $courseId = api_get_course_int_id();
  11. $sessionId = api_get_session_id();
  12. $userId = isset($_GET['user_id']) ? (int) $_GET['user_id'] : 0;
  13. $categoryId = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : 0;
  14. $userInfo = api_get_user_info($userId);
  15. if (empty($userInfo)) {
  16. api_not_allowed(true);
  17. }
  18. $skills = Skill::getSkillRelItemsPerCourse($courseId, $sessionId);
  19. $uniqueSkills = [];
  20. $itemsPerSkill = [];
  21. $uniqueSkillsConclusion = [];
  22. $skillRelUser = new SkillRelUser();
  23. $userSkills = $skillRelUser->getUserSkills($userId, api_get_course_int_id(), api_get_session_id());
  24. $userSkillsList = [];
  25. if (!empty($userSkills)) {
  26. foreach ($userSkills as $userSkill) {
  27. $userSkillsList[] = $userSkill['skill_id'];
  28. }
  29. }
  30. $em = Database::getManager();
  31. $codePath = api_get_path(WEB_CODE_PATH);
  32. /** @var SkillRelItem $skill */
  33. foreach ($skills as $skill) {
  34. $skillId = $skill->getSkill()->getId();
  35. $uniqueSkills[$skillId] = $skill->getSkill();
  36. $itemInfo = Skill::getItemInfo($skill->getItemId(), $skill->getItemType());
  37. $criteria = [
  38. 'user' => $userId,
  39. 'skillRelItem' => $skill,
  40. ];
  41. /** @var \Chamilo\SkillBundle\Entity\SkillRelItemRelUser $skillRelItemRelUser */
  42. $skillRelItemRelUser = $em->getRepository('ChamiloSkillBundle:SkillRelItemRelUser')->findOneBy($criteria);
  43. $itemInfo['status'] = $skillRelItemRelUser ? true : false;
  44. $itemInfo['url_activity'] = $codePath.$skill->getItemResultList(api_get_cidreq());
  45. if ($skillRelItemRelUser) {
  46. $itemInfo['url_activity'] = $codePath.$skillRelItemRelUser->getUserItemResultUrl(api_get_cidreq());
  47. }
  48. $itemsPerSkill[$skillId][]['info'] = $itemInfo;
  49. }
  50. foreach ($itemsPerSkill as $skillId => $skillList) {
  51. $uniqueSkillsConclusion[$skillId] = in_array($skillId, $userSkillsList);
  52. }
  53. $interbreadcrumb[] = [
  54. 'url' => Category::getUrl(),
  55. 'name' => get_lang('Assessments'),
  56. ];
  57. $interbreadcrumb[] = [
  58. 'url' => api_get_path(WEB_CODE_PATH).'gradebook/gradebook_display_summary.php?'.api_get_cidreq().'&selectcat='.$categoryId,
  59. 'name' => get_lang('AssessmentsListOfStudentsReports'),
  60. ];
  61. $url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=assign_user_to_skill';
  62. $template = new Template(get_lang('Skills and users list'));
  63. $template->assign('conclusion_list', $uniqueSkillsConclusion);
  64. $template->assign('skills', $uniqueSkills);
  65. $template->assign('items', $itemsPerSkill);
  66. $template->assign('user', $userInfo);
  67. $template->assign('course_id', api_get_course_int_id());
  68. $template->assign('session_id', api_get_session_id());
  69. $template->assign('assign_user_url', $url);
  70. $templateName = $template->get_template('gradebook/skill_rel_user.tpl');
  71. $content = $template->fetch($templateName);
  72. $template->assign('content', $content);
  73. $template->display_one_col_template();