question_course_report.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Report.
  5. *
  6. * @package chamilo.tracking
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. $this_section = 'session_my_space';
  11. $allow = Tracking::isAllowToTrack(api_get_session_id());
  12. if (!$allow) {
  13. api_not_allowed(true);
  14. }
  15. $export_to_xls = false;
  16. if (isset($_GET['export'])) {
  17. $export_to_xls = true;
  18. }
  19. if (api_is_platform_admin()) {
  20. $global = true;
  21. } else {
  22. $global = false;
  23. }
  24. $global = true;
  25. $course_list = $course_select_list = [];
  26. $html_result = '';
  27. $course_select_list[0] = get_lang('None');
  28. $htmlHeadXtra[] = '
  29. <script type="text/javascript">
  30. function load_courses() {
  31. document.search_simple.submit();
  32. }
  33. </script>';
  34. $session_id = isset($_REQUEST['session_id']) ? intval($_REQUEST['session_id']) : null;
  35. if (empty($session_id)) {
  36. $temp_course_list = CourseManager::get_courses_list();
  37. } else {
  38. $temp_course_list = SessionManager::get_course_list_by_session_id($session_id);
  39. }
  40. foreach ($temp_course_list as $temp_course_item) {
  41. $course_item = api_get_course_info($temp_course_item['code']);
  42. $course_select_list[$temp_course_item['code']] = $course_item['title'];
  43. }
  44. //Get session list
  45. $session_list = SessionManager::get_sessions_list([], ['name']);
  46. $my_session_list = [];
  47. $my_session_list[0] = get_lang('None');
  48. foreach ($session_list as $sesion_item) {
  49. $my_session_list[$sesion_item['id']] = $sesion_item['name'];
  50. }
  51. $form = new FormValidator('search_simple', 'POST', '', '', null, false);
  52. $form->addElement(
  53. 'select',
  54. 'session_id',
  55. get_lang('Sessions'),
  56. $my_session_list,
  57. ['id' => 'session_id', 'onchange' => 'load_courses();']
  58. );
  59. $form->addElement(
  60. 'select',
  61. 'course_code',
  62. get_lang('Courses'),
  63. $course_select_list
  64. );
  65. $form->addButtonFilter(get_lang('Filter'), 'submit_form');
  66. if (!empty($_REQUEST['course_code'])) {
  67. $course_code = $_REQUEST['course_code'];
  68. } else {
  69. $course_code = '';
  70. }
  71. if (empty($course_code)) {
  72. $course_code = 0;
  73. }
  74. $form->setDefaults(['course_code' => (string) $course_code]);
  75. $course_info = api_get_course_info($course_code);
  76. if (!empty($course_info)) {
  77. $list = new LearnpathList('', $course_info);
  78. $lp_list = $list->get_flat_list();
  79. $main_question_list = [];
  80. foreach ($lp_list as $lp_id => $lp) {
  81. $exercise_list = Event::get_all_exercises_from_lp(
  82. $lp_id,
  83. $course_info['real_id']
  84. );
  85. foreach ($exercise_list as $exercise) {
  86. $my_exercise = new Exercise($course_info['real_id']);
  87. $my_exercise->read($exercise['path']);
  88. $question_list = $my_exercise->selectQuestionList();
  89. $exercise_stats = Event::get_all_exercise_event_from_lp(
  90. $exercise['path'],
  91. $course_info['real_id'],
  92. $session_id
  93. );
  94. foreach ($question_list as $question_id) {
  95. $question_data = Question::read($question_id);
  96. $main_question_list[$question_id] = $question_data;
  97. $quantity_exercises = 0;
  98. $question_result = 0;
  99. foreach ($exercise_stats as $stats) {
  100. if (!empty($stats['question_list'])) {
  101. foreach ($stats['question_list'] as $my_question_stat) {
  102. if ($question_id == $my_question_stat['question_id']) {
  103. $question_result = $question_result + $my_question_stat['marks'];
  104. $quantity_exercises++;
  105. }
  106. }
  107. }
  108. }
  109. if (!empty($quantity_exercises)) {
  110. // Score % average
  111. $main_question_list[$question_id]->results = ($question_result / ($quantity_exercises));
  112. } else {
  113. $main_question_list[$question_id]->results = 0;
  114. }
  115. $main_question_list[$question_id]->quantity = $quantity_exercises;
  116. }
  117. }
  118. }
  119. }
  120. if (!$export_to_xls) {
  121. Display::display_header(get_lang("MySpace"));
  122. echo '<div class="actions">';
  123. if ($global) {
  124. echo MySpace::getTopMenu();
  125. } else {
  126. echo '<div style="float:left; clear:left">
  127. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.
  128. get_lang('StudentsTracking').'</a>&nbsp;|
  129. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.
  130. get_lang('CourseTracking').'</a>&nbsp;';
  131. echo '</div>';
  132. }
  133. echo '</div>';
  134. if (api_is_platform_admin()) {
  135. echo MySpace::getAdminActions();
  136. }
  137. echo '<br />';
  138. echo '<h2>'.get_lang('LPQuestionListResults').'</h2>';
  139. $form->display();
  140. if (empty($course_code)) {
  141. echo Display::return_message(get_lang('PleaseSelectACourse'), 'warning');
  142. }
  143. }
  144. $course_average = [];
  145. $counter = 0;
  146. if (!empty($main_question_list) && is_array($main_question_list)) {
  147. $html_result .= '<table class="data_table">';
  148. $html_result .= '<tr><th>'.get_lang('Question').
  149. Display::return_icon('info3.gif', get_lang('QuestionsAreTakenFromLPExercises'), ['align' => 'absmiddle', 'hspace' => '3px']).'</th>';
  150. $html_result .= '<th>'.$course_info['visual_code'].' '.get_lang('AverageScore').Display::return_icon('info3.gif', get_lang('AllStudentsAttemptsAreConsidered'), ['align' => 'absmiddle', 'hspace' => '3px']).' </th>';
  151. $html_result .= '<th>'.get_lang('Quantity').'</th>';
  152. foreach ($main_question_list as $question) {
  153. $total_student = 0;
  154. $counter++;
  155. $s_css_class = 'row_even';
  156. if ($counter % 2 == 0) {
  157. $s_css_class = 'row_odd';
  158. }
  159. $html_result .= "<tr class='$s_css_class'>
  160. <td >";
  161. $question_title = trim($question->question);
  162. if (empty($question_title)) {
  163. $html_result .= get_lang('Untitled').' '.get_lang('Question').' #'.$question->id;
  164. } else {
  165. $html_result .= $question->question;
  166. }
  167. $html_result .= "</td>";
  168. $html_result .= "<td>";
  169. $html_result .= round($question->results, 2).' / '.$question->weighting;
  170. $html_result .= "</td>";
  171. $html_result .= "<td>";
  172. $html_result .= $question->quantity;
  173. $html_result .= "</td>";
  174. }
  175. $html_result .= "</tr>";
  176. $html_result .= '</table>';
  177. } else {
  178. if (!empty($course_code)) {
  179. echo Display::return_message(get_lang('NoResults'), 'warning');
  180. }
  181. }
  182. if (!$export_to_xls) {
  183. echo $html_result;
  184. }
  185. Display::display_footer();