my_skills_report.php 7.5 KB

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