my_skills_report.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. case 'generate':
  27. $certificate = Certificate::generateUserSkills(api_get_user_id());
  28. Display::addFlash(Display::return_message(get_lang('Updated')));
  29. header('Location: '.api_get_self());
  30. exit;
  31. break;
  32. }
  33. $skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
  34. $skillRelUserTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  35. $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
  36. $tableRows = [];
  37. $objSkill = new Skill();
  38. $tpl = new Template(get_lang('Skills'));
  39. $tplPath = null;
  40. $tpl->assign('allow_skill_tool', api_get_setting('allow_skills_tool') === 'true');
  41. $tpl->assign('allow_drh_skills_management', api_get_setting('allow_hr_skills_management') === 'true');
  42. if ($isStudent) {
  43. $result = $objSkill->getUserSkillsTable($userId);
  44. $tableRows = $result['skills'];
  45. $tpl->assign('skill_table', $result['table']);
  46. $tplPath = 'skill/student_report.tpl';
  47. } elseif ($isStudentBoss) {
  48. $tableRows = [];
  49. $followedStudents = UserManager::getUsersFollowedByStudentBoss($userId);
  50. $frmStudents = new FormValidator('students', 'get');
  51. $slcStudent = $frmStudents->addSelect(
  52. 'student',
  53. get_lang('Student'),
  54. ['0' => get_lang('Select')]
  55. );
  56. $frmStudents->addButtonSearch(get_lang('Search'));
  57. foreach ($followedStudents as &$student) {
  58. $student['completeName'] = api_get_person_name($student['firstname'], $student['lastname']);
  59. $slcStudent->addOption($student['completeName'], $student['user_id']);
  60. }
  61. if ($frmStudents->validate()) {
  62. $selectedStudent = (int) $frmStudents->exportValue('student');
  63. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
  64. FROM $skillTable s
  65. INNER JOIN $skillRelUserTable sru
  66. ON s.id = sru.skill_id
  67. LEFT JOIN $courseTable c
  68. ON sru.course_id = c.id
  69. WHERE sru.user_id = $selectedStudent
  70. ";
  71. $result = Database::query($sql);
  72. while ($resultData = Database::fetch_assoc($result)) {
  73. $tableRow = [
  74. 'complete_name' => $followedStudents[$selectedStudent]['completeName'],
  75. 'skill_name' => Skill::translateName($resultData['name']),
  76. 'achieved_at' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  77. 'course_image' => Display::return_icon(
  78. 'course.png',
  79. null,
  80. null,
  81. ICON_SIZE_MEDIUM,
  82. null,
  83. true
  84. ),
  85. 'course_name' => $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(
  90. "%s%s/course-pic32.png",
  91. api_get_path(SYS_COURSE_PATH),
  92. $resultData['directory']
  93. );
  94. $thumbWebPath = sprintf(
  95. "%s%s/course-pic32.png",
  96. api_get_path(WEB_COURSE_PATH),
  97. $resultData['directory']
  98. );
  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('form', $frmStudents->returnForm());
  111. } elseif ($isDRH) {
  112. $selectedCourse = isset($_REQUEST['course']) ? intval($_REQUEST['course']) : null;
  113. $selectedSkill = isset($_REQUEST['skill']) ? intval($_REQUEST['skill']) : 0;
  114. $action = null;
  115. if (!empty($selectedCourse)) {
  116. $action = 'filterByCourse';
  117. } elseif (!empty($selectedSkill)) {
  118. $action = 'filterBySkill';
  119. }
  120. $courses = CourseManager::getCoursesFollowedByUser($userId, DRH);
  121. $tableRows = [];
  122. $reportTitle = null;
  123. $skills = $objSkill->get_all();
  124. switch ($action) {
  125. case 'filterByCourse':
  126. $course = api_get_course_info_by_id($selectedCourse);
  127. $reportTitle = sprintf(get_lang('AchievedSkillInCourseX'), $course['name']);
  128. $tableRows = $objSkill->listAchievedByCourse($selectedCourse);
  129. break;
  130. case 'filterBySkill':
  131. $skill = $objSkill->get($selectedSkill);
  132. $reportTitle = sprintf(get_lang('StudentsWhoAchievedTheSkillX'), $skill['name']);
  133. $students = UserManager::getUsersFollowedByUser(
  134. $userId,
  135. STUDENT,
  136. false,
  137. false,
  138. false,
  139. null,
  140. null,
  141. null,
  142. null,
  143. null,
  144. null,
  145. DRH
  146. );
  147. $coursesFilter = [];
  148. foreach ($courses as $course) {
  149. $coursesFilter[] = $course['id'];
  150. }
  151. $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
  152. break;
  153. }
  154. foreach ($tableRows as &$row) {
  155. $row['complete_name'] = api_get_person_name($row['firstname'], $row['lastname']);
  156. $row['achieved_at'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
  157. $row['course_image'] = Display::return_icon(
  158. 'course.png',
  159. null,
  160. null,
  161. ICON_SIZE_MEDIUM,
  162. null,
  163. true
  164. );
  165. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  166. if (file_exists($imageSysPath)) {
  167. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  168. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
  169. if (!file_exists($thumbSysPath)) {
  170. $courseImageThumb = new Image($imageSysPath);
  171. $courseImageThumb->resize(32);
  172. $courseImageThumb->send_image($thumbSysPath);
  173. }
  174. $row['course_image'] = $thumbWebPath;
  175. }
  176. }
  177. $tplPath = 'skill/drh_report.tpl';
  178. $tpl->assign('action', $action);
  179. $tpl->assign('courses', $courses);
  180. $tpl->assign('skills', $skills);
  181. $tpl->assign('selected_course', $selectedCourse);
  182. $tpl->assign('selected_skill', $selectedSkill);
  183. $tpl->assign('report_title', $reportTitle);
  184. }
  185. if (empty($tableRows)) {
  186. Display::addFlash(Display::return_message(get_lang('NoResults')));
  187. }
  188. $tpl->assign('rows', $tableRows);
  189. $templateName = $tpl->get_template($tplPath);
  190. $contentTemplate = $tpl->fetch($templateName);
  191. $tpl->assign('content', $contentTemplate);
  192. $tpl->display_one_col_template();