my_skills_report.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 '../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. $skillTable = Database::get_main_table(TABLE_MAIN_SKILL);
  18. $skillRelUserTable = Database::get_main_table(TABLE_MAIN_SKILL_REL_USER);
  19. $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
  20. $tableRows = array();
  21. $tpl = new Template(get_lang('Skills'));
  22. $tplPath = null;
  23. $tpl->assign('allowSkillsTool', api_get_setting('allow_skills_tool') == 'true');
  24. $tpl->assign('allowDrhSkillsManagement', api_get_setting('allow_hr_skills_management') == 'true');
  25. if ($isStudent) {
  26. $sql = "SELECT s.name, sru.acquired_skill_at, c.title, c.directory
  27. FROM $skillTable s
  28. INNER JOIN $skillRelUserTable sru
  29. ON s.id = sru.skill_id
  30. INNER JOIN $courseTable c
  31. ON sru.course_id = c.id
  32. WHERE sru.user_id = $userId";
  33. $result = Database::query($sql);
  34. while ($resultData = Database::fetch_assoc($result)) {
  35. $tableRow = array(
  36. 'skillName' => $resultData['name'],
  37. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  38. 'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
  39. 'courseName' => $resultData['title']
  40. );
  41. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  42. if (file_exists($imageSysPath)) {
  43. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  44. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  45. if (!file_exists($thumbSysPath)) {
  46. $courseImageThumb = new Image($imageSysPath);
  47. $courseImageThumb->resize(32);
  48. $courseImageThumb->send_image($thumbSysPath);
  49. }
  50. $tableRow['courseImage'] = $thumbWebPath;
  51. }
  52. $tableRows[] = $tableRow;
  53. }
  54. $tplPath = 'skill/student_report.tpl';
  55. } else if ($isStudentBoss) {
  56. $selectedStudent = isset($_REQUEST['student']) ? intval($_REQUEST['student']) : 0;
  57. $tableRows = array();
  58. $followedStudents = UserManager::getUsersFollowedByStudentBoss($userId);
  59. foreach ($followedStudents as &$student) {
  60. $student['completeName'] = api_get_person_name($student['firstname'], $student['lastname']);
  61. }
  62. if ($selectedStudent > 0) {
  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. INNER 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 = array(
  74. 'completeName' => $followedStudents[$selectedStudent]['completeName'],
  75. 'skillName' => $resultData['name'],
  76. 'achievedAt' => api_format_date($resultData['acquired_skill_at'], DATE_FORMAT_NUMBER),
  77. 'courseImage' => Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true),
  78. 'courseName' => $resultData['title']
  79. );
  80. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  81. if (file_exists($imageSysPath)) {
  82. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $resultData['directory']);
  83. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $resultData['directory']);
  84. if (!file_exists($thumbSysPath)) {
  85. $courseImageThumb = new Image($imageSysPath);
  86. $courseImageThumb->resize(32);
  87. $courseImageThumb->send_image($thumbSysPath);
  88. }
  89. $tableRow['courseImage'] = $thumbWebPath;
  90. }
  91. $tableRows[] = $tableRow;
  92. }
  93. }
  94. $tplPath = 'skill/student_boss_report.tpl';
  95. $tpl->assign('followedStudents', $followedStudents);
  96. $tpl->assign('selectedStudent', $selectedStudent);
  97. } else if ($isDRH) {
  98. $selectedCourse = isset($_REQUEST['course']) ? intval($_REQUEST['course']) : null;
  99. $selectedSkill = isset($_REQUEST['skill']) ? intval($_REQUEST['skill']) : 0;
  100. $action = null;
  101. if (!empty($selectedCourse)) {
  102. $action = 'filterByCourse';
  103. } else if (!empty($selectedSkill)) {
  104. $action = 'filterBySkill';
  105. }
  106. $courses = CourseManager::get_courses_list();
  107. $tableRows = array();
  108. $reportTitle = null;
  109. $objSkill = new Skill();
  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, STUDENT, false, false, false, null, null, null, null, null, null, DRH
  122. );
  123. $coursesFilter = array();
  124. foreach ($courses as $course) {
  125. $coursesFilter[] = $course['id'];
  126. }
  127. $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
  128. break;
  129. }
  130. foreach ($tableRows as &$row) {
  131. $row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']);
  132. $row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
  133. $row['courseImage'] = Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true);
  134. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  135. if (file_exists($imageSysPath)) {
  136. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  137. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
  138. if (!file_exists($thumbSysPath)) {
  139. $courseImageThumb = new Image($imageSysPath);
  140. $courseImageThumb->resize(32);
  141. $courseImageThumb->send_image($thumbSysPath);
  142. }
  143. $row['courseImage'] = $thumbWebPath;
  144. }
  145. }
  146. $tplPath = 'skill/drh_report.tpl';
  147. $tpl->assign('action', $action);
  148. $tpl->assign('courses', $courses);
  149. $tpl->assign('skills', $skills);
  150. $tpl->assign('selectedCourse', $selectedCourse);
  151. $tpl->assign('selectedSkill', $selectedSkill);
  152. $tpl->assign('reportTitle', $reportTitle);
  153. }
  154. $tpl->assign('rows', $tableRows);
  155. $contentTemplate = $tpl->fetch("default/" . $tplPath);
  156. $tpl->assign('content', $contentTemplate);
  157. $tpl->display_one_col_template();