gradebook_display_summary.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.gradebook
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $current_course_tool = TOOL_GRADEBOOK;
  9. api_protect_course_script(true);
  10. api_set_more_memory_and_time_limits();
  11. api_block_anonymous_users();
  12. GradebookUtils::block_students();
  13. $cat_id = isset($_GET['selectcat']) ? (int) $_GET['selectcat'] : null;
  14. $action = isset($_GET['action']) && $_GET['action'] ? $_GET['action'] : null;
  15. $sessionId = api_get_session_id();
  16. $courseInfo = api_get_course_info();
  17. $statusToFilter = empty($sessionId) ? STUDENT : 0;
  18. $userList = CourseManager::get_user_list_from_course_code(
  19. api_get_course_id(),
  20. $sessionId,
  21. null,
  22. null,
  23. $statusToFilter
  24. );
  25. $loadStats = [];
  26. if (api_get_setting('gradebook_detailed_admin_view') === 'true') {
  27. $loadStats = [1, 2, 3];
  28. } else {
  29. if (api_get_configuration_value('gradebook_enable_best_score') !== false) {
  30. $loadStats = [2];
  31. }
  32. }
  33. /*Session::write('use_gradebook_cache', false);
  34. $useCache = api_get_configuration_value('gradebook_use_apcu_cache');
  35. $cacheAvailable = api_get_configuration_value('apc') && $useCache;
  36. if ($cacheAvailable) {
  37. $cacheDriver = new \Doctrine\Common\Cache\ApcuCache();
  38. $cacheDriver->deleteAll();
  39. $cacheDriver->flushAll();
  40. }*/
  41. switch ($action) {
  42. case 'export_all':
  43. //Session::write('use_gradebook_cache', true);
  44. $cats = Category::load($cat_id, null, null, null, null, null, false);
  45. /** @var Category $cat */
  46. $cat = $cats[0];
  47. $allcat = $cat->get_subcategories(
  48. null,
  49. api_get_course_id(),
  50. api_get_session_id()
  51. );
  52. $alleval = $cat->get_evaluations(
  53. null,
  54. true,
  55. api_get_course_id(),
  56. api_get_session_id()
  57. );
  58. $alllink = $cat->get_links(
  59. null,
  60. true,
  61. api_get_course_id(),
  62. api_get_session_id()
  63. );
  64. $gradebooktable = new GradebookTable(
  65. $cat,
  66. $allcat,
  67. $alleval,
  68. $alllink,
  69. null, // params
  70. true, // $exportToPdf
  71. false, // showteacher
  72. null,
  73. $userList,
  74. $loadStats
  75. );
  76. $key = $gradebooktable->getPreloadDataKey();
  77. // preloads data
  78. Session::erase($key);
  79. $defaultData = $gradebooktable->preloadData();
  80. $tpl = new Template('', false, false, false);
  81. $params = [
  82. 'pdf_title' => sprintf(get_lang('GradeFromX'), $courseInfo['name']),
  83. 'session_info' => '',
  84. 'course_info' => '',
  85. 'pdf_date' => '',
  86. 'course_code' => api_get_course_id(),
  87. 'student_info' => null,
  88. 'show_grade_generated_date' => true,
  89. 'show_real_course_teachers' => false,
  90. 'show_teacher_as_myself' => false,
  91. 'orientation' => 'P',
  92. ];
  93. $pdf = new PDF('A4', $params['orientation'], $params, $tpl);
  94. $counter = 0;
  95. $htmlList = [];
  96. foreach ($userList as $index => $value) {
  97. $htmlList[] = GradebookUtils::generateTable(
  98. $courseInfo,
  99. $value['user_id'],
  100. $cats,
  101. false,
  102. true,
  103. $userList,
  104. $pdf
  105. );
  106. $counter++;
  107. }
  108. if (!empty($htmlList)) {
  109. $counter = 0;
  110. //error_log('Loading html list');
  111. $content = '';
  112. foreach ($htmlList as $value) {
  113. $content .= $value.'<pagebreak>';
  114. //error_log('Loading html: '.$counter);
  115. $counter++;
  116. }
  117. $tempFile = api_get_path(SYS_ARCHIVE_PATH).uniqid('gradebook_export_all').'.html';
  118. file_put_contents($tempFile, $content);
  119. //error_log('generating pdf');
  120. $pdf->html_to_pdf(
  121. $tempFile,
  122. null,
  123. null,
  124. false,
  125. true,
  126. true
  127. );
  128. //error_log('End generating');
  129. }
  130. // Delete calc_score session data
  131. Session::erase('calc_score');
  132. break;
  133. case 'download':
  134. //Session::write('use_gradebook_cache', true);
  135. $userId = isset($_GET['user_id']) && $_GET['user_id'] ? $_GET['user_id'] : null;
  136. $cats = Category::load($cat_id, null, null, null, null, null, false);
  137. GradebookUtils::generateTable($courseInfo, $userId, $cats);
  138. break;
  139. }
  140. $course_code = api_get_course_id();
  141. $interbreadcrumb[] = [
  142. 'url' => Category::getUrl(),
  143. 'name' => get_lang('Gradebook'),
  144. ];
  145. $interbreadcrumb[] = [
  146. 'url' => '#',
  147. 'name' => get_lang('GradebookListOfStudentsReports'),
  148. ];
  149. $this_section = SECTION_COURSES;
  150. Display::display_header('');
  151. $token = Security::get_token();
  152. echo Display::page_header(get_lang('GradebookListOfStudentsReports'));
  153. echo '<div class="btn-group">';
  154. if (count($userList) > 0) {
  155. $url = api_get_self().'?action=export_all&'.api_get_cidreq().'&selectcat='.$cat_id;
  156. echo Display::url(get_lang('ExportAllToPDF'), $url, ['class' => 'btn btn-default']);
  157. }
  158. echo '</div>';
  159. $allowSkillRelItem = api_get_configuration_value('allow_skill_rel_items');
  160. if (count($userList) == 0) {
  161. echo Display::return_message(get_lang('NoResultsAvailable'), 'warning');
  162. } else {
  163. echo '<br /><br /><table class="data_table">';
  164. echo '<tr><th>';
  165. echo get_lang('Student');
  166. echo '</th>';
  167. echo '<th>';
  168. echo get_lang('Action');
  169. echo '</th></tr>';
  170. foreach ($userList as $index => $value) {
  171. echo '<tr>
  172. <td width="70%">'
  173. .api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].') </td>';
  174. echo '<td>';
  175. $link = '';
  176. if ($allowSkillRelItem) {
  177. $url = api_get_path(WEB_CODE_PATH).'gradebook/skill_rel_user.php?'.api_get_cidreq().'&user_id='.$value['user_id'].'&selectcat='.$cat_id;
  178. $link = Display::url(
  179. get_lang('Skills'),
  180. $url,
  181. ['class' => 'btn btn-default']
  182. ).'&nbsp;';
  183. }
  184. $url = api_get_self().'?'.api_get_cidreq().'&action=download&user_id='.$value['user_id'].'&selectcat='.$cat_id;
  185. $link .= Display::url(
  186. get_lang('ExportToPDF'),
  187. $url,
  188. ['target' => '_blank', 'class' => 'btn btn-default']
  189. );
  190. echo $link;
  191. echo '</td></tr>';
  192. }
  193. echo '</table>';
  194. }
  195. Display::display_footer();