Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ini_set("display_errors", 1);
- ini_set("track_errors", 1);
- ini_set("html_errors", 1);
- error_reporting(E_ALL);
- require_once("../../config.php");
- require_once($CFG->dirroot.'/mod/scorm/locallib.php');
- global $DB;
- $id = required_param('id', PARAM_INT); // sco id
- $reportData = array();
- $reportData['case.name'] = 'Philip Rivers';
- $PAGE->set_url('/mod/scorm/hello-world.php', array('id'=>$id));
- $PAGE->set_title("Score Analyzer Report for ".$reportData['case.name']);
- $PAGE->set_heading("Score Analyzer Report for ".$reportData['case.name']);
- if (empty($id)) {
- print_error('missingparameter');
- }
- require_course_login($course);
- $PAGE->set_pagelayout('incourse');
- $PAGE->set_context(get_system_context());
- $table = 'iots.mdl_scorm_scoes_track';
- $results = $DB->get_records($table,array('scoid'=>$id));
- $studentResponses = array();
- $questionsReport = array();
- foreach ($results as $interaction) {
- // is this a student_response interaction
- if(contains_substr($interaction->element,"student_response")){
- // echo "build student_response array" ;
- $response = array('userId' => $interaction->userid,
- 'attemptNum' => $interaction->attempt,
- 'questionId' => $interaction->element,
- 'studentAnswer' => $interaction->value);
- //have we already documented this user responce
- if (!isset($studentResponses[$response['userId']])) {
- $studentResponses[$response['userId']][$response['questionId']][] = $response;
- } else {
- //have we logged this question yet for this user
- if (!isset($studentResponses[$response['userId']][$response['questionId']])) {
- $studentResponses[$response['userId']][$response['questionId']][] = $response;
- } else {
- // is the response newer
- if($studentResponses[$response['userId']][$response['questionId']]['attemptNum'] < $response['attemptNum']){
- $studentResponses[$response['userId']][$response['questionId']][] = $response;
- }
- }
- }
- }
- }
- // loop through user question responses
- foreach ($studentResponses as $user) {
- foreach ($user as $response) {
- if(!isset($questionsReport[$response[0]['questionId']])){
- $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']] = 1;
- } else {
- $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']]++;
- }
- }
- }
- // do it again to simulate another student
- foreach ($studentResponses as $user) {
- foreach ($user as $response) {
- if(!isset($questionsReport[$response[0]['questionId']])){
- $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']] = 1;
- } else {
- $questionsReport[$response[0]['questionId']][$response[0]['studentAnswer']]++;
- }
- }
- }
- // simulate higher and lower scoring from db.
- // need to set this part up later with an admin area to set the low and high settings.
- $scoreLegend = array();
- $scoreLegend['cmi.interactions_0.student_response'] = 1;
- $scoreLegend['cmi.interactions_1.student_response'] = 2;
- $scoreLegend['cmi.interactions_2.student_response'] = 2;
- $scoreLegend['cmi.interactions_3.student_response'] = 2;
- $scoreLegend['cmi.interactions_4.student_response'] = 1;
- $scoreLegend['cmi.interactions_5.student_response'] = 2;
- $scoreLegend['cmi.interactions_6.student_response'] = 1;
- $scoreLegend['cmi.interactions_7.student_response'] = 2;
- $scoreLegend['cmi.interactions_8.student_response'] = 1;
- $scoreLegend['cmi.interactions_9.student_response'] = 1;
- $reportData['scoreLegend'] = $scoreLegend;
- echo $OUTPUT->header();
- //build report table
- ?>
- <br />
- <br />
- <table class="flexible generaltable generalbox">
- <thead>
- <tr>
- <th class="header">Skills</th>
- <th class="header">Scoring Higher Than Acceptable</th>
- <th class="header">Scoring Lower Than Acceptable</th>
- <!--<th class="header">key</th> -->
- </tr>
- </thead>
- <tbody>
- <?php
- foreach ($questionsReport as $key => $value) {
- echo '<tr class="row">';
- echo '<td>'. $key .'</td>';
- foreach($value as $info){
- if(key($value) == $reportData['scoreLegend'][$key]){
- echo '<td class="cell">'. $info .'</td>';
- echo '<td class="cell">0</td>';
- //echo '<td class="cell">'.key($value).'</td>';
- } else {
- echo '<td class="cell">0</td>';
- echo '<td class="cell">'. $info .'</td>';
- //echo '<td class="cell">'.key($value).'</td>';
- }
- }
- echo '</tr>';
- }
- ?>
- </tbody>
- </table>
- <?php
- echo $OUTPUT->footer();
- function contains_substr($mainStr, $str, $loc = false) {
- if ($loc === false) return (strpos($mainStr, $str) !== false);
- if (strlen($mainStr) < strlen($str)) return false;
- if (($loc + strlen($str)) > strlen($mainStr)) return false;
- return (strcmp(substr($mainStr, $loc, strlen($str)), $str) == 0);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement