my_skills_report.php 7.9 KB

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