my_skills_report.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. $tpl = \Chamilo\CoreBundle\Framework\Container::getTwig();
  23. $tplPath = null;
  24. $tpl->addGlobal(
  25. 'allowSkillsTool',
  26. api_get_setting('skill.allow_skills_tool') == 'true'
  27. );
  28. $tpl->addGlobal(
  29. 'allowDrhSkillsManagement',
  30. api_get_setting('skill.allow_hr_skills_management') == 'true'
  31. );
  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. INNER 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.html.twig';
  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. INNER 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.html.twig';
  102. $tpl->addGlobal('followedStudents', $followedStudents);
  103. $tpl->addGlobal('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, STUDENT, false, false, false, null, null, null, null, null, null, DRH
  129. );
  130. $coursesFilter = array();
  131. foreach ($courses as $course) {
  132. $coursesFilter[] = $course['id'];
  133. }
  134. $tableRows = $objSkill->listUsersWhoAchieved($selectedSkill, $coursesFilter);
  135. break;
  136. }
  137. foreach ($tableRows as &$row) {
  138. $row['completeName'] = api_get_person_name($row['firstname'], $row['lastname']);
  139. $row['achievedAt'] = api_format_date($row['acquired_skill_at'], DATE_FORMAT_NUMBER);
  140. $row['courseImage'] = Display::return_icon('course.png', null, null, ICON_SIZE_MEDIUM, null, true);
  141. $imageSysPath = sprintf("%s%s/course-pic.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  142. if (file_exists($imageSysPath)) {
  143. $thumbSysPath = sprintf("%s%s/course-pic32.png", api_get_path(SYS_COURSE_PATH), $row['c_directory']);
  144. $thumbWebPath = sprintf("%s%s/course-pic32.png", api_get_path(WEB_COURSE_PATH), $row['c_directory']);
  145. if (!file_exists($thumbSysPath)) {
  146. $courseImageThumb = new Image($imageSysPath);
  147. $courseImageThumb->resize(32);
  148. $courseImageThumb->send_image($thumbSysPath);
  149. }
  150. $row['courseImage'] = $thumbWebPath;
  151. }
  152. }
  153. $tplPath = 'skill/drh_report.html.twig';
  154. $tpl->addGlobal('action', $action);
  155. $tpl->addGlobal('courses', $courses);
  156. $tpl->addGlobal('skills', $skills);
  157. $tpl->addGlobal('selectedCourse', $selectedCourse);
  158. $tpl->addGlobal('selectedSkill', $selectedSkill);
  159. $tpl->addGlobal('reportTitle', $reportTitle);
  160. }
  161. $tpl->addGlobal('rows', $tableRows);
  162. echo $tpl->render("@template_style/".$tplPath);