From: pichetp Date: Tue, 11 Mar 2008 17:13:33 +0000 (+0000) Subject: MDL-12572 MDL-13427 New HTML export mode useable with Excel or Word X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=92f48269278518a6f6da000a10f1ab2e18b9e4a0;p=moodle.git MDL-12572 MDL-13427 New HTML export mode useable with Excel or Word --- diff --git a/mod/quiz/report/analysis/report.php b/mod/quiz/report/analysis/report.php index bf579faf6c..2bb18e4e14 100644 --- a/mod/quiz/report/analysis/report.php +++ b/mod/quiz/report/analysis/report.php @@ -14,7 +14,8 @@ class quiz_report extends quiz_default_report { $this->print_header_and_tabs($cm, $course, $quiz, $reportmode="analysis"); } /// Construct the table for this particular report - +// echo "course
";print_r($course);echo "
"; + // echo "course
";print_r($CFG);echo "
"; if (!$quiz->questions) { print_heading($strnoattempts); return true; @@ -210,7 +211,15 @@ class quiz_report extends quiz_default_report { $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 ; + } + } + + unset($attemptscores); unset($statstable); @@ -226,6 +235,9 @@ class quiz_report extends quiz_default_report { break; case "CSV": $this->Export_CSV($questions, $filename); + break; + case "HTML": + // $this->Export_HTML($questions, $filename); break; } } @@ -246,14 +258,14 @@ class quiz_report extends quiz_default_report { $table->define_baseurl($CFG->wwwroot.'/mod/quiz/report.php?q='.$quiz->id.'&mode=analysis'); $table->sortable(true); - $table->no_sorting('rpercent'); + // $table->no_sorting('rpercent'); $table->collapsible(true); $table->initialbars(false); $table->column_class('id', 'numcol'); $table->column_class('credits', 'numcol'); $table->column_class('rcounts', 'numcol'); - $table->column_class('rpercent', 'numcol'); + // $table->column_class('rpercent', 'numcol'); $table->column_class('facility', 'numcol'); $table->column_class('qsd', 'numcol'); $table->column_class('disc_index', 'numcol'); @@ -337,7 +349,7 @@ class quiz_report extends quiz_default_report { $response->text = ''.format_text($resp, FORMAT_MOODLE, $format_options, $quiz->course).' '; $count = $q['rcounts'][$aid].'/'.$q['count']; $response->rcount = $count; - $response->rpercent = '('.format_float($q['rcounts'][$aid]/$q['count']*100,0).'%)'; + $response->rpercent = $q['rpercent'][$aid]; $responses[] = $response; } @@ -352,7 +364,9 @@ class quiz_report extends quiz_default_report { $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 '
'; @@ -419,6 +433,11 @@ class quiz_report extends quiz_default_report { 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 ''; @@ -659,7 +678,89 @@ class quiz_report extends quiz_default_report { } exit; } + function Export_HTML(&$questions, $filename,$table) { + $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').''; + $text = implode("", $headers)." \n"; + + $filename .= ".html"; + header("Content-Type: application/download\n"); + header("Content-Disposition: attachment; filename=\"$filename\""); + header("Expires: 0"); + header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); + header("Pragma: public"); + print_header(); + echo ''; + echo ''; + foreach($questions as $q) { + $rows = $this->print_row_stats_data_html($q); + foreach($rows as $row){ + $text = implode("'; + //echo $text." \n"; + } + } + echo '
'.$text.'
", $row); + echo '
'.$text.'
'; + echo ''; + exit; + } + function print_row_stats_data_html(&$q) { + global $QTYPE_MENU ; + $format_options = new stdClass; + $format_options->para = false; + $format_options->noclean = true; + $format_options->newlines = false; + + $qid = $q['id']; + $question = get_record('question', 'id', $qid); + $qnumber = "".$qid.""; + $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"; + $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'; + } elseif ($q['credits'][$aid] == 1) { + $qclass = 'color:blue ; font-weight : bold;';//'correct'; + } else { + $qclass = 'green';//'partialcorrect'; + } + $response->credit = '('.format_float($q['credits'][$aid],2).') '; + $response->text = ''.format_text($resp, FORMAT_MOODLE, $format_options).' '; + $count = ' '.$q['rcounts'][$aid].' /  '.$q['count']; + $response->rcount = $count; + $response->rpercent = $q['rpercent'][$aid]; + $responses[] = $response; + } + $facility = format_float($q['facility']*100,0)."%"; + $qsd = format_float($q['qsd'],3); + $di = format_float($q['disc_index'],2); + $dc = format_float($q['disc_coeff'],2); + + $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, '', '', '', '')); + } + return $result; + } function print_row_stats_data(&$q) { $qid = $q['id']; $question = get_record('question', 'id', $qid);