Advertisement
paulCodes

nested-lawls

Aug 27th, 2013
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.13 KB | None | 0 0
  1. <?php
  2. ini_set("display_errors", 1);
  3. ini_set("track_errors", 1);
  4. ini_set("html_errors", 1);
  5. error_reporting(E_ALL);
  6.  
  7. require_once("../../config.php");
  8. require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  9.  
  10. global $DB;
  11.  
  12. $id = required_param('id', PARAM_INT);   // sco id
  13. $reportData = array();
  14. $reportData['case.name'] = 'Philip Rivers';
  15.  
  16. $PAGE->set_url('/mod/scorm/hello-world.php', array('id'=>$id));
  17. $PAGE->set_title("Score Analyzer Report for ".$reportData['case.name']);
  18. $PAGE->set_heading("Score Analyzer Report for ".$reportData['case.name']);
  19.  
  20. if (empty($id)) {
  21.     print_error('missingparameter');
  22. }
  23.  
  24. require_course_login($course);
  25. $PAGE->set_pagelayout('incourse');
  26. $PAGE->set_context(get_system_context());
  27.  
  28. $table = 'iots.mdl_scorm_scoes_track';
  29. $results = $DB->get_records($table,array('scoid'=>$id));
  30. $studentResponses = array();
  31. $questionsReport = array();
  32.  
  33. foreach ($results as $interaction) {
  34.     // is this a student_response interaction
  35.     if(contains_substr($interaction->element,"student_response")){
  36.         // echo "build student_response array" ;
  37.         $response = array('userId' => $interaction->userid,
  38.                           'attemptNum' => $interaction->attempt,
  39.                           'questionId' => $interaction->element,
  40.                           'studentAnswer' => $interaction->value);
  41.         //have we already documented this user responce
  42.         if (!isset($studentResponses[$response['userId']])) {
  43.             $studentResponses[$response['userId']][$response['questionId']][] = $response;
  44.  
  45.         } else {
  46.             //have we logged this question yet for this user
  47.             if (!isset($studentResponses[$response['userId']][$response['questionId']])) {
  48.                 $studentResponses[$response['userId']][$response['questionId']][] = $response;
  49.             } else {
  50.                 // is the response newer
  51.                 if($studentResponses[$response['userId']][$response['questionId']]['attemptNum'] < $response['attemptNum']){
  52.                     $studentResponses[$response['userId']][$response['questionId']][] = $response;
  53.                 }
  54.             }
  55.         }
  56.     }        
  57. }
  58.  
  59. // loop through user question responses
  60. foreach ($studentResponses as $user) {  
  61.     foreach ($user as $response) {
  62.         if(!isset($questionsReport[$response[0]['questionId']])){
  63.             $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']] = 1;
  64.         } else {
  65.             $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']]++;
  66.         }
  67.     }
  68. }
  69. // do it again to simulate another student
  70. foreach ($studentResponses as $user) {  
  71.     foreach ($user as $response) {
  72.         if(!isset($questionsReport[$response[0]['questionId']])){
  73.             $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']] = 1;
  74.         } else {
  75.             $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']]++;
  76.         }
  77.     }
  78. }
  79.  
  80. // simulate higher and lower scoring from db.
  81. // need to set this part up later with an admin area to set the low and high settings.
  82. $scoreLegend = array();
  83. $scoreLegend['cmi.interactions_0.student_response'] = 1;
  84. $scoreLegend['cmi.interactions_1.student_response'] = 2;
  85. $scoreLegend['cmi.interactions_2.student_response'] = 2;
  86. $scoreLegend['cmi.interactions_3.student_response'] = 2;
  87. $scoreLegend['cmi.interactions_4.student_response'] = 1;
  88. $scoreLegend['cmi.interactions_5.student_response'] = 2;
  89. $scoreLegend['cmi.interactions_6.student_response'] = 1;
  90. $scoreLegend['cmi.interactions_7.student_response'] = 2;
  91. $scoreLegend['cmi.interactions_8.student_response'] = 1;
  92. $scoreLegend['cmi.interactions_9.student_response'] = 1;
  93.  
  94. $reportData['scoreLegend'] = $scoreLegend;
  95.  
  96. echo $OUTPUT->header();
  97. //build report table
  98. ?>
  99. <br />
  100. <br />
  101. <table class="flexible generaltable generalbox">
  102.   <thead>
  103.     <tr>
  104.       <th class="header">Skills</th>
  105.       <th class="header">Scoring Higher Than Acceptable</th>
  106.       <th class="header">Scoring Lower Than Acceptable</th>
  107.       <!--<th class="header">key</th> -->
  108.     </tr>
  109.   </thead>
  110.   <tbody>
  111.   <?php
  112.     foreach ($questionsReport as $key => $value) {
  113.         echo '<tr class="row">';
  114.             echo '<td>'. $key .'</td>';
  115.         foreach($value as $info){
  116.  
  117.             if(key($value) == $reportData['scoreLegend'][$key]){
  118.               echo '<td class="cell">'. $info .'</td>';
  119.               echo '<td class="cell">0</td>';
  120.               //echo '<td class="cell">'.key($value).'</td>';
  121.             } else {
  122.               echo '<td class="cell">0</td>';
  123.               echo '<td class="cell">'. $info .'</td>';
  124.               //echo '<td class="cell">'.key($value).'</td>';
  125.             }            
  126.         }
  127.         echo '</tr>';
  128.   }
  129.   ?>
  130.   </tbody>
  131. </table>
  132.  
  133. <?php
  134. echo $OUTPUT->footer();
  135.  
  136.  
  137. function contains_substr($mainStr, $str, $loc = false) {
  138.     if ($loc === false) return (strpos($mainStr, $str) !== false);
  139.     if (strlen($mainStr) < strlen($str)) return false;
  140.     if (($loc + strlen($str)) > strlen($mainStr)) return false;
  141.     return (strcmp(substr($mainStr, $loc, strlen($str)), $str) == 0);
  142. }
  143. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement