my_skills_report.php 7.0 KB

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