my_skills_report.php 7.2 KB

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