my_skills_report.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show the skills report
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.social.skill
  7. */
  8. require_once '../inc/global.inc.php';
  9. $isStudent = api_is_student();
  10. $isStudentBosss = api_is_student_boss();
  11. $isDRH = api_is_drh();
  12. if (!$isStudent && !$isStudentBosss && !$isDRH) {
  13. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'social/skills_wheel.php');
  14. die;
  15. }
  16. $userId = api_get_user_id();
  17. $skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
  18. $skillRelUserTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  19. $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
  20. $tableRows = array();
  21. $tpl = new Template(get_lang('Skills'));
  22. $tplPath = null;
  23. $tpl->assign('allowSkillsTool', api_get_setting('allow_skills_tool') == 'true');
  24. $tpl->assign('allowDrhSkillsManagement', api_get_setting('allow_hr_skills_management') == 'true');
  25. if ($isStudent) {
  26. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory "
  27. . "FROM $skillTable s "
  28. . "INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id "
  29. . "INNER JOIN $courseTable c ON sru.course_id = c.id "
  30. . "WHERE sru.user_id = $userId";
  31. $result = Database::query($sql);
  32. while ($resultData = Database::fetch_assoc($result)) {
  33. $tableRow = array(
  34. 'skillName' => $resultData['name'],
  35. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  36. 'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
  37. 'courseName' => $resultData['title']
  38. );
  39. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  40. if (file_exists($imageSysPath)) {
  41. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  42. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  43. if (!file_exists($thumbSysPath)) {
  44. $courseImageThumb = new Image($imageSysPath);
  45. $courseImageThumb->resize(32, 32, 0);
  46. $courseImageThumb->send_image($thumbSysPath);
  47. }
  48. $tableRow['courseImage'] = $thumbWebPath;
  49. }
  50. $tableRows[] = $tableRow;
  51. }
  52. $tplPath = 'skill/student_report.tpl';
  53. } else if ($isStudentBosss) {
  54. $selectedStudent = isset($_REQUEST['student']) ? intval($_REQUEST['student']) : 0;
  55. $tableRows = array();
  56. $followedStudents = UserManager::getUsersFollowedByStudentBoss($userId);
  57. foreach ($followedStudents as &$student) {
  58. $student['completeName'] = api_get_person_name($student['firstname'], $student['lastname']);
  59. }
  60. if ($selectedStudent > 0) {
  61. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory "
  62. . "FROM $skillTable s "
  63. . "INNER JOIN $skillRelUserTable sru ON s.id = sru.skill_id "
  64. . "INNER JOIN $courseTable c ON sru.course_id = c.id "
  65. . "WHERE sru.user_id = $selectedStudent";
  66. $result = Database::query($sql);
  67. while ($resultData = Database::fetch_assoc($result)) {
  68. $tableRow = array(
  69. 'completeName' => $followedStudents[$selectedStudent]['completeName'],
  70. 'skillName' => $resultData['name'],
  71. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  72. 'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
  73. 'courseName' => $resultData['title']
  74. );
  75. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  76. if (file_exists($imageSysPath)) {
  77. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  78. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  79. if (!file_exists($thumbSysPath)) {
  80. $courseImageThumb = new Image($imageSysPath);
  81. $courseImageThumb->resize(32, 32, 0);
  82. $courseImageThumb->send_image($thumbSysPath);
  83. }
  84. $tableRow['courseImage'] = $thumbWebPath;
  85. }
  86. $tableRows[] = $tableRow;
  87. }
  88. }
  89. $tplPath = 'skill/student_boss_report.tpl';
  90. $tpl->assign('followedStudents', $followedStudents);
  91. $tpl->assign('selectedStudent', $selectedStudent);
  92. } else if ($isDRH) {
  93. $selectedCourse = isset($_REQUEST['course']) ? intval($_REQUEST['course']) : null;
  94. $selectedSkill = isset($_REQUEST['skill']) ? intval($_REQUEST['skill']) : 0;
  95. $action = null;
  96. if (!empty($selectedCourse)) {
  97. $action = 'filterByCourse';
  98. } else if (!empty($selectedSkill)) {
  99. $action = 'filterBySkill';
  100. }
  101. $courses = CourseManager::get_courses_list();
  102. $tableRows = array();
  103. $reportTitle = null;
  104. $objSkill = new Skill();
  105. $skills = $objSkill->get_all();
  106. switch ($action) {
  107. case 'filterByCourse':
  108. $course = api_get_course_info_by_id($selectedCourse);
  109. $reportTitle = sprintf(get_lang('AchievedSkillInCourseX'), $course['name']);
  110. $tableRows = $objSkill->listAchievedByCourse($selectedCourse);
  111. break;
  112. case 'filterBySkill':
  113. $skill = $objSkill->get($selectedSkill);
  114. $reportTitle = sprintf(get_lang('StudentsWhoAchievedTheSkillX'), $skill['name']);
  115. $students = UserManager::getUsersFollowedByUser(
  116. $userId, STUDENT, false, false, false, null, null, null, null, null, null, DRH
  117. );
  118. $coursesFilter = array();
  119. foreach ($courses as $course) {
  120. $coursesFilter[] = $course['id'];
  121. }
  122. $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
  123. break;
  124. }
  125. foreach ($tableRows as &$row) {
  126. $row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']);
  127. $row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
  128. $row['courseImage'] = Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true);
  129. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  130. if (file_exists($imageSysPath)) {
  131. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  132. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
  133. if (!file_exists($thumbSysPath)) {
  134. $courseImageThumb = new Image($imageSysPath);
  135. $courseImageThumb->resize(32, 32, 0);
  136. $courseImageThumb->send_image($thumbSysPath);
  137. }
  138. $row['courseImage'] = $thumbWebPath;
  139. }
  140. }
  141. $tplPath = 'skill/drh_report.tpl';
  142. $tpl->assign('action', $action);
  143. $tpl->assign('courses', $courses);
  144. $tpl->assign('skills', $skills);
  145. $tpl->assign('selectedCourse', $selectedCourse);
  146. $tpl->assign('selectedSkill', $selectedSkill);
  147. $tpl->assign('reportTitle', $reportTitle);
  148. }
  149. $tpl->assign('rows', $tableRows);
  150. $contentTemplate = $tpl->fetch("default/" . $tplPath);
  151. $tpl->assign('content', $contentTemplate);
  152. $tpl->display_one_col_template();