question_course_report.php 6.0 KB

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