my_skills_report.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 __DIR__.'/../inc/global.inc.php';
  9. Skill::isAllow();
  10. $isStudent = api_is_student();
  11. $isStudentBoss = api_is_student_boss();
  12. $isDRH = api_is_drh();
  13. if (!$isStudent && !$isStudentBoss && !$isDRH) {
  14. header('Location: '.api_get_path(WEB_CODE_PATH).'social/skills_wheel.php');
  15. exit;
  16. }
  17. $userId = api_get_user_id();
  18. $skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
  19. $skillRelUserTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  20. $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
  21. $tableRows = array();
  22. $tpl = new Template(get_lang('Skills'));
  23. $tplPath = null;
  24. $tpl->assign('allow_skill_tool', api_get_setting('allow_skills_tool') === 'true');
  25. $tpl->assign('allow_drh_skills_management', api_get_setting('allow_hr_skills_management') === 'true');
  26. if ($isStudent) {
  27. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
  28. FROM $skillTable s
  29. INNER JOIN $skillRelUserTable sru
  30. ON s.id = sru.skill_id
  31. LEFT JOIN $courseTable c
  32. ON sru.course_id = c.id
  33. WHERE sru.user_id = $userId";
  34. $result = Database::query($sql);
  35. while ($resultData = Database::fetch_assoc($result)) {
  36. $tableRow = array(
  37. 'skillName' => $resultData['name'],
  38. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  39. 'courseImage' => Display::return_icon(
  40. 'course.png',
  41. null,
  42. null,
  43. ICON_SIZE_MEDIUM,
  44. null,
  45. true
  46. ),
  47. 'courseName' => $resultData['title']
  48. );
  49. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  50. if (file_exists($imageSysPath)) {
  51. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  52. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  53. if (!file_exists($thumbSysPath)) {
  54. $courseImageThumb = new Image($imageSysPath);
  55. $courseImageThumb->resize(32);
  56. $courseImageThumb->send_image($thumbSysPath);
  57. }
  58. $tableRow['courseImage'] = $thumbWebPath;
  59. }
  60. $tableRows[] = $tableRow;
  61. }
  62. $tplPath = 'skill/student_report.tpl';
  63. } elseif ($isStudentBoss) {
  64. $selectedStudent = isset($_REQUEST['student']) ? intval($_REQUEST['student']) : 0;
  65. $tableRows = array();
  66. $followedStudents = UserManager::getUsersFollowedByStudentBoss($userId);
  67. foreach ($followedStudents as &$student) {
  68. $student['completeName'] = api_get_person_name($student['firstname'], $student['lastname']);
  69. }
  70. if ($selectedStudent > 0) {
  71. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
  72. FROM $skillTable s
  73. INNER JOIN $skillRelUserTable sru
  74. ON s.id = sru.skill_id
  75. LEFT JOIN $courseTable c
  76. ON sru.course_id = c.id
  77. WHERE sru.user_id = $selectedStudent
  78. ";
  79. $result = Database::query($sql);
  80. while ($resultData = Database::fetch_assoc($result)) {
  81. $tableRow = array(
  82. 'completeName' => $followedStudents[$selectedStudent]['completeName'],
  83. 'skillName' => $resultData['name'],
  84. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  85. 'courseImage' => Display::return_icon(
  86. 'course.png',
  87. null,
  88. null,
  89. ICON_SIZE_MEDIUM,
  90. null,
  91. true
  92. ),
  93. 'courseName' => $resultData['title']
  94. );
  95. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  96. if (file_exists($imageSysPath)) {
  97. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  98. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  99. if (!file_exists($thumbSysPath)) {
  100. $courseImageThumb = new Image($imageSysPath);
  101. $courseImageThumb->resize(32);
  102. $courseImageThumb->send_image($thumbSysPath);
  103. }
  104. $tableRow['courseImage'] = $thumbWebPath;
  105. }
  106. $tableRows[] = $tableRow;
  107. }
  108. }
  109. $tplPath = 'skill/student_boss_report.tpl';
  110. $tpl->assign('followedStudents', $followedStudents);
  111. $tpl->assign('selectedStudent', $selectedStudent);
  112. } elseif ($isDRH) {
  113. $selectedCourse = isset($_REQUEST['course']) ? intval($_REQUEST['course']) : null;
  114. $selectedSkill = isset($_REQUEST['skill']) ? intval($_REQUEST['skill']) : 0;
  115. $action = null;
  116. if (!empty($selectedCourse)) {
  117. $action = 'filterByCourse';
  118. } elseif (!empty($selectedSkill)) {
  119. $action = 'filterBySkill';
  120. }
  121. $courses = CourseManager::get_courses_list();
  122. $tableRows = array();
  123. $reportTitle = null;
  124. $objSkill = new Skill();
  125. $skills = $objSkill->get_all();
  126. switch ($action) {
  127. case 'filterByCourse':
  128. $course = api_get_course_info_by_id($selectedCourse);
  129. $reportTitle = sprintf(get_lang('AchievedSkillInCourseX'), $course['name']);
  130. $tableRows = $objSkill->listAchievedByCourse($selectedCourse);
  131. break;
  132. case 'filterBySkill':
  133. $skill = $objSkill->get($selectedSkill);
  134. $reportTitle = sprintf(get_lang('StudentsWhoAchievedTheSkillX'), $skill['name']);
  135. $students = UserManager::getUsersFollowedByUser(
  136. $userId,
  137. STUDENT,
  138. false,
  139. false,
  140. false,
  141. null,
  142. null,
  143. null,
  144. null,
  145. null,
  146. null,
  147. DRH
  148. );
  149. $coursesFilter = array();
  150. foreach ($courses as $course) {
  151. $coursesFilter[] = $course['id'];
  152. }
  153. $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
  154. break;
  155. }
  156. foreach ($tableRows as &$row) {
  157. $row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']);
  158. $row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
  159. $row['courseImage'] = Display::return_icon(
  160. 'course.png',
  161. null,
  162. null,
  163. ICON_SIZE_MEDIUM,
  164. null,
  165. true
  166. );
  167. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  168. if (file_exists($imageSysPath)) {
  169. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  170. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
  171. if (!file_exists($thumbSysPath)) {
  172. $courseImageThumb = new Image($imageSysPath);
  173. $courseImageThumb->resize(32);
  174. $courseImageThumb->send_image($thumbSysPath);
  175. }
  176. $row['courseImage'] = $thumbWebPath;
  177. }
  178. }
  179. $tplPath = 'skill/drh_report.tpl';
  180. $tpl->assign('action', $action);
  181. $tpl->assign('courses', $courses);
  182. $tpl->assign('skills', $skills);
  183. $tpl->assign('selectedCourse', $selectedCourse);
  184. $tpl->assign('selectedSkill', $selectedSkill);
  185. $tpl->assign('reportTitle', $reportTitle);
  186. }
  187. $tpl->assign('rows', $tableRows);
  188. $templateName = $tpl->get_template($tplPath);
  189. $contentTemplate = $tpl->fetch($templateName);
  190. $tpl->assign('content', $contentTemplate);
  191. $tpl->display_one_col_template();