Dans C:\moodle\moodle\site\moodle_head\mod\quiz\report\analysis : "C:\Program Files\TortoiseCVS\cvs.exe" -q diff -u -r 1.46 report.php CVSROOT=:ext:pichetp@cvs.moodle.org:/cvsroot/moodle Index: report.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/report/analysis/report.php,v retrieving revision 1.46 retrieving revision 1.51 diff -u -r1.46 -r1.51 --- report.php 11 Mar 2008 17:13:33 -0000 1.46 +++ report.php 17 Mar 2008 14:21:20 -0000 1.51 @@ -1,4 +1,4 @@ -libdir.'/tablelib.php'); @@ -73,8 +73,9 @@ 'WHERE qa.quiz = '.$quiz->id.' AND qa.preview = 0 '. $group; $usermax = get_records_sql_menu($sql); + }else { + $usermax = ''; } - $groupmembers = ''; $groupwhere = ''; @@ -98,8 +99,13 @@ $this->print_options_form($quiz, $cm, $attemptselection, $lowmarklimit, $pagesize); return true; } + $questions = array(); + $getquestiondata = true ; + $this->get_questions_atttempts_data ($quiz,&$questions,&$attempts,$attemptselection,$usermax); - /// Here we rewiew all attempts and record data to construct the table +/* This is the code before creating the get_questions_atttempts_data function +/// will remove these lines when the new function gets approval +/// Here we rewiew all attempts and record data to construct the table $questions = array(); $statstable = array(); $questionarray = array(); @@ -222,7 +228,7 @@ unset($attemptscores); unset($statstable); - +*/ /// Now check if asked download of data if ($download = optional_param('download', NULL)) { $filename = clean_filename("$course->shortname ".format_string($quiz->name,true)); @@ -237,7 +243,7 @@ $this->Export_CSV($questions, $filename); break; case "HTML": - // $this->Export_HTML($questions, $filename); + $this->Export_HTML($questions, $filename); break; } } @@ -364,9 +370,6 @@ $table->add_data(array('', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '')); } } - if( $download == "HTML") { - $this->Export_HTML($questions, $filename,$table); - } print_heading_with_help(get_string("analysistitle", "quiz_analysis"),"itemanalysis", "quiz"); echo '
'; @@ -413,7 +416,15 @@ $options["mode"] = "analysis"; $options['sesskey'] = $USER->sesskey; $options["noheader"] = "yes"; - echo ''; + if (file_exists("$CFG->libdir/phpdocwriter/lib/include.php")) { + echo ''; + }else { + echo ''; + } + $options["download"] = "HTML"; + print_single_button('report.php', $options, get_string("downloadhtml", "quiz_analysis")); + echo "\n"; + echo ''; $options["download"] = "ODS"; print_single_button("report.php", $options, get_string("downloadods")); echo "\n"; @@ -433,16 +444,138 @@ print_single_button('report.php', $options, get_string("downloadtext")); echo "\n"; echo ""; - echo ''; - $options["download"] = "HTML"; - print_single_button('report.php', $options, get_string("downloadhtml")); - echo "\n"; - echo ""; helpbutton('analysisdownload', get_string('analysisdownload', 'quiz_analysis'), 'quiz'); echo "\n"; echo ''; } + function get_questions_atttempts_data ($quiz,&$questions,&$attempts,$attemptselection,$usermax){ + global $CFG, $SESSION, $QTYPES; + + /// Here we rewiew all attempts and record data to construct the table + $statstable = array(); + $questionarray = array(); + foreach ($attempts as $attempt) { + $questionarray[] = quiz_questions_in_quiz($attempt->layout); + } + $questionlist = quiz_questions_in_quiz(implode(",", $questionarray)); + $questionarray = array_unique(explode(",",$questionlist)); + $questionlist = implode(",", $questionarray); + unset($questionarray); + + foreach ($attempts as $attempt) { + switch ($attemptselection) { + case QUIZ_ALLATTEMPTS : + $userscore = 0; // can be anything, not used + break; + case QUIZ_HIGHESTATTEMPT : + $userscore = $attempt->sumgrades; + break; + case QUIZ_FIRSTATTEMPT : + $userscore = $attempt->timemodified; + break; + case QUIZ_LASTATTEMPT : + $userscore = $attempt->timemodified; + break; + } + + if ($attemptselection == QUIZ_ALLATTEMPTS || $userscore == $usermax[$attempt->userid]) { + + $sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance". + " FROM {$CFG->prefix}question q,". + " {$CFG->prefix}quiz_question_instances i". + " WHERE i.quiz = '$quiz->id' AND q.id = i.question". + " AND q.id IN ($questionlist)"; + + if (!$quizquestions = get_records_sql($sql)) { + error('No questions found'); + } + + // Load the question type specific information + if (!get_question_options($quizquestions)) { + error('Could not load question options'); + } + // Restore the question sessions to their most recent states + // creating new sessions where required + if (!$states = get_question_states($quizquestions, $quiz, $attempt)) { + error('Could not restore question sessions'); + } + $numbers = explode(',', $questionlist); + $statsrow = array(); + foreach ($numbers as $i) { + if (!isset($quizquestions[$i]) or !isset($states[$i])) { + continue; + } + $qtype = ($quizquestions[$i]->qtype=='random') ? $states[$i]->options->question->qtype : $quizquestions[$i]->qtype; + if($quizquestions[$i]->qtype =='randomsamatch'){ + $quizquestions[$i]->options =$states[$i]->options ; + } + $q = get_question_responses($quizquestions[$i], $states[$i]); + if (empty($q)){ + continue; + } + $qid = $q->id; + if (!isset($questions[$qid])) { + $questions[$qid]['id'] = $qid; + $questions[$qid]['qname'] = $quizquestions[$i]->name; + foreach ($q->responses as $answer => $r) { + $r->count = 0; + $questions[$qid]['responses'][$answer] = $r->answer; + $questions[$qid]['rcounts'][$answer] = 0; + $questions[$qid]['credits'][$answer] = $r->credit; + $statsrow[$qid] = 0; + } + } + $responses = get_question_actual_response($quizquestions[$i], $states[$i]); + foreach ($responses as $resp){ + if ($resp) { + if ($key = array_search($resp, $questions[$qid]['responses'])) { + $questions[$qid]['rcounts'][$key]++; + } else { + $test = new stdClass; + $test->responses = $QTYPES[$quizquestions[$i]->qtype]->get_correct_responses($quizquestions[$i], $states[$i]); + if ($key = $QTYPES[$quizquestions[$i]->qtype]->check_response($quizquestions[$i], $states[$i], $test)) { + $questions[$qid]['rcounts'][$key]++; + } else { + $questions[$qid]['responses'][] = $resp; + $questions[$qid]['rcounts'][] = 1; + $questions[$qid]['credits'][] = 0; + } + } + } + } + $statsrow[$qid] = get_question_fraction_grade($quizquestions[$i], $states[$i]); + } + $attemptscores[$attempt->id] = $attempt->sumgrades; + $statstable[$attempt->id] = $statsrow; + } + } // Statistics Data table built + + unset($attempts); + unset($quizquestions); + unset($states); + + // now calculate statistics and set the values in the $questions array + $top = max($attemptscores); + $bottom = min($attemptscores); + $gap = ($top - $bottom)/3; + $top -=$gap; + $bottom +=$gap; + foreach ($questions as $qid=>$q) { + $questions[$qid] = $this->report_question_stats($q, $attemptscores, $statstable, $top, $bottom); + // calculate rpercent + foreach($q['responses']as $aid => $resp){ + $rpercent = '('.format_float($q['rcounts'][$aid]/$q['count']*100,0).'%)'; + $questions[$qid]['rpercent'][$aid] = $rpercent ; + } + $SESSION->quiz_analysis_table['question'][$qid]=$questions[$qid] ; + + } + + + unset($attemptscores); + unset($statstable); + } function report_question_stats(&$q, &$attemptscores, &$questionscores, $top, $bottom) { $qstats = array(); $qid = $q['id']; @@ -536,13 +669,15 @@ /// Here starts workshhet headers $myxls->write_string(0,0,$sheettitle,$formatb); - $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), - get_string('qnametitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), - get_string('responsestitle','quiz_analysis'), get_string('rfractiontitle','quiz_analysis'), - get_string('rcounttitle','quiz_analysis'), get_string('rpercenttitle','quiz_analysis'), - get_string('qcounttitle','quiz_analysis'), - get_string('facilitytitle','quiz_analysis'), get_string('stddevtitle','quiz_analysis'), - get_string('dicsindextitle','quiz_analysis'), get_string('disccoefftitle','quiz_analysis')); + $headers = array(strip_tags(get_string('row','quiz_analysis')),strip_tags(get_string('qidtitle','quiz_analysis')), + strip_tags(get_string('index','quiz_analysis')),strip_tags(get_string('qtypetitle','quiz_analysis')), + strip_tags(get_string('qnametitle','quiz_analysis')), strip_tags(get_string('qtexttitle','quiz_analysis')), + strip_tags(get_string('responsestitle','quiz_analysis')), strip_tags(get_string('rfractiontitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis').'/'.get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('rpercenttitle','quiz_analysis')), strip_tags(get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('facilitytitle','quiz_analysis')), strip_tags(get_string('stddevtitle','quiz_analysis')), + strip_tags(get_string('dicsindextitle','quiz_analysis')), strip_tags(get_string('disccoefftitle','quiz_analysis'))); $col = 0; foreach ($headers as $item) { @@ -551,8 +686,10 @@ } $row = 3; + foreach($questions as $q) { - $rows = $this->print_row_stats_data($q); + $r = $row -2; + $rows = $this->print_row_stats_data($q,$r); foreach($rows as $rowdata){ $col = 0; foreach($rowdata as $item){ @@ -614,14 +751,15 @@ $formatblue->set_align('center'); /// Here starts workshhet headers $myxls->write_string(0,0,$sheettitle,$formatb); - - $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), - get_string('qnametitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), - get_string('responsestitle','quiz_analysis'), get_string('rfractiontitle','quiz_analysis'), - get_string('rcounttitle','quiz_analysis'), get_string('rpercenttitle','quiz_analysis'), - get_string('qcounttitle','quiz_analysis'), - get_string('facilitytitle','quiz_analysis'), get_string('stddevtitle','quiz_analysis'), - get_string('dicsindextitle','quiz_analysis'), get_string('disccoefftitle','quiz_analysis')); + $headers = array(strip_tags(get_string('row','quiz_analysis')),strip_tags(get_string('qidtitle','quiz_analysis')), + strip_tags(get_string('index','quiz_analysis')),strip_tags(get_string('qtypetitle','quiz_analysis')), + strip_tags(get_string('qnametitle','quiz_analysis')), strip_tags(get_string('qtexttitle','quiz_analysis')), + strip_tags(get_string('responsestitle','quiz_analysis')), strip_tags(get_string('rfractiontitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis').'/'.get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('rpercenttitle','quiz_analysis')), strip_tags(get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('facilitytitle','quiz_analysis')), strip_tags(get_string('stddevtitle','quiz_analysis')), + strip_tags(get_string('dicsindextitle','quiz_analysis')), strip_tags(get_string('disccoefftitle','quiz_analysis'))); $col = 0; foreach ($headers as $item) { @@ -631,7 +769,8 @@ $row = 3; foreach($questions as $q) { - $rows = $this->print_row_stats_data($q); + $r = $row -2; + $rows = $this->print_row_stats_data($q,$r); foreach($rows as $rowdata){ $col = 0; foreach($rowdata as $item){ @@ -649,13 +788,15 @@ function Export_CSV(&$questions, $filename) { - $headers = array(get_string('qidtitle','quiz_analysis'), get_string('qtypetitle','quiz_analysis'), - get_string('qnametitle','quiz_analysis'), get_string('qtexttitle','quiz_analysis'), - get_string('responsestitle','quiz_analysis'), get_string('rfractiontitle','quiz_analysis'), - get_string('rcounttitle','quiz_analysis'), get_string('rpercenttitle','quiz_analysis'), - get_string('qcounttitle','quiz_analysis'), - get_string('facilitytitle','quiz_analysis'), get_string('stddevtitle','quiz_analysis'), - get_string('dicsindextitle','quiz_analysis'), get_string('disccoefftitle','quiz_analysis')); + $headers = array(strip_tags(get_string('row','quiz_analysis')),strip_tags(get_string('qidtitle','quiz_analysis')), + strip_tags(get_string('index','quiz_analysis')),strip_tags(get_string('qtypetitle','quiz_analysis')), + strip_tags(get_string('qnametitle','quiz_analysis')), strip_tags(get_string('qtexttitle','quiz_analysis')), + strip_tags(get_string('responsestitle','quiz_analysis')), strip_tags(get_string('rfractiontitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis')), + strip_tags(get_string('rcounttitle','quiz_analysis').'/'.get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('rpercenttitle','quiz_analysis')), strip_tags(get_string('qcounttitle','quiz_analysis')), + strip_tags(get_string('facilitytitle','quiz_analysis')), strip_tags(get_string('stddevtitle','quiz_analysis')), + strip_tags(get_string('dicsindextitle','quiz_analysis')), strip_tags(get_string('disccoefftitle','quiz_analysis'))); $text = implode("\t", $headers)." \n"; @@ -668,29 +809,89 @@ header("Pragma: public"); echo $text; - + + $row = 1; foreach($questions as $q) { - $rows = $this->print_row_stats_data($q); - foreach($rows as $row){ - $text = implode("\t", $row); + $rows = $this->print_row_stats_data_CSV($q,$row); + foreach($rows as $rowdata){ + $text = implode("\t", $rowdata); echo $text." \n"; + $row++; } } exit; } - function Export_HTML(&$questions, $filename,$table) { + function print_row_stats_data_CSV(&$q,&$index) { + $qid = $q['id']; + $question = get_record('question', 'id', $qid); + + $options = new stdClass; + $options->para = false; + $options->noclean = true; + $options->newlines = false; + $qtype = $question->qtype; + $qname = format_text($question->name, FORMAT_MOODLE, $options); + $trans = str_replace('\t',' ',$question->questiontext); + $trans = substr($trans,0,390); + $order = array("\r\n", "\n", "\r"); + $trans = str_replace($order,' ',$trans); + // $trans = explode(',',$trans); + + // $qtext = format_text(implode('__',$trans), FORMAT_MOODLE, $options); + + $qtext = format_text($trans, FORMAT_MOODLE, $options); + $responses = array(); + foreach ($q['responses'] as $aid=>$resp){ + $response = new stdClass; + if ($q['credits'][$aid] <= 0) { + $qclass = 'uncorrect'; + } elseif ($q['credits'][$aid] == 1) { + $qclass = 'correct'; + } else { + $qclass = 'partialcorrect'; + } + $response->credit = " (".format_float($q['credits'][$aid],2).") "; + $response->text = format_text("$resp", FORMAT_MOODLE, $options); + $count = $q['rcounts'][$aid].'/'.$q['count']; + $response->count = $q['rcounts'][$aid]; + $response->rcount = $count; + $response->rpercent = format_float($q['rcounts'][$aid]/$q['count']*100,0).'%'; + $responses[] = $response; + } + $count = format_float($q['count'],0); + $facility = format_float($q['facility']*100,0); + $qsd = format_float($q['qsd'],4); + $di = format_float($q['disc_index'],3); + $dc = format_float($q['disc_coeff'],3); + $result = array(); + $response = array_shift($responses); + $indexrep= 0; + $result[] = array($index,$qid,$indexrep, $qtype, $qname, $qtext,' ', ' ', ' ', ' ',' ', $count, $facility, $qsd, $di, $dc); + $index++ ; + $indexrep++; + $result[] = array($index,$qid,$indexrep, $qtype, $qname, substr($qtext,0,250) , $response->text, $response->credit, $response->count,$response->rcount, $response->rpercent, $count, ' ', ' ', ' ', ' '); + $index++ ; + $indexrep++; + foreach($responses as $response){ + $result[] = array($index,$qid,$indexrep,$qtype,$qname,substr($qtext,0,250) , $response->text, $response->credit,$response->count, $response->rcount, $response->rpercent, $count, ' ', ' ', ' ', ' '); + $index++ ; + $indexrep++; + } + return $result; + } + function Export_HTML(&$questions, $filename) { $headers = array(); - $headers[] = ''.get_string('qidtitle','quiz_analysis').''; - $headers[] = ''.get_string('qtypetitle','quiz_analysis').''; - $headers[] = ''.get_string('qnametitle','quiz_analysis').''.'
'.''.get_string('qtexttitle','quiz_analysis').''; - $headers[] = ''.get_string('responsestitle','quiz_analysis').''; - $headers[] = ''.get_string('rfractiontitle','quiz_analysis').''; - $headers[] = ''.get_string('rcounttitle','quiz_analysis').' / '.get_string('qcounttitle','quiz_analysis').''; - $headers[] = ''.get_string('rpercenttitle','quiz_analysis').''; - $headers[] = ''.get_string('facilitytitle','quiz_analysis').''; - $headers[] = ''.get_string('stddevtitle','quiz_analysis').''; - $headers[] = ''.get_string('dicsindextitle','quiz_analysis').''; - $headers[] = ''.get_string('disccoefftitle','quiz_analysis').''; + $headers[] = ''.get_string('qidtitle','quiz_analysis').''; + $headers[] = ''.get_string('qtypetitle','quiz_analysis').''; + $headers[] = ''.get_string('qnametitle','quiz_analysis').':'.'
'.''.get_string('qtexttitle','quiz_analysis').''; + $headers[] = ''.get_string('responsestitle','quiz_analysis').''; + $headers[] = ''.get_string('rfractiontitle','quiz_analysis').''; + $headers[] = ''.get_string('rcounttitle','quiz_analysis').' / '.get_string('qcounttitle','quiz_analysis').''; + $headers[] = ''.get_string('rpercenttitle','quiz_analysis').''; + $headers[] = ''.get_string('facilitytitle','quiz_analysis').''; + $headers[] = ''.get_string('stddevtitle','quiz_analysis').''; + $headers[] = ''.get_string('dicsindextitle','quiz_analysis').''; + $headers[] = ''.get_string('disccoefftitle','quiz_analysis').''; $text = implode("", $headers)." \n"; $filename .= ".html"; @@ -700,7 +901,7 @@ header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); header("Pragma: public"); print_header(); - echo ''; + echo '
'; echo ''; foreach($questions as $q) { $rows = $this->print_row_stats_data_html($q); @@ -724,25 +925,28 @@ $qid = $q['id']; $question = get_record('question', 'id', $qid); $qnumber = "".$qid.""; - $qname = '
'.format_text($question->name, $question->questiontextformat, $format_options).'
'; + $qname = ''.format_text($question->name, $question->questiontextformat, $format_options).':
'; $qicon = '';//print_question_icon($question, true); $qreview = ''; //quiz_question_preview_button($quiz, $question); $qtext = format_text($question->questiontext, $question->questiontextformat, $format_options); - $qquestion = $qname."\n".$qtext."\n"; + $qquestion = '
'.$text.'
'.$qname."\n".$qtext."\n".'
'; $qtype = $QTYPE_MENU[$question->qtype]; $responses = array(); foreach ($q['responses'] as $aid=>$resp){ $response = new stdClass; if ($q['credits'][$aid] <= 0) { - $qclass = 'color:red';//'uncorrect'; + $qclass = 'red';//'uncorrect'; } elseif ($q['credits'][$aid] == 1) { - $qclass = 'color:blue ; font-weight : bold;';//'correct'; + $qclass = 'blue';//'correct'; } else { $qclass = 'green';//'partialcorrect'; } - $response->credit = '('.format_float($q['credits'][$aid],2).') '; - $response->text = ''.format_text($resp, FORMAT_MOODLE, $format_options).' '; + $response->credit = '('.format_float($q['credits'][$aid],2).')'; + if ($response->text ='') { + $response->text =' '; + } + $response->text = ''.format_text($resp, FORMAT_MOODLE, $format_options).''; $count = ' '.$q['rcounts'][$aid].' /  '.$q['count']; $response->rcount = $count; $response->rpercent = $q['rpercent'][$aid]; @@ -757,11 +961,11 @@ $response = array_shift($responses); $result[] =(array($qnumber,$qtype, $qquestion, $response->text, $response->credit, $response->rcount, $response->rpercent, $facility, $qsd, $di, $dc)); foreach($responses as $response) { - $result[]=(array('', '', '',$response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '')); + $result[]=(array(' ',' ',' ',$response->text, $response->credit, $response->rcount, $response->rpercent, '  ', '  ', '  ', '  ')); } return $result; } - function print_row_stats_data(&$q) { + function print_row_stats_data(&$q, &$index) { $qid = $q['id']; $question = get_record('question', 'id', $qid); @@ -788,8 +992,10 @@ $response->credit = " (".format_float($q['credits'][$aid],2).") "; $response->text = format_text("$resp", FORMAT_MOODLE, $options); $count = $q['rcounts'][$aid].'/'.$q['count']; + $response->count = $q['rcounts'][$aid]; $response->rcount = $count; - $response->rpercent = '('.format_float($q['rcounts'][$aid]/$q['count']*100,0).'%)'; +// $response->rpercent = format_float($q['rcounts'][$aid]/$q['count']*100,0).'%'; + $response->rpercent = $q['rcounts'][$aid]/$q['count']*100.0; $responses[] = $response; } $count = format_float($q['count'],0); @@ -800,9 +1006,17 @@ $result = array(); $response = array_shift($responses); - $result[] = array($qid, $qtype, $qname, $qtext, $response->text, $response->credit, $response->rcount, $response->rpercent, $count, $facility, $qsd, $di, $dc); + $indexrep= 0; + $result[] = array($index,$qid,$indexrep, $qtype, $qname, $qtext,' ', ' ', ' ', ' ', ' ',$count, $facility, $qsd, $di, $dc); + $index++ ; + $indexrep++; + $result[] = array($index,$qid,$indexrep, $qtype, $qname, substr($qtext,0,250) , $response->text, $response->credit, $response->count,$response->rcount, $response->rpercent, $count, ' ', ' ', ' ', ' '); + $index++ ; + $indexrep++; foreach($responses as $response){ - $result[] = array('', '', '', '', $response->text, $response->credit, $response->rcount, $response->rpercent, '', '', '', '', ''); + $result[] = array($index,$qid,$indexrep,$qtype,$qname,substr($qtext,0,250) , $response->text, $response->credit, $response->count,$response->rcount, $response->rpercent, $count, ' ', ' ', ' ', ' '); + $index++ ; + $indexrep++; } return $result; }